Skip to content

Commit d3da0f6

Browse files
authored
Merge pull request #40 from FrankYang0529/HARV-6584
fix: add patch local provisioing cluster status for rancher v2.9.x
2 parents bee45cd + dedbc05 commit d3da0f6

File tree

5 files changed

+50
-7
lines changed

5 files changed

+50
-7
lines changed

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ require (
4646
github.com/sirupsen/logrus v1.8.1
4747
github.com/spf13/cobra v1.7.0
4848
golang.org/x/crypto v0.14.0
49+
golang.org/x/mod v0.8.0
4950
gopkg.in/yaml.v2 v2.4.0
5051
gopkg.in/yaml.v3 v3.0.1
5152
k8s.io/api v0.28.3

go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -2172,6 +2172,7 @@ golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
21722172
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
21732173
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
21742174
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
2175+
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
21752176
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
21762177
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
21772178
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=

pkg/plan/bootstrap.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package plan
33
import (
44
"context"
55
"fmt"
6-
"strings"
76

87
"github.com/rancher/system-agent/pkg/applyinator"
8+
"golang.org/x/mod/semver"
99

1010
"github.com/rancher/rancherd/pkg/cacerts"
1111
"github.com/rancher/rancherd/pkg/config"
@@ -131,17 +131,31 @@ func (p *plan) addInstructions(cfg *config.Config, dataDir string) error {
131131
return err
132132
}
133133

134+
// Above Rancher v2.9.x, we cannot patch provisioing cluster with empty rkeConfig,
135+
// so we need to delete the webhook validation configuration.
136+
if semver.Compare(cfg.RancherVersion, "v2.9.0") >= 0 {
137+
if err := p.addInstruction(rancher.ToDeleteRancherWebhookValidationConfiguration(k8sVersion)); err != nil {
138+
return err
139+
}
140+
}
141+
134142
if err := p.addInstruction(resources.ToInstruction(cfg.RancherInstallerImage, cfg.SystemDefaultRegistry, k8sVersion, dataDir)); err != nil {
135143
return err
136144
}
137145

138-
// currently instruction is only needed for v2.8.x
139-
if strings.HasPrefix(cfg.RancherVersion, "v2.8") {
146+
// currently instruction is needed for version above v2.8.x
147+
if semver.Compare(cfg.RancherVersion, "v2.8.0") >= 0 {
140148
if err := p.addInstruction(rancher.PatchLocalProvisioningClusterStatus(cfg.RancherInstallerImage, cfg.SystemDefaultRegistry, k8sVersion)); err != nil {
141149
return err
142150
}
143151
}
144152

153+
if semver.Compare(cfg.RancherVersion, "v2.9.0") >= 0 {
154+
if err := p.addInstruction(rancher.ToRestartRancherWebhookInstruction(k8sVersion)); err != nil {
155+
return err
156+
}
157+
}
158+
145159
if err := p.addInstruction(rancher.ToWaitSUCInstruction(cfg.RancherInstallerImage, cfg.SystemDefaultRegistry, k8sVersion)); err != nil {
146160
return err
147161
}

pkg/rancher/wait.go

+29-1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,34 @@ func ToScaleUpFleetControllerInstruction(_, _, k8sVersion string) (*applyinator.
124124
}, nil
125125
}
126126

127+
func ToDeleteRancherWebhookValidationConfiguration(k8sVersion string) (*applyinator.Instruction, error) {
128+
cmd, err := self.Self()
129+
if err != nil {
130+
return nil, fmt.Errorf("resolving location of %s: %w", os.Args[0], err)
131+
}
132+
return &applyinator.Instruction{
133+
Name: "delete-rancher-webhook-validation-configuration",
134+
SaveOutput: true,
135+
Args: []string{"retry", kubectl.Command(k8sVersion), "delete", "validatingwebhookconfiguration", "rancher.cattle.io"},
136+
Env: kubectl.Env(k8sVersion),
137+
Command: cmd,
138+
}, nil
139+
}
140+
141+
func ToRestartRancherWebhookInstruction(k8sVersion string) (*applyinator.Instruction, error) {
142+
cmd, err := self.Self()
143+
if err != nil {
144+
return nil, fmt.Errorf("resolving location of %s: %w", os.Args[0], err)
145+
}
146+
return &applyinator.Instruction{
147+
Name: "wait-rancher-webhook",
148+
SaveOutput: true,
149+
Args: []string{"retry", kubectl.Command(k8sVersion), "-n", "cattle-system", "rollout", "restart", "deploy/rancher-webhook"},
150+
Env: kubectl.Env(k8sVersion),
151+
Command: cmd,
152+
}, nil
153+
}
154+
127155
// Needs to patch status subresource
128156
// k patch cluster.provisioning local -n fleet-local --subresource=status --type=merge --patch '{"status":{"fleetWorkspaceName": "fleet-local"}}'
129157
func PatchLocalProvisioningClusterStatus(_, _, k8sVersion string) (*applyinator.Instruction, error) {
@@ -132,7 +160,7 @@ func PatchLocalProvisioningClusterStatus(_, _, k8sVersion string) (*applyinator.
132160
return nil, fmt.Errorf("resolving location of %s: %w", os.Args[0], err)
133161
}
134162
return &applyinator.Instruction{
135-
Name: "wait-suc-plan-resolved",
163+
Name: "patch-provisioning-cluster-status",
136164
SaveOutput: true,
137165
Args: []string{"retry", kubectl.Command(k8sVersion), "-n", "fleet-local", "patch", "cluster.provisioning", "local", "--subresource=status", "--type=merge", "--patch", "{\"status\":{\"fleetWorkspaceName\": \"fleet-local\"}}"},
138166
Env: kubectl.Env(k8sVersion),

pkg/resources/resources.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,8 @@ func ToBootstrapFile(config *config.Config, path string) (*applyinator.File, err
107107
},
108108
"spec": map[string]interface{}{
109109
"kubernetesVersion": k8sVersion,
110-
"rkeConfig": map[string]interface{}{
111-
"controlPlaneConfig": config.ConfigValues,
112-
},
110+
// Rancher needs a non-null rkeConfig to apply system-upgrade-controller managed chart.
111+
"rkeConfig": map[string]interface{}{},
113112
},
114113
},
115114
}, v1.GenericMap{

0 commit comments

Comments
 (0)