Skip to content

Commit

Permalink
Merge pull request #412 from timflannagan/remove-migration-logic
Browse files Browse the repository at this point in the history
cmd,pkg: Remove migration logic for deprecated APIs
  • Loading branch information
openshift-merge-robot committed Jun 28, 2021
2 parents 4503147 + 100426f commit 23a4a8b
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
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 @@ -99,7 +93,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 @@ -174,32 +167,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 @@ -256,35 +229,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
@@ -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 23a4a8b

Please sign in to comment.