Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd,pkg: Remove migration logic for deprecated APIs #412

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.