-
Notifications
You must be signed in to change notification settings - Fork 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
OS upgrade implementation for single clusters #20
Changes from all commits
6e9f5e4
c68ffd5
c4496cf
aead1cc
e944079
cc35034
696b08a
23dd6f9
ac585c3
f201d2e
7e1e987
f82727b
1e63caf
fc288b4
c236ccf
58074e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ rules: | |
- delete | ||
- get | ||
- list | ||
- watch | ||
- apiGroups: | ||
- batch | ||
resources: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,19 +4,25 @@ import ( | |
"bytes" | ||
_ "embed" | ||
"fmt" | ||
"path/filepath" | ||
"strings" | ||
"text/template" | ||
|
||
upgradecattlev1 "github.com/rancher/system-upgrade-controller/pkg/apis/upgrade.cattle.io/v1" | ||
"github.com/suse-edge/upgrade-controller/pkg/release" | ||
corev1 "k8s.io/api/core/v1" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
const ( | ||
scriptName = "os-upgrade.sh" | ||
) | ||
|
||
//go:embed templates/os-upgrade.sh.tpl | ||
var osUpgradeScript string | ||
|
||
func OSUpgradeSecret(releaseOS *release.OperatingSystem) (*corev1.Secret, error) { | ||
const ( | ||
scriptName = "os-upgrade.sh" | ||
secretName = "os-upgrade-secret" | ||
) | ||
|
||
|
@@ -45,7 +51,7 @@ func OSUpgradeSecret(releaseOS *release.OperatingSystem) (*corev1.Secret, error) | |
} | ||
|
||
secret := &corev1.Secret{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: secretName, | ||
Namespace: planNamespace, | ||
}, | ||
|
@@ -57,3 +63,71 @@ func OSUpgradeSecret(releaseOS *release.OperatingSystem) (*corev1.Secret, error) | |
|
||
return secret, nil | ||
} | ||
|
||
func OSControlPlanePlan(releaseVersion, secretName string, releaseOS *release.OperatingSystem) *upgradecattlev1.Plan { | ||
const ( | ||
planImage = "registry.suse.com/bci/bci-base:15.5" | ||
) | ||
|
||
controlPlanePlanName := osPlanName(controlPlaneKey, releaseOS.ZypperID, releaseOS.Version) | ||
controlPlanePlan := baseUpgradePlan(controlPlanePlanName) | ||
controlPlanePlan.Labels = map[string]string{ | ||
"os-upgrade": "control-plane", | ||
} | ||
controlPlanePlan.Spec.Concurrency = 1 | ||
controlPlanePlan.Spec.NodeSelector = &metav1.LabelSelector{ | ||
MatchExpressions: []metav1.LabelSelectorRequirement{ | ||
{ | ||
Key: ControlPlaneLabel, | ||
Operator: "In", | ||
Values: []string{ | ||
"true", | ||
}, | ||
}, | ||
}, | ||
} | ||
controlPlanePlan.Spec.Tolerations = []corev1.Toleration{ | ||
{ | ||
Key: "CriticalAddonsOnly", | ||
Operator: "Equal", | ||
Value: "true", | ||
Effect: "NoExecute", | ||
}, | ||
{ | ||
Key: ControlPlaneLabel, | ||
Operator: "Equal", | ||
Value: "", | ||
Effect: "NoSchedule", | ||
}, | ||
{ | ||
Key: "node-role.kubernetes.io/etcd", | ||
Operator: "Equal", | ||
Value: "", | ||
Effect: "NoExecute", | ||
}, | ||
} | ||
|
||
secretPathRelativeToHost := fmt.Sprintf("/run/system-upgrade/secrets/%s", secretName) | ||
mountPath := filepath.Join("/host", secretPathRelativeToHost) | ||
controlPlanePlan.Spec.Secrets = []upgradecattlev1.SecretSpec{ | ||
{ | ||
Name: secretName, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know it is tempting to just use the constants here but wouldn't it be better if the secret name and script are passed to the function from the outside? Both can be extracted from the secret that we query. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved the |
||
Path: mountPath, | ||
}, | ||
} | ||
controlPlanePlan.Spec.Cordon = true | ||
controlPlanePlan.Spec.Version = releaseVersion | ||
|
||
controlPlanePlan.Spec.JobActiveDeadlineSecs = 3600 | ||
|
||
controlPlanePlan.Spec.Upgrade = &upgradecattlev1.ContainerSpec{ | ||
Image: planImage, | ||
Command: []string{"chroot", "/host"}, | ||
Args: []string{"sh", filepath.Join(secretPathRelativeToHost, scriptName)}, | ||
} | ||
return controlPlanePlan | ||
} | ||
|
||
func osPlanName(typeKey, osName, osVersion string) string { | ||
return fmt.Sprintf("%s-%s-%s", typeKey, strings.ToLower(osName), strings.ReplaceAll(osVersion, ".", "-")) | ||
} |
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 approach is fine and will work but I might look into simplifying it when I have some time.
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.
Sounds good, I did it like this mainly because it was the least invasive method of introducing this in the existing code.