Skip to content

Conversation

faizanahmad055
Copy link
Contributor

Work in Progress.

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"

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"

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"

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)

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)

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)

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)

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

@stakater-user
Copy link
Contributor

@faizanahmad055 Image is available for testing. docker pull stakater/reloader:PR-2-1

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"
Copy link
Member

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"
Copy link
Member

@hazim1093 hazim1093 Jul 17, 2018

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 {

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 {

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"

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"

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"))

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"

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"

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

// GenerateSHA generates SHA from string
func GenerateSHA(data string) string {
hasher := sha1.New()
io.WriteString(hasher, data)

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

@stakater-user
Copy link
Contributor

@faizanahmad055 Image is available for testing. docker pull stakater/reloader:PR-2-2

}

if rollingUpgradeType == "deployments" {
rollingUpgradeForDeployment(client, namespace, name, sshData, envName)

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)

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)

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

@stakater-user
Copy link
Contributor

@faizanahmad055 Image is available for testing. docker pull stakater/reloader:PR-2-3

Copy link
Contributor

@waseem-h waseem-h left a 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"
Copy link
Contributor

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")
Copy link
Contributor

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"
Copy link
Contributor

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)
Copy link
Contributor

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

Copy link
Contributor

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
Copy link
Contributor

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

}

// ConvertConfigmapToSHA generates SHA for configmap data
func ConvertConfigmapToSHA(cm *v1.ConfigMap) string {
Copy link
Contributor

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)
Copy link
Member

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

}
sort.Strings(values)
sha := GenerateSHA(strings.Join(values, ";"))
logrus.Infof("SHA for configmap data: %s", sha)
Copy link
Member

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)
Copy link
Member

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

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


