Skip to content

Commit

Permalink
Merge pull request #423 from alexander-demicev/cherrypick-422
Browse files Browse the repository at this point in the history
[release-0.6] Ignore changes injected by Turtles when doing CP rollout
  • Loading branch information
alexander-demicev authored Aug 30, 2024
2 parents 8e06dcc + e68e3e3 commit 9e0ddd5
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion pkg/rke2/machine_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func matchesRKE2BootstrapConfig(machineConfigs map[string]*bootstrapv1.RKE2Confi
return true
}

// Check if RCP and machine RKE2Config matche, if not return
// Check if RCP and machine RKE2Config matches, if not return
if match := matchServerConfig(rcp, machine); !match {
return false
}
Expand All @@ -54,6 +54,42 @@ func matchesRKE2BootstrapConfig(machineConfigs map[string]*bootstrapv1.RKE2Confi
return true
}

if _, ok := machineConfig.Annotations["cluster-api.cattle.io/turtles-system-agent"]; ok {
files := []bootstrapv1.File{}

for _, file := range machineConfig.Spec.Files {
switch file.Path {
case "/etc/rancher/agent/connect-info-config.json", "/opt/system-agent-install.sh",
"/etc/rancher/agent/config.yaml": // Filter out files that are injected by the Rancher Turtles webhook
continue
}

files = append(files, file)
}

if len(files) == 0 {
machineConfig.Spec.Files = nil // Set to nil because rcp.Spec.RKE2ConfigSpec.Files will be nil if no files are present
} else {
machineConfig.Spec.Files = files
}

cmds := []string{}

for _, cmd := range machineConfig.Spec.PostRKE2Commands { // Filter out commands that are injected by the Rancher Turtles webhook
if cmd == "sudo sh /opt/system-agent-install.sh" {
continue
}

cmds = append(cmds, cmd)
}

if len(cmds) == 0 {
machineConfig.Spec.PostRKE2Commands = nil // Set to nil because rcp.Spec.RKE2ConfigSpec.PostRKE2Commands will be nil if no commands are present
} else {
machineConfig.Spec.PostRKE2Commands = cmds
}
}

// Check if RCP AgentConfig and machineBootstrapConfig matches
return reflect.DeepEqual(machineConfig.Spec, rcp.Spec.RKE2ConfigSpec)
}
Expand Down

0 comments on commit 9e0ddd5

Please sign in to comment.