Skip to content
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

Bugfix kops update always detecting changes when using ExecContainerAction. #3790

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions pkg/model/bootstrapscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,17 @@ func (b *BootstrapScript) getRelevantHooks(allHooks []kops.HookSpec, role kops.I
}

if hook.ExecContainer != nil && hook.ExecContainer.Command != nil {
execContainerCommandFingerprint, err := b.computeFingerprint(hook.ExecContainer.Command)
execContainerCommandFingerprint, err := b.computeFingerprint(strings.Join(hook.ExecContainer.Command[:], " "))
if err != nil {
return nil, err
}
hook.ExecContainer.Command = []string{execContainerCommandFingerprint + " (fingerprint)"}

execContainerAction := &kops.ExecContainerAction{
Command: []string{execContainerCommandFingerprint + " (fingerprint)"},
Environment: hook.ExecContainer.Environment,
Image: hook.ExecContainer.Image,
}
hook.ExecContainer = execContainerAction
}

hook.Roles = nil
Expand Down Expand Up @@ -248,16 +254,11 @@ func (b *BootstrapScript) getRelevantFileAssets(allFileAssets []kops.FileAssetSp
return fileAssets, nil
}

// computeFingerprint takes an object and returns a base64 encoded fingerprint
func (b *BootstrapScript) computeFingerprint(obj interface{}) (string, error) {
// computeFingerprint takes a string and returns a base64 encoded fingerprint
func (b *BootstrapScript) computeFingerprint(content string) (string, error) {
hasher := sha1.New()

data, err := kops.ToRawYaml(obj)
if err != nil {
return "", err
}

if _, err := hasher.Write(data); err != nil {
if _, err := hasher.Write([]byte(content)); err != nil {
return "", fmt.Errorf("error computing fingerprint hash: %v", err)
}

Expand Down
8 changes: 7 additions & 1 deletion pkg/model/bootstrapscript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ func TestBootstrapUserData(t *testing.T) {
NodeUpConfigBuilder: renderNodeUpConfig,
}

// Purposely running this twice to cover issue #3516
_, err := bs.ResourceNodeUp(group, &spec)
if err != nil {
t.Errorf("case %d failed to create nodeup resource. error: %s", i, err)
continue
}
res, err := bs.ResourceNodeUp(group, &spec)
if err != nil {
t.Errorf("case %d failed to create nodeup resource. error: %s", i, err)
Expand Down Expand Up @@ -209,7 +215,7 @@ func makeTestCluster(hookSpecRoles []kops.InstanceGroupRole, fileAssetSpecRoles
Command: []string{
"sh",
"-c",
"chroot /rootfs apt-get update && chroot /rootfs apt-get install -y ceph-common",
"apt-get update",
},
Image: "busybox",
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/model/tests/data/bootstrapscript_0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ __EOF_CLUSTER_SPEC

cat > ig_spec.yaml << '__EOF_IG_SPEC'
fileAssets:
- content: tre8+iQw12cCsccJY3cQk4HQV3g= (fingerprint)
- content: xYagtQLwBAAi3V8Wc2Jrojz28I0= (fingerprint)
name: tokens
path: /kube/tokens.csv
hooks:
- manifest: FdicqEXLciSI1yRjQxsrye3QivU= (fingerprint)
- manifest: 8BN3anFUyDlkVF/JnaJqbwpq8ME= (fingerprint)
name: apply-to-all.service
kubelet:
kubeconfigPath: /etc/kubernetes/igconfig.txt
Expand Down
12 changes: 6 additions & 6 deletions pkg/model/tests/data/bootstrapscript_1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ cloudConfig:
docker:
logLevel: INFO
fileAssets:
- content: 4/KwQntXJBIluh/8K2f+zWTQdhM= (fingerprint)
- content: E1oeAbrnQsSldrIP1BpoP2SDykM= (fingerprint)
name: iptables-restore
path: /var/lib/iptables/rules-save
hooks:
- execContainer:
command:
- ChIIt0bv6sTY/wwaEWTBNaObBgM= (fingerprint)
- pkF7ytM3ENpYWZF36FoHJsqXP5Y= (fingerprint)
image: busybox
kubeAPIServer:
image: CoreOS
Expand All @@ -186,19 +186,19 @@ __EOF_CLUSTER_SPEC

cat > ig_spec.yaml << '__EOF_IG_SPEC'
fileAssets:
- content: 4/KwQntXJBIluh/8K2f+zWTQdhM= (fingerprint)
- content: E1oeAbrnQsSldrIP1BpoP2SDykM= (fingerprint)
name: iptables-restore
path: /var/lib/iptables/rules-save
- content: tre8+iQw12cCsccJY3cQk4HQV3g= (fingerprint)
- content: xYagtQLwBAAi3V8Wc2Jrojz28I0= (fingerprint)
name: tokens
path: /kube/tokens.csv
hooks:
- before:
- update-engine.service
- kubelet.service
manifest: LSdpmOQebIkYoG0lRv8AUHCBIyg= (fingerprint)
manifest: /uSPh015xYXh8dAVqXjP/ePkbrM= (fingerprint)
name: disable-update-engine.service
- manifest: FdicqEXLciSI1yRjQxsrye3QivU= (fingerprint)
- manifest: 8BN3anFUyDlkVF/JnaJqbwpq8ME= (fingerprint)
name: apply-to-all.service
kubelet:
kubeconfigPath: /etc/kubernetes/igconfig.txt
Expand Down
12 changes: 6 additions & 6 deletions pkg/model/tests/data/bootstrapscript_2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ cloudConfig:
docker:
logLevel: INFO
fileAssets:
- content: 4/KwQntXJBIluh/8K2f+zWTQdhM= (fingerprint)
- content: E1oeAbrnQsSldrIP1BpoP2SDykM= (fingerprint)
name: iptables-restore
path: /var/lib/iptables/rules-save
hooks:
- execContainer:
command:
- ChIIt0bv6sTY/wwaEWTBNaObBgM= (fingerprint)
- pkF7ytM3ENpYWZF36FoHJsqXP5Y= (fingerprint)
image: busybox
kubeAPIServer:
image: CoreOS
Expand All @@ -186,19 +186,19 @@ __EOF_CLUSTER_SPEC

cat > ig_spec.yaml << '__EOF_IG_SPEC'
fileAssets:
- content: 4/KwQntXJBIluh/8K2f+zWTQdhM= (fingerprint)
- content: E1oeAbrnQsSldrIP1BpoP2SDykM= (fingerprint)
name: iptables-restore
path: /var/lib/iptables/rules-save
- content: tre8+iQw12cCsccJY3cQk4HQV3g= (fingerprint)
- content: xYagtQLwBAAi3V8Wc2Jrojz28I0= (fingerprint)
name: tokens
path: /kube/tokens.csv
hooks:
- before:
- update-engine.service
- kubelet.service
manifest: LSdpmOQebIkYoG0lRv8AUHCBIyg= (fingerprint)
manifest: /uSPh015xYXh8dAVqXjP/ePkbrM= (fingerprint)
name: disable-update-engine.service
- manifest: FdicqEXLciSI1yRjQxsrye3QivU= (fingerprint)
- manifest: 8BN3anFUyDlkVF/JnaJqbwpq8ME= (fingerprint)
name: apply-to-all.service
kubelet:
kubeconfigPath: /etc/kubernetes/igconfig.txt
Expand Down
4 changes: 2 additions & 2 deletions pkg/model/tests/data/bootstrapscript_3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ __EOF_CLUSTER_SPEC

cat > ig_spec.yaml << '__EOF_IG_SPEC'
fileAssets:
- content: tre8+iQw12cCsccJY3cQk4HQV3g= (fingerprint)
- content: xYagtQLwBAAi3V8Wc2Jrojz28I0= (fingerprint)
name: tokens
path: /kube/tokens.csv
hooks:
- manifest: FdicqEXLciSI1yRjQxsrye3QivU= (fingerprint)
- manifest: 8BN3anFUyDlkVF/JnaJqbwpq8ME= (fingerprint)
name: apply-to-all.service
kubelet:
kubeconfigPath: /etc/kubernetes/igconfig.txt
Expand Down
12 changes: 6 additions & 6 deletions pkg/model/tests/data/bootstrapscript_4.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ cloudConfig:
docker:
logLevel: INFO
fileAssets:
- content: 4/KwQntXJBIluh/8K2f+zWTQdhM= (fingerprint)
- content: E1oeAbrnQsSldrIP1BpoP2SDykM= (fingerprint)
name: iptables-restore
path: /var/lib/iptables/rules-save
hooks:
- execContainer:
command:
- ChIIt0bv6sTY/wwaEWTBNaObBgM= (fingerprint)
- pkF7ytM3ENpYWZF36FoHJsqXP5Y= (fingerprint)
image: busybox
kubeProxy:
cpuRequest: 30m
Expand All @@ -178,19 +178,19 @@ __EOF_CLUSTER_SPEC

cat > ig_spec.yaml << '__EOF_IG_SPEC'
fileAssets:
- content: 4/KwQntXJBIluh/8K2f+zWTQdhM= (fingerprint)
- content: E1oeAbrnQsSldrIP1BpoP2SDykM= (fingerprint)
name: iptables-restore
path: /var/lib/iptables/rules-save
- content: tre8+iQw12cCsccJY3cQk4HQV3g= (fingerprint)
- content: xYagtQLwBAAi3V8Wc2Jrojz28I0= (fingerprint)
name: tokens
path: /kube/tokens.csv
hooks:
- before:
- update-engine.service
- kubelet.service
manifest: LSdpmOQebIkYoG0lRv8AUHCBIyg= (fingerprint)
manifest: /uSPh015xYXh8dAVqXjP/ePkbrM= (fingerprint)
name: disable-update-engine.service
- manifest: FdicqEXLciSI1yRjQxsrye3QivU= (fingerprint)
- manifest: 8BN3anFUyDlkVF/JnaJqbwpq8ME= (fingerprint)
name: apply-to-all.service
kubelet:
kubeconfigPath: /etc/kubernetes/igconfig.txt
Expand Down
12 changes: 6 additions & 6 deletions pkg/model/tests/data/bootstrapscript_5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ cloudConfig:
docker:
logLevel: INFO
fileAssets:
- content: 4/KwQntXJBIluh/8K2f+zWTQdhM= (fingerprint)
- content: E1oeAbrnQsSldrIP1BpoP2SDykM= (fingerprint)
name: iptables-restore
path: /var/lib/iptables/rules-save
hooks:
- execContainer:
command:
- ChIIt0bv6sTY/wwaEWTBNaObBgM= (fingerprint)
- pkF7ytM3ENpYWZF36FoHJsqXP5Y= (fingerprint)
image: busybox
kubeProxy:
cpuRequest: 30m
Expand All @@ -178,19 +178,19 @@ __EOF_CLUSTER_SPEC

cat > ig_spec.yaml << '__EOF_IG_SPEC'
fileAssets:
- content: 4/KwQntXJBIluh/8K2f+zWTQdhM= (fingerprint)
- content: E1oeAbrnQsSldrIP1BpoP2SDykM= (fingerprint)
name: iptables-restore
path: /var/lib/iptables/rules-save
- content: tre8+iQw12cCsccJY3cQk4HQV3g= (fingerprint)
- content: xYagtQLwBAAi3V8Wc2Jrojz28I0= (fingerprint)
name: tokens
path: /kube/tokens.csv
hooks:
- before:
- update-engine.service
- kubelet.service
manifest: LSdpmOQebIkYoG0lRv8AUHCBIyg= (fingerprint)
manifest: /uSPh015xYXh8dAVqXjP/ePkbrM= (fingerprint)
name: disable-update-engine.service
- manifest: FdicqEXLciSI1yRjQxsrye3QivU= (fingerprint)
- manifest: 8BN3anFUyDlkVF/JnaJqbwpq8ME= (fingerprint)
name: apply-to-all.service
kubelet:
kubeconfigPath: /etc/kubernetes/igconfig.txt
Expand Down