Skip to content

Commit

Permalink
cmd,pkg: Remove migration logic for depreacted APIs
Browse files Browse the repository at this point in the history
Update the cmd,pkg files that house the cleanup/migration logic for
ensuring that any deprecated APIs, like the OperatorSource resource, are
transistioned to the CatalogSource resource. These APIs have been
deprecated for multiple OCP releases now, and the marketplace project is
largely a downstream project at this point as most of the heavy-lifting
functionality has been migrated over to upstream OLM, so these changes
should help cleanup the main package.
  • Loading branch information
timflannagan committed Jun 22, 2021
1 parent 487cc3c commit 6616e86
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 189 deletions.
59 changes: 0 additions & 59 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ import (
"github.com/operator-framework/operator-marketplace/pkg/apis"
configv1 "github.com/operator-framework/operator-marketplace/pkg/apis/config/v1"
olmv1alpha1 "github.com/operator-framework/operator-marketplace/pkg/apis/olm/v1alpha1"
"github.com/operator-framework/operator-marketplace/pkg/builders"
"github.com/operator-framework/operator-marketplace/pkg/controller"
"github.com/operator-framework/operator-marketplace/pkg/controller/options"
"github.com/operator-framework/operator-marketplace/pkg/defaults"
"github.com/operator-framework/operator-marketplace/pkg/metrics"
"github.com/operator-framework/operator-marketplace/pkg/migrator"
"github.com/operator-framework/operator-marketplace/pkg/operatorhub"
"github.com/operator-framework/operator-marketplace/pkg/signals"
"github.com/operator-framework/operator-marketplace/pkg/status"
Expand All @@ -30,12 +28,8 @@ import (
"github.com/operator-framework/operator-sdk/pkg/leader"
sdkVersion "github.com/operator-framework/operator-sdk/version"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
kruntime "k8s.io/apimachinery/pkg/runtime"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -119,7 +113,6 @@ func main() {
logrus.Fatal(err)
}

// Create a new Cmd to provide shared dependencies and start components
// Even though we are asking to watch all namespaces, we only handle events
// from the operator's namespace. The reason for watching all namespaces is
// watch for CatalogSources in targetNamespaces being deleted and recreate
Expand Down Expand Up @@ -176,32 +169,12 @@ func main() {

logrus.Info("Starting the Cmd.")

// migrate away from Marketplace API
clientGo, err := client.New(cfg, client.Options{Scheme: mgr.GetScheme()})
if err != nil && !k8sErrors.IsNotFound(err) {
logrus.Fatal(err, "Failed to instantiate the client for migrator")
}
migrator := migrator.New(clientGo)
err = migrator.Migrate()
if err != nil {
logrus.Error(err, "[migration] Error while migrating Marketplace away from OperatorSource API")
}

err = cleanUpOldOpsrcResources(clientGo)
if err != nil {
logrus.Error(err, "OperatorSource child resource cleanup failed")
}

// Handle the defaults
err = ensureDefaults(cfg, mgr.GetScheme())
if err != nil {
logrus.Fatal(err)
}

err = defaults.RemoveObsoleteOpsrc(clientGo)
if err != nil {
logrus.Error(err, "[defaults] Could not remove the obsolete default OperatorSource(s)")
}
// statusReportingDoneCh will be closed after the operator has successfully stopped reporting ClusterOperator status.
statusReportingDoneCh := statusReporter.StartReporting()

Expand Down Expand Up @@ -258,35 +231,3 @@ func ensureDefaults(cfg *rest.Config, scheme *kruntime.Scheme) error {

return nil
}

// cleanUpOldOpsrcResources cleans up old deployments and services associated with OperatorSources
func cleanUpOldOpsrcResources(kubeClient client.Client) error {
ctx := context.TODO()

deploy := &appsv1.DeploymentList{}
svc := &corev1.ServiceList{}
o := []client.ListOption{
client.MatchingLabels{builders.OpsrcOwnerNameLabel: builders.OpsrcOwnerNamespaceLabel},
}

var allErrors []error
if err := kubeClient.List(ctx, deploy, o...); err == nil {
for _, d := range deploy.Items {
if err := kubeClient.Delete(ctx, &d); err != nil {
allErrors = append(allErrors, err)
}
}
} else {
allErrors = append(allErrors, err)
}
if err := kubeClient.List(ctx, svc, o...); err == nil {
for _, s := range svc.Items {
if err := kubeClient.Delete(ctx, &s); err != nil {
allErrors = append(allErrors, err)
}
}
} else {
allErrors = append(allErrors, err)
}
return utilerrors.NewAggregate(allErrors)
}
23 changes: 0 additions & 23 deletions pkg/defaults/defaults.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package defaults

import (
"context"
"io/ioutil"
"os"

olm "github.com/operator-framework/operator-marketplace/pkg/apis/olm/v1alpha1"
v1 "github.com/operator-framework/operator-marketplace/pkg/apis/operators/v1"
wrapper "github.com/operator-framework/operator-marketplace/pkg/client"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"sigs.k8s.io/controller-runtime/pkg/client"
)

var (
Expand Down Expand Up @@ -187,23 +184,3 @@ func populateDefsConfig(dir string) (map[string]v1.OperatorSource, map[string]ol
}
return opsrcDefinitions, catsrcDefinitions, config, nil
}

// RemoveObsoleteOpsrc removes any existing default OperatorSource
// in the cluster that has been switched into a default CatalogSource
func RemoveObsoleteOpsrc(kubeClient client.Client) error {
opsrcs := &v1.OperatorSourceList{}
if err := kubeClient.List(context.TODO(), opsrcs, &client.ListOptions{}); err != nil {
return err
}
allErrors := []error{}
for _, opsrc := range opsrcs.Items {
_, presentInOpsrcDefs := globalOpsrcDefinitions[opsrc.Name]
_, presentInCatsrcDefs := globalCatsrcDefinitions[opsrc.Name]
if !presentInOpsrcDefs && presentInCatsrcDefs {
if err := kubeClient.Delete(context.TODO(), &opsrc); err != nil {
allErrors = append(allErrors, err)
}
}
}
return utilerrors.NewAggregate(allErrors)
}
107 changes: 0 additions & 107 deletions pkg/migrator/migrator.go

This file was deleted.

0 comments on commit 6616e86

Please sign in to comment.