-
-
Notifications
You must be signed in to change notification settings - Fork 593
[STK-322] Rollback upgrade deployment #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…pgrade-deployment
const ( | ||
configmapUpdateOnChangeAnnotation = "reloader.stakater.com/configmap.update-on-change" | ||
// Adding seperate annotation to differentiate between configmap and secret | ||
secretUpdateOnChangeAnnotation = "reloader.stakater.com/secret.update-on-change" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
G101: Potential hardcoded credentials
namespace = r.Resource.(*v1.ConfigMap).Namespace | ||
name = r.Resource.(*v1.ConfigMap).Name | ||
sshData = convertConfigmapToSHA(r.Resource.(*v1.ConfigMap)) | ||
envName = "_CONFIGMAP" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string _CONFIGMAP
has 4 occurrences, make it a constant
namespace = r.Resource.(*v1.Secret).Namespace | ||
name = r.Resource.(*v1.Secret).Name | ||
sshData = convertSecretToSHA(r.Resource.(*v1.Secret)) | ||
envName = "_SECRET" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string _SECRET
has 4 occurrences, make it a constant
} | ||
|
||
if rollingUpgradeType == "deployments" { | ||
rollingUpgradeForDeployment(client, r, namespace, name, sshData, envName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of rollingUpgradeForDeployment
is not checked
if rollingUpgradeType == "deployments" { | ||
rollingUpgradeForDeployment(client, r, namespace, name, sshData, envName) | ||
} else if rollingUpgradeType == "daemonsets" { | ||
rollingUpgradeForDaemonSets(client, r, namespace, name, sshData, envName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of rollingUpgradeForDaemonSets
is not checked
} else if rollingUpgradeType == "daemonsets" { | ||
rollingUpgradeForDaemonSets(client, r, namespace, name, sshData, envName) | ||
} else if rollingUpgradeType == "statefulSets" { | ||
rollingUpgradeForStatefulSets(client, r, namespace, name, sshData, envName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of rollingUpgradeForStatefulSets
is not checked
|
||
func generateSHA(data string) string { | ||
hasher := sha1.New() | ||
io.WriteString(hasher, data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of io.WriteString
is not checked
@faizanahmad055 Image is available for testing. |
README.md
Outdated
@@ -21,10 +21,20 @@ For a `Deployment` called `foo` have a `ConfigMap` called `foo`. Then add this a | |||
```yaml | |||
metadata: | |||
annotations: | |||
reloader.stakater.com/update-on-change: "foo" | |||
reloader.stakater.com/configmap.update-on-change: "foo" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@waseem-h is it good to have configmap.
as prefix or configmap-
?
@@ -1,8 +1,23 @@ | |||
package handler | |||
|
|||
import ( | |||
"bytes" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is updated-handler
a good name for this? 🤔 @faizanahmad055 @waseem-h
|
||
if updated != sshData { | ||
return false | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if block ends with a return statement, so drop this else and outdent its block
return false | ||
} | ||
|
||
func getResourceSsh(containers []v1.Container, envar string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func getResourceSsh should be getResourceSSH
secretNamePrefix = "testsecret-reloader" | ||
letters = []rune("abcdefghijklmnopqrstuvwxyz") | ||
configmapUpdateOnChangeAnnotation = "reloader.stakater.com/configmap.update-on-change" | ||
secretUpdateOnChangeAnnotation = "reloader.stakater.com/secret.update-on-change" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
G101: Potential hardcoded credentials
const ( | ||
configmapUpdateOnChangeAnnotation = "reloader.stakater.com/configmap.update-on-change" | ||
// Adding separate annotation to differentiate between configmap and secret | ||
secretUpdateOnChangeAnnotation = "reloader.stakater.com/secret.update-on-change" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
G101: Potential hardcoded credentials
time.Sleep(10 * time.Second) | ||
|
||
logrus.Infof("Step 8: Update configmap for Second time") | ||
_, updateErr = configmapClient.Update(updateConfigmap(namespace, configmapName, "aurorasolutions.io")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ineffectual assignment to updateErr
namespace = r.Resource.(*v1.ConfigMap).Namespace | ||
name = r.Resource.(*v1.ConfigMap).Name | ||
sshData = helper.ConvertConfigmapToSHA(r.Resource.(*v1.ConfigMap)) | ||
envName = "_CONFIGMAP" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string _CONFIGMAP
has 4 occurrences, make it a constant
namespace = r.Resource.(*v1.Secret).Namespace | ||
name = r.Resource.(*v1.Secret).Name | ||
sshData = helper.ConvertSecretToSHA(r.Resource.(*v1.Secret)) | ||
envName = "_SECRET" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string _SECRET
has 4 occurrences, make it a constant
internal/pkg/helper/helper.go
Outdated
// GenerateSHA generates SHA from string | ||
func GenerateSHA(data string) string { | ||
hasher := sha1.New() | ||
io.WriteString(hasher, data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of io.WriteString
is not checked
@faizanahmad055 Image is available for testing. |
} | ||
|
||
if rollingUpgradeType == "deployments" { | ||
rollingUpgradeForDeployment(client, namespace, name, sshData, envName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of rollingUpgradeForDeployment
is not checked
if rollingUpgradeType == "deployments" { | ||
rollingUpgradeForDeployment(client, namespace, name, sshData, envName) | ||
} else if rollingUpgradeType == "daemonsets" { | ||
rollingUpgradeForDaemonSets(client, namespace, name, sshData, envName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of rollingUpgradeForDaemonSets
is not checked
} else if rollingUpgradeType == "daemonsets" { | ||
rollingUpgradeForDaemonSets(client, namespace, name, sshData, envName) | ||
} else if rollingUpgradeType == "statefulSets" { | ||
rollingUpgradeForStatefulSets(client, namespace, name, sshData, envName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of rollingUpgradeForStatefulSets
is not checked
@faizanahmad055 Image is available for testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename handlers to just the verbs. e.g., update.go, create.go
) | ||
|
||
const ( | ||
configmapUpdateOnChangeAnnotation = "reloader.stakater.com/configmap.update-on-change" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Export these annotations by pascal casing them.
Keys should be: configmap.reloader.stakater.com/reload
and secret.reloader.stakater.com/reload
Make sure to reuse them instead of copy pasting again into tests etc
@@ -20,11 +32,210 @@ func (r ResourceUpdatedHandler) Handle() error { | |||
// process resource based on its type | |||
if _, ok := r.Resource.(*v1.ConfigMap); ok { | |||
logrus.Infof("Performing 'Updated' action for resource of type 'configmap'") | |||
rollingUpgrade(r, "configmaps", "deployments") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats the point of checking for resource type here and passing it to rollingUpgrade and then checking for resource type again in that function? Seems pretty redundant
namespace = r.Resource.(*v1.ConfigMap).Namespace | ||
name = r.Resource.(*v1.ConfigMap).Name | ||
sshData = helper.ConvertConfigmapToSHA(r.Resource.(*v1.ConfigMap)) | ||
envName = "_CONFIGMAP" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to write constants again and again for the same resource. Since you know the resource type, better use that to generate the env name
} | ||
|
||
if rollingUpgradeType == "deployments" { | ||
rollingUpgradeForDeployment(client, namespace, name, sshData, envName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rollingUpgradeForDeployment
, rollingUpgradeForDaemonSets
, rollingUpgradeForStatefulSets
are almost identical to each other. Remove redundancy and figure out a way to make it more generic than copy pasting methods and just changing the resource type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also think of a better name for these functions or just drop the for
if you still want to use these functions. But I think they can be combined into 1 function with no duplication logic
logrus.Infof("Generated environment variable: %s", envar) | ||
|
||
for i := range containers { | ||
envs := containers[i].Env |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactor logic in this method for readability
internal/pkg/helper/helper.go
Outdated
} | ||
|
||
// ConvertConfigmapToSHA generates SHA for configmap data | ||
func ConvertConfigmapToSHA(cm *v1.ConfigMap) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ConvertConfigMapToSHA and ConvertSecretToSHA are identical except for 1 small thing.
Responsibility of converting some string to SHA should be separate and in a separate package. This helper doesn't really make sense since it isn't clear of what it is supposed to do. Create meaningful packages and try to keep things decoupled from kubernetes objects at the bottom level
@@ -236,60 +234,8 @@ func updateContainers(containers []v1.Container, annotationValue string, sshData | |||
} | |||
containers[i].Env = append(containers[i].Env, e) | |||
updated = true | |||
logrus.Infof("%s environment variable does not found so creating a new one") | |||
logrus.Infof("%s environment variable does not found, creating a new env with value %s", envar, sshData) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change the text to "environment variable not found" or "environment variable does not exist".
Plus we should log the name of the object i.e. deployment daemonset, stateful set etc instead of the SHA value
internal/pkg/helper/helper.go
Outdated
} | ||
sort.Strings(values) | ||
sha := GenerateSHA(strings.Join(values, ";")) | ||
logrus.Infof("SHA for configmap data: %s", sha) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we dont need to logg the SHA data
@@ -211,7 +209,7 @@ func rollingUpgradeForStatefulSets(client kubernetes.Interface, r ResourceUpdate | |||
|
|||
func updateContainers(containers []v1.Container, annotationValue string, sshData string, resourceType string) bool { | |||
updated := false | |||
envar := "STAKATER_" + convertToEnvVarName(annotationValue) + resourceType | |||
envar := "STAKATER_" + helper.ConvertToEnvVarName(annotationValue) + resourceType | |||
logrus.Infof("Generated environment variable: %s", envar) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please mention the name of Deployment, Daemonsets or statefulset on which action is being performed
@@ -0,0 +1,261 @@ | |||
package handlerTester |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't use MixedCaps in package name; handlerTester should be handlertester
internal/pkg/helper/testUtils.go
Outdated
|
||
if updated != shaData { | ||
return false | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if block ends with a return statement, so drop this else and outdent its block
internal/pkg/helper/testUtils.go
Outdated
|
||
if updated != shaData { | ||
return false | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if block ends with a return statement, so drop this else and outdent its block
internal/pkg/helper/testUtils.go
Outdated
|
||
if updated != shaData { | ||
return false | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if block ends with a return statement, so drop this else and outdent its block
internal/pkg/helper/testUtils.go
Outdated
var ( | ||
letters = []rune("abcdefghijklmnopqrstuvwxyz") | ||
configmapUpdateOnChangeAnnotation = "reloader.stakater.com/configmap.update-on-change" | ||
secretUpdateOnChangeAnnotation = "reloader.stakater.com/secret.update-on-change" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
G101: Potential hardcoded credentials
|
||
func TestRollingUpgradeForDeploymentWithSecret(t *testing.T) { | ||
shaData := helper.ConvertSecretToSHA(helper.GetSecret(namespace, secretName, "dGVzdFVwZGF0ZWRTZWNyZXRFbmNvZGluZ0ZvclJlbG9hZGVy")) | ||
handler.RollingUpgradeForDeployment(client, namespace, secretName, shaData, "_SECRET") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of handler.RollingUpgradeForDeployment
is not checked
|
||
func TestRollingUpgradeForDaemonsetWithConfigmap(t *testing.T) { | ||
shaData := helper.ConvertConfigmapToSHA(helper.GetConfigmap(namespace, configmapName, "www.facebook.com")) | ||
handler.RollingUpgradeForDaemonSets(client, namespace, configmapName, shaData, "_CONFIGMAP") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of handler.RollingUpgradeForDaemonSets
is not checked
|
||
func TestRollingUpgradeForDaemonsetWithSecret(t *testing.T) { | ||
shaData := helper.ConvertSecretToSHA(helper.GetSecret(namespace, secretName, "d3d3LmZhY2Vib29rLmNvbQ==")) | ||
handler.RollingUpgradeForDaemonSets(client, namespace, secretName, shaData, "_SECRET") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of handler.RollingUpgradeForDaemonSets
is not checked
|
||
func TestRollingUpgradeForStatefulsetWithConfigmap(t *testing.T) { | ||
shaData := helper.ConvertConfigmapToSHA(helper.GetConfigmap(namespace, configmapName, "www.twitter.com")) | ||
handler.RollingUpgradeForStatefulSets(client, namespace, configmapName, shaData, "_CONFIGMAP") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of handler.RollingUpgradeForStatefulSets
is not checked
|
||
func TestRollingUpgradeForStatefulsetWithSecret(t *testing.T) { | ||
shaData := helper.ConvertSecretToSHA(helper.GetSecret(namespace, secretName, "d3d3LnR3aXR0ZXIuY29t")) | ||
handler.RollingUpgradeForStatefulSets(client, namespace, secretName, shaData, "_SECRET") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of handler.RollingUpgradeForStatefulSets
is not checked
internal/pkg/helper/testUtils.go
Outdated
|
||
if updated != shaData { | ||
return false | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if block ends with a return statement, so drop this else and outdent its block
internal/pkg/helper/testUtils.go
Outdated
|
||
if updated != shaData { | ||
return false | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if block ends with a return statement, so drop this else and outdent its block
@@ -20,11 +32,216 @@ func (r ResourceUpdatedHandler) Handle() error { | |||
// process resource based on its type | |||
if _, ok := r.Resource.(*v1.ConfigMap); ok { | |||
logrus.Infof("Performing 'Updated' action for resource of type 'configmap'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This log should be changed to something like: "Configmap: 'configmapname' updated, performing update action" and then the next log where pods are restarted can say something like this Deployment, Daemonsets or statefulset was reloaded due to change or etc
@faizanahmad055 Yikes! You better fix it before anyone else finds out! Build 4 has Failed! |
internal/pkg/helper/testUtils.go
Outdated
|
||
if updated != shaData { | ||
return false | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if block ends with a return statement, so drop this else and outdent its block
internal/pkg/helper/testUtils.go
Outdated
|
||
if updated != shaData { | ||
return false | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if block ends with a return statement, so drop this else and outdent its block
shaData = helper.ConvertSecretToSHA(r.Resource.(*v1.Secret)) | ||
envNamePostfix = "_SECRET" | ||
} else { | ||
logrus.Warnf("Invalid resource: Resource should be 'Secret' or 'Configmap' but found, %v", r.Resource) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File is not goimports-ed
namespace = r.Resource.(*v1.ConfigMap).Namespace | ||
name = r.Resource.(*v1.ConfigMap).Name | ||
shaData = helper.ConvertConfigmapToSHA(r.Resource.(*v1.ConfigMap)) | ||
envNamePostfix = "_CONFIGMAP" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string _CONFIGMAP
has 4 occurrences, make it a constant
namespace = r.Resource.(*v1.Secret).Namespace | ||
name = r.Resource.(*v1.Secret).Name | ||
shaData = helper.ConvertSecretToSHA(r.Resource.(*v1.Secret)) | ||
envNamePostfix = "_SECRET" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string _SECRET
has 4 occurrences, make it a constant
} | ||
|
||
if rollingUpgradeType == "deployments" { | ||
RollingUpgradeForDeployment(client, namespace, name, shaData, envNamePostfix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of RollingUpgradeForDeployment
is not checked
if rollingUpgradeType == "deployments" { | ||
RollingUpgradeForDeployment(client, namespace, name, shaData, envNamePostfix) | ||
} else if rollingUpgradeType == "daemonsets" { | ||
RollingUpgradeForDaemonSets(client, namespace, name, shaData, envNamePostfix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of RollingUpgradeForDaemonSets
is not checked
} else if rollingUpgradeType == "daemonsets" { | ||
RollingUpgradeForDaemonSets(client, namespace, name, shaData, envNamePostfix) | ||
} else if rollingUpgradeType == "statefulSets" { | ||
RollingUpgradeForStatefulSets(client, namespace, name, shaData, envNamePostfix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of RollingUpgradeForStatefulSets
is not checked
@faizanahmad055 Image is available for testing. |
_, err = secretClient.Create(initSecret(namespace, secretName)) | ||
// Creating secret | ||
secretName := secretNamePrefix + "-update-" + common.RandSeq(5) | ||
data := "dGVzdFNlY3JldEVuY29kaW5nRm9yUmVsb2FkZXI=" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string dGVzdFNlY3JldEVuY29kaW5nRm9yUmVsb2FkZXI=
has 3 occurrences, make it a constant
|
||
// TODO: Add functionality to verify reloader functionality here | ||
// Updating Secret | ||
data = "dGVzdFVwZGF0ZWRTZWNyZXRFbmNvZGluZ0ZvclJlbG9hZGVy" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string dGVzdFVwZGF0ZWRTZWNyZXRFbmNvZGluZ0ZvclJlbG9hZGVy
has 3 occurrences, make it a constant
internal/pkg/testutil/kube.go
Outdated
} else if resourceType == ConfigmapResourceType { | ||
configmap := GetConfigmap(namespace, resourceName, data) | ||
for k, v := range configmap.Data { | ||
values = append(values, k+"="+string(v[:])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary conversion
} | ||
|
||
// Creating deployment | ||
testutil.CreateDeployment(client, configmapName, namespace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of testutil.CreateDeployment
is not checked
|
||
// TODO: Add functionality to verify reloader functionality here | ||
// Creating deployment | ||
testutil.CreateDeployment(client, configmapName, namespace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of testutil.CreateDeployment
is not checked
internal/pkg/handler/update_test.go
Outdated
|
||
func TestRollingUpgradeForDeploymentWithSecret(t *testing.T) { | ||
shaData := testutil.ConvertResourceToSHA(testutil.SecretResourceType, namespace, secretName, "dGVzdFVwZGF0ZWRTZWNyZXRFbmNvZGluZ0ZvclJlbG9hZGVy") | ||
RollingUpgradeDeployment(client, namespace, secretName, shaData, common.SecretEnvarPostfix, common.SecretUpdateOnChangeAnnotation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of RollingUpgradeDeployment
is not checked
internal/pkg/handler/update_test.go
Outdated
|
||
func TestRollingUpgradeForDaemonsetWithConfigmap(t *testing.T) { | ||
shaData := testutil.ConvertResourceToSHA(testutil.ConfigmapResourceType, namespace, configmapName, "www.facebook.com") | ||
RollingUpgradeDaemonSets(client, namespace, configmapName, shaData, common.ConfigmapEnvarPostfix, common.ConfigmapUpdateOnChangeAnnotation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of RollingUpgradeDaemonSets
is not checked
internal/pkg/handler/update_test.go
Outdated
|
||
func TestRollingUpgradeForDaemonsetWithSecret(t *testing.T) { | ||
shaData := testutil.ConvertResourceToSHA(testutil.SecretResourceType, namespace, secretName, "d3d3LmZhY2Vib29rLmNvbQ==") | ||
RollingUpgradeDaemonSets(client, namespace, secretName, shaData, common.SecretEnvarPostfix, common.SecretUpdateOnChangeAnnotation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of RollingUpgradeDaemonSets
is not checked
internal/pkg/handler/update_test.go
Outdated
|
||
func TestRollingUpgradeForStatefulsetWithConfigmap(t *testing.T) { | ||
shaData := testutil.ConvertResourceToSHA(testutil.ConfigmapResourceType, namespace, configmapName, "www.twitter.com") | ||
RollingUpgradeStatefulSets(client, namespace, configmapName, shaData, common.ConfigmapEnvarPostfix, common.ConfigmapUpdateOnChangeAnnotation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of RollingUpgradeStatefulSets
is not checked
internal/pkg/handler/update_test.go
Outdated
|
||
func TestRollingUpgradeForStatefulsetWithSecret(t *testing.T) { | ||
shaData := testutil.ConvertResourceToSHA(testutil.SecretResourceType, namespace, secretName, "d3d3LnR3aXR0ZXIuY29t") | ||
RollingUpgradeStatefulSets(client, namespace, secretName, shaData, common.SecretEnvarPostfix, common.SecretUpdateOnChangeAnnotation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of RollingUpgradeStatefulSets
is not checked
@faizanahmad055 Image is available for testing. |
@faizanahmad055 Yikes! You better fix it before anyone else finds out! Build 8 has Failed! |
@faizanahmad055 Image is available for testing. |
@faizanahmad055 Image is available for testing. |
README.md
Outdated
@@ -21,10 +21,20 @@ For a `Deployment` called `foo` have a `ConfigMap` called `foo`. Then add this a | |||
```yaml | |||
metadata: | |||
annotations: | |||
reloader.stakater.com/update-on-change: "foo" | |||
reloader.stakater.com/configmap.update-on-change: "foo" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@faizanahmad055 update the readme to reflect the new annotations
- list | ||
- get | ||
- update | ||
- patch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we really need watching for daemonsets, deployments and statefulsets? I don't think all these permissions are needed for these. Please verify what is needed for the resources and restrict the RBAC
internal/pkg/common/common.go
Outdated
) | ||
|
||
var ( | ||
letters = []rune("abcdefghijklmnopqrstuvwxyz") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be a part of common. Its only needed for tests so move it to testutil and its respective method as well
internal/pkg/common/common.go
Outdated
|
||
const ( | ||
// ConfigmapUpdateOnChangeAnnotation is an annotation to detect changes in configmaps | ||
ConfigmapUpdateOnChangeAnnotation = "configmap.reloader.stakater.com/reload" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotations mustn't be in common. They belong to either the controller, or in handlers since they're only used there. The tests can simply use them without importing the common package
internal/pkg/common/common.go
Outdated
// SecretUpdateOnChangeAnnotation is an annotation to detect changes in secrets | ||
SecretUpdateOnChangeAnnotation = "secret.reloader.stakater.com/reload" | ||
// ConfigmapEnvarPostfix is a postfix for configmap envVar | ||
ConfigmapEnvarPostfix = "_CONFIGMAP" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a typo in these. Fix the names and move them to where they belong, instead of common
internal/pkg/handler/update.go
Outdated
} | ||
|
||
var shaData, oldSHAdata string | ||
shaData = getSHAfromData(r.Resource) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like that we're checking for resource type again and again. Make the sequence like this:
- Generate config to resource type as mentioned in the comment below
- Generate SHA by passing in the data without checking for the resource type again in the method
- If both SHA's aren't equal, then call the rollingUpgradeInternal method
internal/pkg/handler/update_test.go
Outdated
var ( | ||
client = getClient() | ||
namespace = "test-handler" | ||
configmapName = "testconfigmap-handler-update-" + common.RandSeq(5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to verify that configmap and secret names can be this long
internal/pkg/handler/update_test.go
Outdated
} | ||
|
||
func getClient() *kubernetes.Clientset { | ||
newClient, err := kube.GetClient() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked you to use fake client where controller isn't created. So use that
} | ||
|
||
// Creating a Controller to do a rolling upgrade upon updating the configmap or secret | ||
func getClient() *kubernetes.Clientset { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this duplicated in 2 test cases? Move it to testutil if its needed elsewhere
internal/pkg/testutil/kube.go
Outdated
} | ||
|
||
// VerifyDeploymentUpdate verifies whether deployment has been updated with environment variable or not | ||
func VerifyDeploymentUpdate(client kubernetes.Interface, namespace string, name string, envarPostfix string, shaData string, annotation string) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these verification methods are identical. Use a func for fetching containers for each please and use 1 method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make changes as requested above @faizanahmad055
ConfigmapUpdateOnChangeAnnotation = "configmap.reloader.stakater.com/reload" | ||
// SecretUpdateOnChangeAnnotation is an annotation to detect changes in secrets | ||
SecretUpdateOnChangeAnnotation = "secret.reloader.stakater.com/reload" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File is not goimports-ed
internal/pkg/constants/constants.go
Outdated
SecretEnvarPostfix = "_SECRET" | ||
// EnvVarPrefix is a Prefix for environment variable | ||
EnvVarPrefix = "STAKATER_" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File is not goimports-ed
@faizanahmad055 Image is available for testing. |
@faizanahmad055 Image is available for testing. |
ItemsFunc ItemsFunc | ||
ContainersFunc ContainersFunc | ||
UpdateFunc UpdateFunc | ||
ResourceTypeFunc ResourceTypeFunc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed. Callback functions are only used where you're not sure what the logic for doing a specific task is going to be. Here you know that the resource type is a literal string and can be passed as deployment
etc
} | ||
|
||
// GetDeploymentTypeName returns Deployment resource type | ||
func GetDeploymentTypeName() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove these name funcs
@faizanahmad055 Yikes! You better fix it before anyone else finds out! Build 2 has Failed! |
@faizanahmad055 Yikes! You better fix it before anyone else finds out! Build 1 has Failed! |
@faizanahmad055 Image is available for testing. |
@faizanahmad055 Image is available for testing. |
Work in Progress.