-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set Istio CR to warning on version update that is not allowed (#855)
* Return warning instead of error when Istio version update is not allowed. * Move code to separate files to improve readability * Add condition for Istio version update * Reformat docs to have version on new line * Add PR link to release notes * Remove unnecessary function * Replace context.TODO() with context.Background() * Apply suggestions from code review Co-authored-by: Natalia Sitko <80401180+nataliasitko@users.noreply.github.com> --------- Co-authored-by: Marek Kołodziejczak <69915024+kolodziejczak@users.noreply.github.com> Co-authored-by: Natalia Sitko <80401180+nataliasitko@users.noreply.github.com>
- Loading branch information
1 parent
2482918
commit d190d85
Showing
13 changed files
with
423 additions
and
411 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package istio | ||
|
||
import ( | ||
"context" | ||
"k8s.io/client-go/util/retry" | ||
|
||
operatorv1alpha2 "github.com/kyma-project/istio/operator/api/v1alpha2" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
) | ||
|
||
const ( | ||
installationFinalizer string = "istios.operator.kyma-project.io/istio-installation" | ||
) | ||
|
||
func hasInstallationFinalizer(istioCR *operatorv1alpha2.Istio) bool { | ||
return controllerutil.ContainsFinalizer(istioCR, installationFinalizer) | ||
} | ||
|
||
func addInstallationFinalizer(ctx context.Context, apiClient client.Client, istioCR *operatorv1alpha2.Istio) error { | ||
ctrl.Log.Info("Adding Istio installation finalizer") | ||
return retry.RetryOnConflict(retry.DefaultRetry, func() error { | ||
finalizerCR := operatorv1alpha2.Istio{} | ||
if err := apiClient.Get(ctx, client.ObjectKeyFromObject(istioCR), &finalizerCR); err != nil { | ||
return err | ||
} | ||
if controllerutil.AddFinalizer(&finalizerCR, installationFinalizer) { | ||
if err := apiClient.Update(ctx, &finalizerCR); err != nil { | ||
return err | ||
} | ||
} | ||
istioCR.Finalizers = finalizerCR.Finalizers | ||
ctrl.Log.Info("Successfully added Istio installation finalizer") | ||
return nil | ||
}) | ||
} | ||
|
||
func removeInstallationFinalizer(ctx context.Context, apiClient client.Client, istioCR *operatorv1alpha2.Istio) error { | ||
ctrl.Log.Info("Removing Istio installation finalizer") | ||
return retry.RetryOnConflict(retry.DefaultRetry, func() error { | ||
finalizerCR := operatorv1alpha2.Istio{} | ||
if err := apiClient.Get(ctx, client.ObjectKeyFromObject(istioCR), &finalizerCR); err != nil { | ||
return err | ||
} | ||
if controllerutil.RemoveFinalizer(&finalizerCR, installationFinalizer) { | ||
if err := apiClient.Update(ctx, &finalizerCR); err != nil { | ||
return err | ||
} | ||
} | ||
istioCR.Finalizers = finalizerCR.Finalizers | ||
ctrl.Log.Info("Successfully removed Istio installation finalizer") | ||
return nil | ||
}) | ||
} |
Oops, something went wrong.