Skip to content

Commit

Permalink
Stop panic when losing connectivity. (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvleandro authored Aug 11, 2023
1 parent 7f3fda0 commit e25d1f9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func New() *cli.App {
app := cli.NewApp()
app.Name = "Keess"
app.Version = "v0.1.8"
app.Version = "v0.1.10"
app.Usage = "Keep stuff synchronized."
app.Description = "Keep secrets and configmaps synchronized."
app.Suggest = true
Expand Down
4 changes: 2 additions & 2 deletions chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.8
version: 0.1.10

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "v0.1.8"
appVersion: "v0.1.10"
34 changes: 17 additions & 17 deletions kube_syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (s *Syncer) Start(kubeConfigPath string, developmentMode bool, sourceContex

zapLogger, err := loggerConfig.Build()
if err != nil {
return err
s.logger.Error(err)
}
abstractions.Logger = zapLogger.Sugar()
s.logger = abstractions.Logger
Expand Down Expand Up @@ -87,7 +87,7 @@ func (s *Syncer) Start(kubeConfigPath string, developmentMode bool, sourceContex
// use the current context in kubeconfig
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
panic(err.Error())
s.logger.Error(err)
}

inClusterConfig, err := rest.InClusterConfig()
Expand All @@ -97,14 +97,14 @@ func (s *Syncer) Start(kubeConfigPath string, developmentMode bool, sourceContex
// create the clientset
client, err = kubernetes.NewForConfig(inClusterConfig)
if err != nil {
return err
s.logger.Error(err)
}
s.logger.Info("Config loaded from service account.")
} else {
// create the clientset
client, err = kubernetes.NewForConfig(config)
if err != nil {
return err
s.logger.Error(err)
}
s.logger.Info("Config loaded from kube config.")
}
Expand All @@ -115,13 +115,13 @@ func (s *Syncer) Start(kubeConfigPath string, developmentMode bool, sourceContex
for _, context := range destinationContexts {
config, err := buildConfigWithContextFromFlags(context, *kubeconfig)
if err != nil {
panic(err)
s.logger.Error(err)
}

// create the clientset
client, err := kubernetes.NewForConfig(config)
if err != nil {
return err
s.logger.Error(err)
}

s.kubeClients[context] = client
Expand Down Expand Up @@ -157,7 +157,7 @@ func (s *Syncer) Run() error {
// First of all we need to load all namespaces.
namespaceList, err := kubeClient.CoreV1().Namespaces().List(context.TODO(), metav1.ListOptions{})
if err != nil {
return err
s.logger.Error(err)
}

for _, namespace := range namespaceList.Items {
Expand All @@ -169,7 +169,7 @@ func (s *Syncer) Run() error {
LabelSelector: abstractions.LabelSelector,
})
if err != nil {
return err
s.logger.Error(err)
}

for _, configMap := range configMapList.Items {
Expand All @@ -187,7 +187,7 @@ func (s *Syncer) Run() error {
LabelSelector: abstractions.LabelSelector,
})
if err != nil {
return err
s.logger.Error(err)
}

for _, secret := range secretList.Items {
Expand All @@ -207,7 +207,7 @@ func (s *Syncer) Run() error {
LabelSelector: abstractions.ManagedLabelSelector,
})
if err != nil {
return err
s.logger.Error(err)
}

for _, configMap := range managedConfigMapList.Items {
Expand All @@ -226,7 +226,7 @@ func (s *Syncer) Run() error {
sourceConfigMap, err := sourceKubeClient.CoreV1().ConfigMaps(sourceNamespace).Get(context.TODO(), configMap.Name, metav1.GetOptions{})

if err != nil && !errorsTypes.IsNotFound(err) {
return err
s.logger.Error(err)
}

// Check if source configmap was deleted.
Expand All @@ -235,7 +235,7 @@ func (s *Syncer) Run() error {

err := entity.Delete()
if err != nil && !errorsTypes.IsNotFound(err) {
return err
s.logger.Error(err)
} else {
s.logger.Infof("The ConfigMap '%s' was deleted in namespace '%s' on context '%s' because it was deleted in the source namespace '%s' on the source context '%s'.", configMap.Name, configMap.Namespace, currentContext, sourceNamespace, sourceContext)
}
Expand All @@ -247,7 +247,7 @@ func (s *Syncer) Run() error {
entity = abstractions.NewKubernetesEntity(s.kubeClients, sourceConfigMap, abstractions.ConfigMapEntity, sourceNamespace, configMap.Namespace, sourceContext, currentContext)
err := entity.Update()
if err != nil {
return err
s.logger.Error(err)
} else {
s.logger.Infof("The ConfigMap '%s' was updated in namespace '%s' on context '%s' because It was updated in the source namespace '%s' on the source context '%s'.", configMap.Name, configMap.Namespace, currentContext, sourceNamespace, sourceContext)
}
Expand All @@ -260,7 +260,7 @@ func (s *Syncer) Run() error {
LabelSelector: abstractions.ManagedLabelSelector,
})
if err != nil {
return err
s.logger.Error(err)
}

for _, secret := range managedSecretList.Items {
Expand All @@ -279,7 +279,7 @@ func (s *Syncer) Run() error {
sourceSecret, err := sourceKubeClient.CoreV1().Secrets(sourceNamespace).Get(context.TODO(), secret.Name, metav1.GetOptions{})

if err != nil && !errorsTypes.IsNotFound(err) {
return err
s.logger.Error(err)
}

// Check if source secret was deleted.
Expand All @@ -288,7 +288,7 @@ func (s *Syncer) Run() error {

err := entity.Delete()
if err != nil && !errorsTypes.IsNotFound(err) {
return err
s.logger.Error(err)
} else {
s.logger.Infof("The Secret '%s' was deleted in namespace '%s' on context '%s' because It was deleted in the source namespace '%s' on the source context '%s'.", secret.Name, secret.Namespace, currentContext, sourceNamespace, sourceContext)
}
Expand All @@ -300,7 +300,7 @@ func (s *Syncer) Run() error {
entity = abstractions.NewKubernetesEntity(s.kubeClients, sourceSecret, abstractions.SecretEntity, sourceNamespace, secret.Namespace, sourceContext, currentContext)
err := entity.Update()
if err != nil {
return err
s.logger.Error(err)
} else {
s.logger.Infof("The Secret '%s' was updated in namespace '%s' on context '%s' because It was updated in the source namespace '%s' on the source context '%s'.", secret.Name, secret.Namespace, currentContext, sourceNamespace, sourceContext)
}
Expand Down

0 comments on commit e25d1f9

Please sign in to comment.