Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 0 additions & 68 deletions controllers/common/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ package common

import (
"context"
"strings"
"time"

olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -170,70 +166,6 @@ func FetchClusterServiceVersion(c client.Client, sub *olmv1alpha1.Subscription)
return csv, nil
}

// FetchClusterServiceVersionForDelete fetch the ClusterServiceVersion from the subscription for delete
func FetchClusterServiceVersionForDelete(c client.Client, sub *olmv1alpha1.Subscription) (*olmv1alpha1.ClusterServiceVersion, error) {
csvName := ""
csvNamespace := sub.Namespace

if sub.Status.InstallPlanRef != nil {
ip, err := FetchInstallPlan(c, sub.Status.InstallPlanRef.Name, sub.Status.InstallPlanRef.Namespace)
if err != nil {
return nil, err
}
for _, step := range ip.Status.Plan {
if step.Resource.Kind == "ClusterServiceVersion" && strings.HasPrefix(step.Resource.Name, sub.Name) {
csvName = step.Resource.Name
}
}
} else {
klog.Warningf("The Installplan for Subscription %s is not ready. Will check it again", sub.Name)
return nil, nil
}

if csvName == "" {
return nil, nil
}

csv := &olmv1alpha1.ClusterServiceVersion{}
csvKey := types.NamespacedName{
Name: csvName,
Namespace: csvNamespace,
}
if err := getObjectWithRetry(c, csvKey, csv); err != nil {
return nil, err
}
return csv, nil
}

func FetchInstallPlan(c client.Client, name, namespace string) (*olmv1alpha1.InstallPlan, error) {
installPlan := &olmv1alpha1.InstallPlan{}
installPlanKey := types.NamespacedName{
Namespace: namespace,
Name: name,
}
if err := getObjectWithRetry(c, installPlanKey, installPlan); err != nil {
return nil, err
}
return installPlan, nil
}

// Get object with retry
func getObjectWithRetry(c client.Client, key types.NamespacedName, obj runtime.Object) error {
if err := wait.PollImmediate(time.Second*5, time.Second*15, func() (bool, error) {
if err := c.Get(context.TODO(), key, obj); err != nil {
if errors.IsNotFound(err) {
return false, nil
}
klog.Errorf("failed to get %s with %s: %v", obj.GetObjectKind(), key.String(), err)
return false, err
}
return true, nil
}); err != nil {
return err
}
return nil
}

// GetOperatorNamespace returns the operator namespace based on the install mode
func GetOperatorNamespace(installMode, namespace string) string {
if installMode == apiv1alpha1.InstallModeCluster {
Expand Down
4 changes: 2 additions & 2 deletions controllers/operandrequest_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (

// +kubebuilder:docs-gen:collapse=Imports

var _ = Describe("OperandRequest controller", func() {
var _ = Describe("OperandRegistry controller", func() {
const (
name = "ibm-cloudpak-name"
namespace = "ibm-cloudpak"
Expand Down Expand Up @@ -97,7 +97,7 @@ var _ = Describe("OperandRequest controller", func() {

Expect(k8sClient.Create(ctx, request)).Should(Succeed())

By("Checking status of the OperandRequest")
By("Checking status of the OperandRegquest")
Eventually(func() operatorv1alpha1.ClusterPhase {
requestInstance := &operatorv1alpha1.OperandRequest{}
Expect(k8sClient.Get(ctx, requestKey, requestInstance)).Should(Succeed())
Expand Down
2 changes: 1 addition & 1 deletion controllers/reconcile_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (r *OperandRequestReconciler) deleteSubscription(operandName string, reques
return nil
}

csv, err := fetch.FetchClusterServiceVersionForDelete(r.Client, sub)
csv, err := fetch.FetchClusterServiceVersion(r.Client, sub)
// If can't get CSV, requeue the request
if err != nil {
return err
Expand Down
26 changes: 0 additions & 26 deletions controllers/testutil/test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,32 +287,6 @@ func InstallPlanStatus() olmv1alpha1.InstallPlanStatus {
return olmv1alpha1.InstallPlanStatus{
Phase: olmv1alpha1.InstallPlanPhaseComplete,
CatalogSources: []string{},
Plan: []*olmv1alpha1.Step{
{
Resolving: "etcd-csv.v0.0.1",
Resource: olmv1alpha1.StepResource{
CatalogSource: "community-operators",
CatalogSourceNamespace: "openshift-marketplace",
Group: "operators.coreos.com",
Version: "v1alpha1",
Kind: "ClusterServiceVersion",
Name: "etcd-csv.v0.0.1",
},
Status: olmv1alpha1.StepStatusPresent,
},
{
Resolving: "jenkins-csv.v0.0.1",
Resource: olmv1alpha1.StepResource{
CatalogSource: "community-operators",
CatalogSourceNamespace: "openshift-marketplace",
Group: "operators.coreos.com",
Version: "v1alpha1",
Kind: "ClusterServiceVersion",
Name: "jenkins-csv.v0.0.1",
},
Status: olmv1alpha1.StepStatusCreated,
},
},
}
}

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/onsi/gomega v1.9.0
github.com/operator-framework/api v0.3.10
k8s.io/api v0.18.2
k8s.io/apiextensions-apiserver v0.18.2
k8s.io/apimachinery v0.18.2
k8s.io/client-go v0.18.2
k8s.io/klog v1.0.0
Expand Down