diff --git a/v2/charts/azure-service-operator/templates/pre-release-hook/batch_v1_job_pre-upgrade-checker.yaml b/v2/charts/azure-service-operator/templates/pre-release-hook/batch_v1_job_pre-upgrade-checker.yaml deleted file mode 100644 index 13104ecbd9b..00000000000 --- a/v2/charts/azure-service-operator/templates/pre-release-hook/batch_v1_job_pre-upgrade-checker.yaml +++ /dev/null @@ -1,27 +0,0 @@ -apiVersion: batch/v1 -kind: Job -metadata: - name: azureserviceoperator-pre-upgrade-checker - annotations: - "helm.sh/hook": pre-upgrade - "helm.sh/hook-weight": "0" - "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded -spec: - backoffLimit: 2 - template: - spec: - restartPolicy: Never - serviceAccountName: azureserviceoperator-pre-upgrade-checker - containers: - - args: - - --pre-upgrade-check=true - image: {{.Values.image.repository}} - imagePullPolicy: Always - name: pre-upgrade-checker - resources: - limits: - cpu: 500m - memory: 512Mi - requests: - cpu: 200m - memory: 256Mi diff --git a/v2/charts/azure-service-operator/templates/pre-release-hook/rbac.authorization.k8s.io_v1_clusterrole_azureserviceoperator-pre-upgrade-checker-role.yaml b/v2/charts/azure-service-operator/templates/pre-release-hook/rbac.authorization.k8s.io_v1_clusterrole_azureserviceoperator-pre-upgrade-checker-role.yaml deleted file mode 100644 index 476a6cae529..00000000000 --- a/v2/charts/azure-service-operator/templates/pre-release-hook/rbac.authorization.k8s.io_v1_clusterrole_azureserviceoperator-pre-upgrade-checker-role.yaml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: azureserviceoperator-pre-upgrade-checker-role - annotations: - "helm.sh/hook": pre-upgrade - "helm.sh/hook-weight": "-1" - "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded -rules: -- apiGroups: - - apiextensions.k8s.io - resources: - - customresourcedefinitions - verbs: - - create - - get - - list - - patch - - update - - watch diff --git a/v2/charts/azure-service-operator/templates/pre-release-hook/rbac.authorization.k8s.io_v1_clusterrolebinding_azureserviceoperator-pre-upgrade-checker-rolebinding.yaml b/v2/charts/azure-service-operator/templates/pre-release-hook/rbac.authorization.k8s.io_v1_clusterrolebinding_azureserviceoperator-pre-upgrade-checker-rolebinding.yaml deleted file mode 100644 index 213853d49bd..00000000000 --- a/v2/charts/azure-service-operator/templates/pre-release-hook/rbac.authorization.k8s.io_v1_clusterrolebinding_azureserviceoperator-pre-upgrade-checker-rolebinding.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: azureserviceoperator-pre-upgrade-checker-rolebinding - annotations: - "helm.sh/hook": pre-upgrade - "helm.sh/hook-weight": "-1" - "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: azureserviceoperator-pre-upgrade-checker-role -subjects: -- kind: ServiceAccount - name: azureserviceoperator-pre-upgrade-checker - namespace: {{ .Release.Namespace }} diff --git a/v2/charts/azure-service-operator/templates/pre-release-hook/v1_serviceaccount_azureserviceoperator-pre-upgrade-checker.yaml b/v2/charts/azure-service-operator/templates/pre-release-hook/v1_serviceaccount_azureserviceoperator-pre-upgrade-checker.yaml deleted file mode 100644 index 4b7d75eca63..00000000000 --- a/v2/charts/azure-service-operator/templates/pre-release-hook/v1_serviceaccount_azureserviceoperator-pre-upgrade-checker.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: v1 -kind: ServiceAccount -metadata: - name: azureserviceoperator-pre-upgrade-checker - namespace: {{ .Release.Namespace }} - annotations: - "helm.sh/hook": pre-upgrade - "helm.sh/hook-weight": "-1" - "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded diff --git a/v2/cmd/controller/app/flags.go b/v2/cmd/controller/app/flags.go index 4795471f443..6383ee9effa 100644 --- a/v2/cmd/controller/app/flags.go +++ b/v2/cmd/controller/app/flags.go @@ -24,12 +24,11 @@ type Flags struct { EnableLeaderElection bool CRDManagementMode string CRDPatterns string // This is a ';' delimited string containing a collection of patterns - PreUpgradeCheck bool } func (f Flags) String() string { return fmt.Sprintf( - "MetricsAddr: %s, SecureMetrics: %t, ProfilingMetrics: %t, HealthAddr: %s, WebhookPort: %d, WebhookCertDir: %s, EnableLeaderElection: %t, CRDManagementMode: %s, CRDPatterns: %s, PreUpgradeCheck: %t", + "MetricsAddr: %s, SecureMetrics: %t, ProfilingMetrics: %t, HealthAddr: %s, WebhookPort: %d, WebhookCertDir: %s, EnableLeaderElection: %t, CRDManagementMode: %s, CRDPatterns: %s", f.MetricsAddr, f.SecureMetrics, f.ProfilingMetrics, @@ -38,8 +37,7 @@ func (f Flags) String() string { f.WebhookCertDir, f.EnableLeaderElection, f.CRDManagementMode, - f.CRDPatterns, - f.PreUpgradeCheck) + f.CRDPatterns) } func ParseFlags(args []string) (Flags, error) { @@ -56,7 +54,6 @@ func ParseFlags(args []string) (Flags, error) { var enableLeaderElection bool var crdManagementMode string var crdPatterns string - var preUpgradeCheck bool // default here for 'MetricsAddr' is set to "0", which sets metrics to be disabled if 'metrics-addr' flag is omitted. flagSet.StringVar(&metricsAddr, "metrics-addr", "0", "The address the metric endpoint binds to.") @@ -71,8 +68,6 @@ func ParseFlags(args []string) (Flags, error) { flagSet.StringVar(&crdManagementMode, "crd-management", "auto", "Instructs the operator on how it should manage the Custom Resource Definitions. One of 'auto', 'none'") flagSet.StringVar(&crdPatterns, "crd-pattern", "", "Install these CRDs. CRDs already in the cluster will also always be upgraded.") - flagSet.BoolVar(&preUpgradeCheck, "pre-upgrade-check", false, - "Enable pre upgrade check to check if existing crds contain helm 'keep' policy.") flagSet.Parse(args[1:]) //nolint:errcheck @@ -85,6 +80,5 @@ func ParseFlags(args []string) (Flags, error) { EnableLeaderElection: enableLeaderElection, CRDManagementMode: crdManagementMode, CRDPatterns: crdPatterns, - PreUpgradeCheck: preUpgradeCheck, }, nil } diff --git a/v2/cmd/controller/app/setup.go b/v2/cmd/controller/app/setup.go index af690602de6..1141190d30c 100644 --- a/v2/cmd/controller/app/setup.go +++ b/v2/cmd/controller/app/setup.go @@ -12,7 +12,6 @@ import ( "net/http" "net/http/pprof" "os" - "regexp" "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore" @@ -22,16 +21,12 @@ import ( "github.com/pkg/errors" "golang.org/x/time/rate" apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - kerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/client-go/rest" "k8s.io/client-go/util/workqueue" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/client" - clientconfig "sigs.k8s.io/controller-runtime/pkg/client/config" "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/healthz" "sigs.k8s.io/controller-runtime/pkg/manager" @@ -40,7 +35,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/webhook" - "github.com/Azure/azure-service-operator/v2/api" "github.com/Azure/azure-service-operator/v2/internal/config" "github.com/Azure/azure-service-operator/v2/internal/controllers" "github.com/Azure/azure-service-operator/v2/internal/crdmanagement" @@ -58,55 +52,6 @@ import ( "github.com/Azure/azure-service-operator/v2/pkg/genruntime/conditions" ) -func SetupPreUpgradeCheck(ctx context.Context) error { - cfg, err := clientconfig.GetConfig() - if err != nil { - return errors.Wrap(err, "unable to get client config") - } - - apiExtClient, err := apiextensionsclient.NewForConfig(cfg) - if err != nil { - return errors.Wrap(err, "unable to create kubernetes client") - } - - // Had to list CRDs this way and not with crdManager, since we did not have "serviceoperator.azure.com/version" labels in earlier versions. - list, err := apiExtClient.CustomResourceDefinitions().List(ctx, v1.ListOptions{}) - if err != nil { - return errors.Wrap(err, "failed to list CRDs") - } - - scheme := api.CreateScheme() - crdRegexp := regexp.MustCompile(`.*\.azure\.com`) - var errs []error - for _, crd := range list.Items { - crd := crd - if !crdRegexp.MatchString(crd.Name) { - continue - } - - if !scheme.Recognizes(crd.GroupVersionKind()) { - // Not one of our resources - continue - } - - // If this CRD is annotated with "serviceoperator.azure.com/version", it must be >=2.0.0 and so safe - // as we didn't start using this label until 2.0.0. Same with "app.kubernetes.io/version" which was added in 2.3.0 - // in favor of our custom serviceoperator.azure.com - _, hasOldLabel := crd.Labels[crdmanagement.ServiceOperatorVersionLabelOld] - _, hasNewLabel := crd.Labels[crdmanagement.ServiceOperatorVersionLabel] - if hasOldLabel || hasNewLabel { - continue - } - - if policy, ok := crd.Annotations["helm.sh/resource-policy"]; !ok || policy != "keep" { - err = errors.New(fmt.Sprintf("CRD '%s' does not have annotation for helm keep policy. Make sure the upgrade is from beta.5", crd.Name)) - errs = append(errs, err) - } - } - - return kerrors.NewAggregate(errs) -} - func SetupControllerManager(ctx context.Context, setupLog logr.Logger, flgs Flags) manager.Manager { scheme := controllers.CreateScheme() _ = apiextensions.AddToScheme(scheme) // Used for managing CRDs diff --git a/v2/cmd/controller/main.go b/v2/cmd/controller/main.go index fe8cdb9f85c..744e28a9632 100644 --- a/v2/cmd/controller/main.go +++ b/v2/cmd/controller/main.go @@ -27,19 +27,10 @@ func main() { } setupLog.Info("Launching with flags", "flags", flgs.String()) - - if flgs.PreUpgradeCheck { - err = app.SetupPreUpgradeCheck(ctx) - if err != nil { - setupLog.Error(err, "pre-upgrade check failed") - os.Exit(1) - } - } else { - mgr := app.SetupControllerManager(ctx, setupLog, flgs) - setupLog.Info("starting manager") - if err = mgr.Start(ctx); err != nil { - setupLog.Error(err, "failed to start manager") - os.Exit(1) - } + mgr := app.SetupControllerManager(ctx, setupLog, flgs) + setupLog.Info("starting manager") + if err = mgr.Start(ctx); err != nil { + setupLog.Error(err, "failed to start manager") + os.Exit(1) } }