Skip to content

Commit

Permalink
fix: add patch local provisioing cluster status for rancher v2.9.x
Browse files Browse the repository at this point in the history
Signed-off-by: PoAn Yang <[email protected]>
  • Loading branch information
FrankYang0529 committed Sep 20, 2024
1 parent 7f98289 commit dedbc05
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
20 changes: 17 additions & 3 deletions pkg/plan/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package plan
import (
"context"
"fmt"
"strings"

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

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

// Above Rancher v2.9.x, we cannot patch provisioing cluster with empty rkeConfig,
// so we need to delete the webhook validation configuration.
if semver.Compare(cfg.RancherVersion, "v2.9.0") >= 0 {
if err := p.addInstruction(rancher.ToDeleteRancherWebhookValidationConfiguration(k8sVersion)); err != nil {
return err
}
}

if err := p.addInstruction(resources.ToInstruction(cfg.RancherInstallerImage, cfg.SystemDefaultRegistry, k8sVersion, dataDir)); err != nil {
return err
}

// currently instruction is only needed for v2.8.x
if strings.HasPrefix(cfg.RancherVersion, "v2.8") {
// currently instruction is needed for version above v2.8.x
if semver.Compare(cfg.RancherVersion, "v2.8.0") >= 0 {
if err := p.addInstruction(rancher.PatchLocalProvisioningClusterStatus(cfg.RancherInstallerImage, cfg.SystemDefaultRegistry, k8sVersion)); err != nil {
return err
}
}

if semver.Compare(cfg.RancherVersion, "v2.9.0") >= 0 {
if err := p.addInstruction(rancher.ToRestartRancherWebhookInstruction(k8sVersion)); err != nil {
return err
}
}

if err := p.addInstruction(rancher.ToWaitSUCInstruction(cfg.RancherInstallerImage, cfg.SystemDefaultRegistry, k8sVersion)); err != nil {
return err
}
Expand Down
30 changes: 29 additions & 1 deletion pkg/rancher/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,34 @@ func ToScaleUpFleetControllerInstruction(_, _, k8sVersion string) (*applyinator.
}, nil
}

func ToDeleteRancherWebhookValidationConfiguration(k8sVersion string) (*applyinator.Instruction, error) {
cmd, err := self.Self()
if err != nil {
return nil, fmt.Errorf("resolving location of %s: %w", os.Args[0], err)
}
return &applyinator.Instruction{
Name: "delete-rancher-webhook-validation-configuration",
SaveOutput: true,
Args: []string{"retry", kubectl.Command(k8sVersion), "delete", "validatingwebhookconfiguration", "rancher.cattle.io"},
Env: kubectl.Env(k8sVersion),
Command: cmd,
}, nil
}

func ToRestartRancherWebhookInstruction(k8sVersion string) (*applyinator.Instruction, error) {
cmd, err := self.Self()
if err != nil {
return nil, fmt.Errorf("resolving location of %s: %w", os.Args[0], err)
}
return &applyinator.Instruction{
Name: "wait-rancher-webhook",
SaveOutput: true,
Args: []string{"retry", kubectl.Command(k8sVersion), "-n", "cattle-system", "rollout", "restart", "deploy/rancher-webhook"},
Env: kubectl.Env(k8sVersion),
Command: cmd,
}, nil
}

// Needs to patch status subresource
// k patch cluster.provisioning local -n fleet-local --subresource=status --type=merge --patch '{"status":{"fleetWorkspaceName": "fleet-local"}}'
func PatchLocalProvisioningClusterStatus(_, _, k8sVersion string) (*applyinator.Instruction, error) {
Expand All @@ -132,7 +160,7 @@ func PatchLocalProvisioningClusterStatus(_, _, k8sVersion string) (*applyinator.
return nil, fmt.Errorf("resolving location of %s: %w", os.Args[0], err)
}
return &applyinator.Instruction{
Name: "wait-suc-plan-resolved",
Name: "patch-provisioning-cluster-status",
SaveOutput: true,
Args: []string{"retry", kubectl.Command(k8sVersion), "-n", "fleet-local", "patch", "cluster.provisioning", "local", "--subresource=status", "--type=merge", "--patch", "{\"status\":{\"fleetWorkspaceName\": \"fleet-local\"}}"},
Env: kubectl.Env(k8sVersion),
Expand Down
5 changes: 2 additions & 3 deletions pkg/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ func ToBootstrapFile(config *config.Config, path string) (*applyinator.File, err
},
"spec": map[string]interface{}{
"kubernetesVersion": k8sVersion,
"rkeConfig": map[string]interface{}{
"controlPlaneConfig": config.ConfigValues,
},
// Rancher needs a non-null rkeConfig to apply system-upgrade-controller managed chart.
"rkeConfig": map[string]interface{}{},
},
},
}, v1.GenericMap{
Expand Down

0 comments on commit dedbc05

Please sign in to comment.