Skip to content

Commit

Permalink
Remove pre-upgrade check (#4217)
Browse files Browse the repository at this point in the history
This check was only needed to prevent v2.0.0-beta4 from upgrading to
v2.0.0 (GA). Since we're now moving towards version 2.10.0 the check is
no longer needed. Usage of v2.0.0-beta4 at this point is very low.

Fixes #3436
  • Loading branch information
matthchr authored Aug 28, 2024
1 parent 9498d0a commit f839e2f
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 149 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 2 additions & 8 deletions v2/cmd/controller/app/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand All @@ -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.")
Expand All @@ -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

Expand All @@ -85,6 +80,5 @@ func ParseFlags(args []string) (Flags, error) {
EnableLeaderElection: enableLeaderElection,
CRDManagementMode: crdManagementMode,
CRDPatterns: crdPatterns,
PreUpgradeCheck: preUpgradeCheck,
}, nil
}
55 changes: 0 additions & 55 deletions v2/cmd/controller/app/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"net/http"
"net/http/pprof"
"os"
"regexp"
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand Down
19 changes: 5 additions & 14 deletions v2/cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit f839e2f

Please sign in to comment.