From e25d1f9a8370a1cbef0b5f06020bc2478d761934 Mon Sep 17 00:00:00 2001 From: Marcus Leandro Date: Thu, 10 Aug 2023 23:11:46 -0300 Subject: [PATCH] Stop panic when losing connectivity. (#17) --- application/application.go | 2 +- chart/Chart.yaml | 4 ++-- kube_syncer/syncer.go | 34 +++++++++++++++++----------------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/application/application.go b/application/application.go index 4994f00..41a0696 100644 --- a/application/application.go +++ b/application/application.go @@ -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 diff --git a/chart/Chart.yaml b/chart/Chart.yaml index 5982b37..56a4e5c 100644 --- a/chart/Chart.yaml +++ b/chart/Chart.yaml @@ -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" diff --git a/kube_syncer/syncer.go b/kube_syncer/syncer.go index 3f9d51a..2efaec4 100644 --- a/kube_syncer/syncer.go +++ b/kube_syncer/syncer.go @@ -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 @@ -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() @@ -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.") } @@ -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 @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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. @@ -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) } @@ -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) } @@ -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 { @@ -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. @@ -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) } @@ -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) }