if updated != shaData {
return false
} else {

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


if updated != shaData {
return false
} else {

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


if updated != shaData {
return false
} else {

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

var (
letters = []rune("abcdefghijklmnopqrstuvwxyz")
configmapUpdateOnChangeAnnotation = "reloader.stakater.com/configmap.update-on-change"
secretUpdateOnChangeAnnotation = "reloader.stakater.com/secret.update-on-change"

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")

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")

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")

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")

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")

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


if updated != shaData {
return false
} else {

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


if updated != shaData {
return false
} else {

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'")
Copy link
Member

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

@stakater-user
Copy link
Contributor

@faizanahmad055 Yikes! You better fix it before anyone else finds out! Build 4 has Failed!


if updated != shaData {
return false
} else {

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


if updated != shaData {
return false
} else {

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)

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"

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"

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)

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)

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)

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

@stakater-user
Copy link
Contributor

@faizanahmad055 Image is available for testing. docker pull stakater/reloader:PR-2-5

_, err = secretClient.Create(initSecret(namespace, secretName))
// Creating secret
secretName := secretNamePrefix + "-update-" + common.RandSeq(5)
data := "dGVzdFNlY3JldEVuY29kaW5nRm9yUmVsb2FkZXI="

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"

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

} else if resourceType == ConfigmapResourceType {
configmap := GetConfigmap(namespace, resourceName, data)
for k, v := range configmap.Data {
values = append(values, k+"="+string(v[:]))

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)

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)

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


func TestRollingUpgradeForDeploymentWithSecret(t *testing.T) {
shaData := testutil.ConvertResourceToSHA(testutil.SecretResourceType, namespace, secretName, "dGVzdFVwZGF0ZWRTZWNyZXRFbmNvZGluZ0ZvclJlbG9hZGVy")
RollingUpgradeDeployment(client, namespace, secretName, shaData, common.SecretEnvarPostfix, common.SecretUpdateOnChangeAnnotation)

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


func TestRollingUpgradeForDaemonsetWithConfigmap(t *testing.T) {
shaData := testutil.ConvertResourceToSHA(testutil.ConfigmapResourceType, namespace, configmapName, "www.facebook.com")
RollingUpgradeDaemonSets(client, namespace, configmapName, shaData, common.ConfigmapEnvarPostfix, common.ConfigmapUpdateOnChangeAnnotation)

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


func TestRollingUpgradeForDaemonsetWithSecret(t *testing.T) {
shaData := testutil.ConvertResourceToSHA(testutil.SecretResourceType, namespace, secretName, "d3d3LmZhY2Vib29rLmNvbQ==")
RollingUpgradeDaemonSets(client, namespace, secretName, shaData, common.SecretEnvarPostfix, common.SecretUpdateOnChangeAnnotation)

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


func TestRollingUpgradeForStatefulsetWithConfigmap(t *testing.T) {
shaData := testutil.ConvertResourceToSHA(testutil.ConfigmapResourceType, namespace, configmapName, "www.twitter.com")
RollingUpgradeStatefulSets(client, namespace, configmapName, shaData, common.ConfigmapEnvarPostfix, common.ConfigmapUpdateOnChangeAnnotation)

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


func TestRollingUpgradeForStatefulsetWithSecret(t *testing.T) {
shaData := testutil.ConvertResourceToSHA(testutil.SecretResourceType, namespace, secretName, "d3d3LnR3aXR0ZXIuY29t")
RollingUpgradeStatefulSets(client, namespace, secretName, shaData, common.SecretEnvarPostfix, common.SecretUpdateOnChangeAnnotation)

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

@stakater-user
Copy link
Contributor

@faizanahmad055 Image is available for testing. docker pull stakater/reloader:PR-2-6

@stakater-user
Copy link
Contributor

@faizanahmad055 Yikes! You better fix it before anyone else finds out! Build 8 has Failed!

@stakater-user
Copy link
Contributor

@faizanahmad055 Image is available for testing. docker pull stakater/reloader:PR-2-9

@stakater-user
Copy link
Contributor

@faizanahmad055 Image is available for testing. docker pull stakater/reloader:PR-2-10

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"
Copy link
Contributor

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
Copy link
Contributor

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

)

var (
letters = []rune("abcdefghijklmnopqrstuvwxyz")
Copy link
Contributor

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


const (
// ConfigmapUpdateOnChangeAnnotation is an annotation to detect changes in configmaps
ConfigmapUpdateOnChangeAnnotation = "configmap.reloader.stakater.com/reload"
Copy link
Contributor

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

// SecretUpdateOnChangeAnnotation is an annotation to detect changes in secrets
SecretUpdateOnChangeAnnotation = "secret.reloader.stakater.com/reload"
// ConfigmapEnvarPostfix is a postfix for configmap envVar
ConfigmapEnvarPostfix = "_CONFIGMAP"
Copy link
Contributor

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

}

var shaData, oldSHAdata string
shaData = getSHAfromData(r.Resource)
Copy link
Contributor

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

var (
client = getClient()
namespace = "test-handler"
configmapName = "testconfigmap-handler-update-" + common.RandSeq(5)
Copy link
Contributor

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

}

func getClient() *kubernetes.Clientset {
newClient, err := kube.GetClient()
Copy link
Contributor

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 {
Copy link
Contributor

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

}

// 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 {
Copy link
Contributor

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

Copy link
Contributor

@waseem-h waseem-h left a 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"
)

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

SecretEnvarPostfix = "_SECRET"
// EnvVarPrefix is a Prefix for environment variable
EnvVarPrefix = "STAKATER_"
)

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

@stakater-user
Copy link
Contributor

@faizanahmad055 Image is available for testing. docker pull stakater/reloader:PR-2-11

@stakater-user
Copy link
Contributor

@faizanahmad055 Image is available for testing. docker pull stakater/reloader:PR-2-12

ItemsFunc ItemsFunc
ContainersFunc ContainersFunc
UpdateFunc UpdateFunc
ResourceTypeFunc ResourceTypeFunc
Copy link
Contributor

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these name funcs

@waseem-h waseem-h closed this Jul 26, 2018
@stakater-user
Copy link
Contributor

@faizanahmad055 Yikes! You better fix it before anyone else finds out! Build 2 has Failed!

@stakater-user
Copy link
Contributor

@faizanahmad055 Yikes! You better fix it before anyone else finds out! Build 1 has Failed!

@stakater-user
Copy link
Contributor

@faizanahmad055 Image is available for testing. docker pull stakater/reloader:PR-2-3

@stakater-user
Copy link
Contributor

@faizanahmad055 Image is available for testing. docker pull stakater/reloader:PR-2-4

@waseem-h waseem-h merged commit 0b0679b into master Jul 26, 2018
@waseem-h waseem-h deleted the rollback-upgrade-deployment branch July 26, 2018 11:15
faizanahmad055 pushed a commit that referenced this pull request Jan 5, 2023
Felix-Stakater pushed a commit that referenced this pull request May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants