From 44341ff539d3dcd2a519ee4d53c22b6b3c51234e Mon Sep 17 00:00:00 2001 From: faizanahmad055 Date: Mon, 16 Jul 2018 14:21:27 +0500 Subject: [PATCH] Implement PR-1 review comments --- internal/pkg/controller/controller_test.go | 8 ++--- internal/pkg/handler/created-handler.go | 23 ++++++++++++ internal/pkg/handler/handler.go | 41 ---------------------- internal/pkg/handler/updated-handler.go | 23 ++++++++++++ 4 files changed, 50 insertions(+), 45 deletions(-) diff --git a/internal/pkg/controller/controller_test.go b/internal/pkg/controller/controller_test.go index 6aa90897..c2517c52 100644 --- a/internal/pkg/controller/controller_test.go +++ b/internal/pkg/controller/controller_test.go @@ -32,7 +32,7 @@ func randSeq(n int) string { func TestControllerForUpdatingConfigmapShouldUpdateDeployment(t *testing.T) { client, err := kube.GetClient() if err != nil { - logrus.Infof("Unable to create Kubernetes client error = %v", err) + logrus.Errorf("Unable to create Kubernetes client error = %v", err) return } namespace := "test-reloader" @@ -41,7 +41,7 @@ func TestControllerForUpdatingConfigmapShouldUpdateDeployment(t *testing.T) { controller, err := NewController(client, "configMaps", namespace) if err != nil { - logrus.Infof("Unable to create NewController error = %v", err) + logrus.Errorf("Unable to create NewController error = %v", err) return } stop := make(chan struct{}) @@ -103,7 +103,7 @@ func createDeployement(deploymentName string, namespace string, client kubernete func TestControllerForUpdatingSecretShouldUpdateDeployment(t *testing.T) { client, err := kube.GetClient() if err != nil { - logrus.Infof("Unable to create Kubernetes client error = %v", err) + logrus.Errorf("Unable to create Kubernetes client error = %v", err) return } namespace := "test-reloader-secrets" @@ -112,7 +112,7 @@ func TestControllerForUpdatingSecretShouldUpdateDeployment(t *testing.T) { controller, err := NewController(client, "secrets", namespace) if err != nil { - logrus.Infof("Unable to create NewController error = %v", err) + logrus.Errorf("Unable to create NewController error = %v", err) return } stop := make(chan struct{}) diff --git a/internal/pkg/handler/created-handler.go b/internal/pkg/handler/created-handler.go index 1983018d..53927afd 100644 --- a/internal/pkg/handler/created-handler.go +++ b/internal/pkg/handler/created-handler.go @@ -1,6 +1,29 @@ package handler +import ( + "github.com/sirupsen/logrus" + "k8s.io/api/core/v1" +) + // ResourceCreatedHandler contains new objects type ResourceCreatedHandler struct { Resource interface{} } + +// Handle processes the newly created resource +func (r ResourceCreatedHandler) Handle() error { + if r.Resource == nil { + logrus.Errorf("Error in Handler") + } else { + logrus.Infof("Detected changes in object %s", r.Resource) + // process resource based on its type + if _, ok := r.Resource.(*v1.ConfigMap); ok { + logrus.Infof("Performing 'Added' action for resource of type 'configmap'") + } else if _, ok := r.Resource.(*v1.Secret); ok { + logrus.Infof("Performing 'Added' action for resource of type 'secret'") + } else { + logrus.Infof("Invalid resource") + } + } + return nil +} diff --git a/internal/pkg/handler/handler.go b/internal/pkg/handler/handler.go index 09f3a4ee..20b28ee7 100644 --- a/internal/pkg/handler/handler.go +++ b/internal/pkg/handler/handler.go @@ -1,47 +1,6 @@ package handler -import ( - "github.com/sirupsen/logrus" - "k8s.io/api/core/v1" -) - // ResourceHandler handles the creation and update of resources type ResourceHandler interface { Handle() error } - -// Handle processes the newly created resource -func (r ResourceCreatedHandler) Handle() error { - if r.Resource == nil { - logrus.Infof("Error in Handler") - } else { - logrus.Infof("Detected changes in object %s", r.Resource) - // process resource based on its type - if _, ok := r.Resource.(*v1.ConfigMap); ok { - logrus.Infof("Performing 'Added' action for resource of type 'configmap'") - } else if _, ok := r.Resource.(*v1.Secret); ok { - logrus.Infof("Performing 'Added' action for resource of type 'secret'") - } else { - logrus.Infof("Invalid resource") - } - } - return nil -} - -// Handle processes the updated resource -func (r ResourceUpdatedHandler) Handle() error { - if r.Resource == nil || r.OldResource == nil { - logrus.Infof("Error in Handler") - } else { - logrus.Infof("Detected changes in object %s", r.Resource) - // process resource based on its type - if _, ok := r.Resource.(*v1.ConfigMap); ok { - logrus.Infof("Performing 'Updated' action for resource of type 'configmap'") - } else if _, ok := r.Resource.(*v1.Secret); ok { - logrus.Infof("Performing 'Updated' action for resource of type 'secret'") - } else { - logrus.Infof("Invalid resource") - } - } - return nil -} diff --git a/internal/pkg/handler/updated-handler.go b/internal/pkg/handler/updated-handler.go index 85157afa..478445db 100644 --- a/internal/pkg/handler/updated-handler.go +++ b/internal/pkg/handler/updated-handler.go @@ -1,7 +1,30 @@ package handler +import ( + "github.com/sirupsen/logrus" + "k8s.io/api/core/v1" +) + // ResourceUpdatedHandler contains updated objects type ResourceUpdatedHandler struct { Resource interface{} OldResource interface{} } + +// Handle processes the updated resource +func (r ResourceUpdatedHandler) Handle() error { + if r.Resource == nil || r.OldResource == nil { + logrus.Errorf("Error in Handler") + } else { + logrus.Infof("Detected changes in object %s", r.Resource) + // process resource based on its type + if _, ok := r.Resource.(*v1.ConfigMap); ok { + logrus.Infof("Performing 'Updated' action for resource of type 'configmap'") + } else if _, ok := r.Resource.(*v1.Secret); ok { + logrus.Infof("Performing 'Updated' action for resource of type 'secret'") + } else { + logrus.Infof("Invalid resource") + } + } + return nil +}