mirror of
https://github.com/stakater/Reloader.git
synced 2026-08-20 04:26:28 +00:00
Implement PR-1 review comments
This commit is contained in:
@@ -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{})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user