Skip to content
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

Don't modify running cluster in dry-run mode #2166

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion install/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (k *K8sInstaller) azureSetupServicePrincipal() error {
}
}

if k.params.Azure.TenantID == "" && k.params.Azure.ClientID == "" && k.params.Azure.ClientSecret == "" {
if k.params.Azure.TenantID == "" && k.params.Azure.ClientID == "" && k.params.Azure.ClientSecret == "" && !k.params.IsDryRun() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no directly part of this pr. Would be nice to define a helper func here ie needsAzServicePrincipal(params) bool.

k.Log("🚀 Creating Azure Service Principal for Cilium Azure operator...")
bytes, err := k.azExec("ad", "sp", "create-for-rbac", "--scopes", "/subscriptions/"+k.params.Azure.SubscriptionID+"/resourceGroups/"+k.params.Azure.AKSNodeResourceGroup, "--role", "Contributor")
if err != nil {
Expand Down
10 changes: 7 additions & 3 deletions install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,9 @@ type Parameters struct {
HelmRepository string
}

type rollbackStep func(context.Context)
func (p *Parameters) IsDryRun() bool {
return p.DryRun || p.DryRunHelmValues
}

func (p *Parameters) validate() error {
p.configOverwrites = map[string]string{}
Expand Down Expand Up @@ -682,7 +684,7 @@ func (k *K8sInstaller) preinstall(ctx context.Context) error {
chainingMode := getChainingMode(helmValues)

// Do not stop AWS DS if we are running in chaining mode
if chainingMode != "aws-cni" {
if chainingMode != "aws-cni" && !k.params.IsDryRun() {
if _, err := k.client.GetDaemonSet(ctx, AwsNodeDaemonSetNamespace, AwsNodeDaemonSetName, metav1.GetOptions{}); err == nil {
k.Log("🔥 Patching the %q DaemonSet to evict its pods...", AwsNodeDaemonSetName)
patch := []byte(fmt.Sprintf(`{"spec":{"template":{"spec":{"nodeSelector":{"%s":"%s"}}}}}`, AwsNodeDaemonSetNodeSelectorKey, AwsNodeDaemonSetNodeSelectorValue))
Expand Down Expand Up @@ -1003,6 +1005,8 @@ func (k *K8sInstaller) Install(ctx context.Context) error {
return nil
}

type rollbackStep func(context.Context)

func (k *K8sInstaller) pushRollbackStep(step rollbackStep) {
// Prepend the step to the steps slice so that, in case rollback is
// performed, steps are rolled back in the reverse order
Expand Down Expand Up @@ -1037,7 +1041,7 @@ func (k *K8sInstaller) InstallWithHelm(ctx context.Context, k8sClient *k8s.Clien
helmClient.Namespace = k.params.Namespace
helmClient.Wait = k.params.Wait
helmClient.Timeout = k.params.WaitDuration
helmClient.DryRun = k.params.DryRun || k.params.DryRunHelmValues
helmClient.DryRun = k.params.IsDryRun()
release, err := helmClient.RunWithContext(ctx, k.chart, vals)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ cilium install --context kind-cluster1 --set cluster.id=1 --set cluster.name=clu
RunE: func(cmd *cobra.Command, args []string) error {
params.Namespace = namespace
// Don't log anything if it's a dry run so that the dry run output can easily be piped to other commands.
if params.DryRun || params.DryRunHelmValues {
if params.IsDryRun() {
params.Writer = io.Discard
}
installer, err := install.NewK8sInstaller(k8sClient, params)
Expand Down Expand Up @@ -346,7 +346,7 @@ cilium upgrade --set cluster.id=1 --set cluster.name=cluster1
RunE: func(cmd *cobra.Command, args []string) error {
params.Namespace = namespace
// Don't log anything if it's a dry run so that the dry run output can easily be piped to other commands.
if params.DryRun || params.DryRunHelmValues {
if params.IsDryRun() {
params.Writer = io.Discard
}
installer, err := install.NewK8sInstaller(k8sClient, params)
Expand Down
6 changes: 5 additions & 1 deletion internal/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,10 @@ type UpgradeParameters struct {
DryRunHelmValues bool
}

func (p *UpgradeParameters) IsDryRun() bool {
return p.DryRun || p.DryRunHelmValues
}

// Upgrade upgrades the existing Helm release with the given Helm chart and values
func Upgrade(
ctx context.Context,
Expand All @@ -544,7 +548,7 @@ func Upgrade(
helmClient.ReuseValues = params.ReuseValues
helmClient.Wait = params.Wait
helmClient.Timeout = params.WaitDuration
helmClient.DryRun = params.DryRun || params.DryRunHelmValues
helmClient.DryRun = params.IsDryRun()

return helmClient.RunWithContext(ctx, defaults.HelmReleaseName, params.Chart, params.Values)
}
Expand Down