Skip to content

Commit c685d31

Browse files
committed
feat: add instructions to patch system-upgrade-controller
Signed-off-by: PoAn Yang <[email protected]>
1 parent fd9194c commit c685d31

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

pkg/plan/bootstrap.go

+22
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,28 @@ func (p *plan) addInstructions(cfg *config.Config, dataDir string) error {
156156
}
157157
}
158158

159+
// Above Rancher v2.10.x, we should patch system-upgrade-controller with meta.helm.sh/release-name:mcc-local-managed-system-upgrade-controller to continue cluster intialization.
160+
if semver.Compare(cfg.RancherVersion, "v2.10.0") >= 0 {
161+
if err := p.addInstruction(rancher.ToWaitLocalManagedSystemUpgradeControllerInstruction(k8sVersion)); err != nil {
162+
return err
163+
}
164+
if err := p.addInstruction(rancher.ToPatchSUCServiceAccountInstruction(k8sVersion)); err != nil {
165+
return err
166+
}
167+
if err := p.addInstruction(rancher.ToPatchSUCClusterRoleBindingInstruction(k8sVersion)); err != nil {
168+
return err
169+
}
170+
if err := p.addInstruction(rancher.ToPatchSUCConfigMapInstruction(k8sVersion)); err != nil {
171+
return err
172+
}
173+
if err := p.addInstruction(rancher.ToPatchSUCDeploymentInstruction(k8sVersion)); err != nil {
174+
return err
175+
}
176+
if err := p.addInstruction(rancher.ToDeleteSUCInstruction(k8sVersion)); err != nil {
177+
return err
178+
}
179+
}
180+
159181
if err := p.addInstruction(rancher.ToWaitSUCInstruction(cfg.RancherInstallerImage, cfg.SystemDefaultRegistry, k8sVersion)); err != nil {
160182
return err
161183
}

pkg/rancher/wait.go

+84
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,90 @@ func ToWaitSUCInstruction(_, _, k8sVersion string) (*applyinator.Instruction, er
5252
}, nil
5353
}
5454

55+
func ToWaitLocalManagedSystemUpgradeControllerInstruction(k8sVersion string) (*applyinator.Instruction, error) {
56+
cmd, err := self.Self()
57+
if err != nil {
58+
return nil, fmt.Errorf("resolving location of %s: %w", os.Args[0], err)
59+
}
60+
return &applyinator.Instruction{
61+
Name: "wait-system-upgrade-controller",
62+
SaveOutput: true,
63+
Args: []string{"retry", kubectl.Command(k8sVersion), "-n", "fleet-local", "get", "managedchart", "local-managed-system-upgrade-controller"},
64+
Env: kubectl.Env(k8sVersion),
65+
Command: cmd,
66+
}, nil
67+
}
68+
69+
func ToPatchSUCServiceAccountInstruction(k8sVersion string) (*applyinator.Instruction, error) {
70+
cmd, err := self.Self()
71+
if err != nil {
72+
return nil, fmt.Errorf("resolving location of %s: %w", os.Args[0], err)
73+
}
74+
return &applyinator.Instruction{
75+
Name: "patch-system-upgrade-controller-serviceaccount",
76+
SaveOutput: true,
77+
Args: []string{"retry", kubectl.Command(k8sVersion), "annotate", "--overwrite", "serviceaccount", "-n", "cattle-system", "system-upgrade-controller", "meta.helm.sh/release-name=mcc-local-managed-system-upgrade-controller"},
78+
Env: kubectl.Env(k8sVersion),
79+
Command: cmd,
80+
}, nil
81+
}
82+
83+
func ToPatchSUCConfigMapInstruction(k8sVersion string) (*applyinator.Instruction, error) {
84+
cmd, err := self.Self()
85+
if err != nil {
86+
return nil, fmt.Errorf("resolving location of %s: %w", os.Args[0], err)
87+
}
88+
return &applyinator.Instruction{
89+
Name: "patch-system-upgrade-controller-configmap",
90+
SaveOutput: true,
91+
Args: []string{"retry", kubectl.Command(k8sVersion), "annotate", "--overwrite", "configmap", "-n", "cattle-system", "system-upgrade-controller-config", "meta.helm.sh/release-name=mcc-local-managed-system-upgrade-controller"},
92+
Env: kubectl.Env(k8sVersion),
93+
Command: cmd,
94+
}, nil
95+
}
96+
97+
func ToPatchSUCClusterRoleBindingInstruction(k8sVersion string) (*applyinator.Instruction, error) {
98+
cmd, err := self.Self()
99+
if err != nil {
100+
return nil, fmt.Errorf("resolving location of %s: %w", os.Args[0], err)
101+
}
102+
return &applyinator.Instruction{
103+
Name: "patch-system-upgrade-controller-clusterrolebinding",
104+
SaveOutput: true,
105+
Args: []string{"retry", kubectl.Command(k8sVersion), "annotate", "--overwrite", "clusterrolebinding", "-n", "cattle-system", "system-upgrade-controller", "meta.helm.sh/release-name=mcc-local-managed-system-upgrade-controller"},
106+
Env: kubectl.Env(k8sVersion),
107+
Command: cmd,
108+
}, nil
109+
}
110+
111+
func ToPatchSUCDeploymentInstruction(k8sVersion string) (*applyinator.Instruction, error) {
112+
cmd, err := self.Self()
113+
if err != nil {
114+
return nil, fmt.Errorf("resolving location of %s: %w", os.Args[0], err)
115+
}
116+
return &applyinator.Instruction{
117+
Name: "patch-system-upgrade-controller-deployment",
118+
SaveOutput: true,
119+
Args: []string{"retry", kubectl.Command(k8sVersion), "annotate", "--overwrite", "deployment", "-n", "cattle-system", "system-upgrade-controller", "meta.helm.sh/release-name=mcc-local-managed-system-upgrade-controller"},
120+
Env: kubectl.Env(k8sVersion),
121+
Command: cmd,
122+
}, nil
123+
}
124+
125+
func ToDeleteSUCInstruction(k8sVersion string) (*applyinator.Instruction, error) {
126+
cmd, err := self.Self()
127+
if err != nil {
128+
return nil, fmt.Errorf("resolving location of %s: %w", os.Args[0], err)
129+
}
130+
return &applyinator.Instruction{
131+
Name: "patch-system-upgrade-controller-deployment",
132+
SaveOutput: true,
133+
Args: []string{"retry", kubectl.Command(k8sVersion), "delete", "bundle", "-n", "cattle-system", "mcc-local-managed-system-upgrade-controller"},
134+
Env: kubectl.Env(k8sVersion),
135+
Command: cmd,
136+
}, nil
137+
}
138+
55139
func ToWaitSUCPlanInstruction(_, _, k8sVersion string) (*applyinator.Instruction, error) {
56140
cmd, err := self.Self()
57141
if err != nil {

0 commit comments

Comments
 (0)