github.com/operator-framework/operator-lifecycle-manager@v0.30.0/test/e2e/deprecated_e2e_test.go (about)

     1  package e2e
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"time"
     7  
     8  	"github.com/blang/semver/v4"
     9  	. "github.com/onsi/ginkgo/v2"
    10  	. "github.com/onsi/gomega"
    11  	operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
    12  	operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
    13  	"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
    14  	corev1 "k8s.io/api/core/v1"
    15  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    16  	"sigs.k8s.io/controller-runtime/pkg/client"
    17  )
    18  
    19  var missingAPI = `{"apiVersion":"verticalpodautoscalers.autoscaling.k8s.io/v1","kind":"VerticalPodAutoscaler","metadata":{"name":"my.thing","namespace":"foo"}}`
    20  
    21  var _ = Describe("Not found APIs", func() {
    22  	var generatedNamespace corev1.Namespace
    23  
    24  	BeforeEach(func() {
    25  		namespaceName := genName("deprecated-e2e-")
    26  		og := operatorsv1.OperatorGroup{
    27  			ObjectMeta: metav1.ObjectMeta{
    28  				Name:      fmt.Sprintf("%s-operatorgroup", namespaceName),
    29  				Namespace: namespaceName,
    30  			},
    31  		}
    32  		generatedNamespace = SetupGeneratedTestNamespaceWithOperatorGroup(namespaceName, og)
    33  
    34  		csv := newCSV("test-csv", generatedNamespace.GetName(), "", semver.Version{}, nil, nil, nil)
    35  		Expect(ctx.Ctx().Client().Create(context.TODO(), &csv)).To(Succeed())
    36  	})
    37  
    38  	AfterEach(func() {
    39  		TeardownNamespace(generatedNamespace.GetName())
    40  	})
    41  
    42  	Context("objects with APIs that are not on-cluster are created in the installplan", func() {
    43  		When("installplan contains a missing API", func() {
    44  			It("the ip enters a failed state with a helpful error message", func() {
    45  				ip := &operatorsv1alpha1.InstallPlan{
    46  					ObjectMeta: metav1.ObjectMeta{
    47  						Name:      "test-plan-api",
    48  						Namespace: generatedNamespace.GetName(),
    49  					},
    50  					Spec: operatorsv1alpha1.InstallPlanSpec{
    51  						Approval:                   operatorsv1alpha1.ApprovalAutomatic,
    52  						Approved:                   true,
    53  						ClusterServiceVersionNames: []string{},
    54  					},
    55  				}
    56  				Expect(ctx.Ctx().Client().Create(context.Background(), ip)).To(Succeed())
    57  
    58  				ip.Status = operatorsv1alpha1.InstallPlanStatus{
    59  					Phase:          operatorsv1alpha1.InstallPlanPhaseInstalling,
    60  					CatalogSources: []string{},
    61  					Plan: []*operatorsv1alpha1.Step{
    62  						{
    63  							Resolving: "test-csv",
    64  							Status:    operatorsv1alpha1.StepStatusUnknown,
    65  							Resource: operatorsv1alpha1.StepResource{
    66  								Name:     "my.thing",
    67  								Group:    "verticalpodautoscalers.autoscaling.k8s.io",
    68  								Version:  "v1",
    69  								Kind:     "VerticalPodAutoscaler",
    70  								Manifest: missingAPI,
    71  							},
    72  						},
    73  					},
    74  				}
    75  
    76  				Expect(ctx.Ctx().Client().Status().Update(context.Background(), ip)).To(Succeed(), "failed to update the resource")
    77  
    78  				errMessage := "api-server resource not found installing VerticalPodAutoscaler my.thing: GroupVersionKind " +
    79  					"verticalpodautoscalers.autoscaling.k8s.io/v1, Kind=VerticalPodAutoscaler not found on the cluster"
    80  				By("The IP sits in the Installing phase with the GVK missing error")
    81  				Eventually(func() (*operatorsv1alpha1.InstallPlan, error) {
    82  					return ip, ctx.Ctx().Client().Get(context.Background(), client.ObjectKeyFromObject(ip), ip)
    83  				}).Should(And(HavePhase(operatorsv1alpha1.InstallPlanPhaseInstalling), HaveMessage(errMessage)))
    84  
    85  				By("Eventually the IP fails with the GVK missing error, after installplan retries, which is by default 1 minute.")
    86  				Eventually(func() (*operatorsv1alpha1.InstallPlan, error) {
    87  					return ip, ctx.Ctx().Client().Get(context.Background(), client.ObjectKeyFromObject(ip), ip)
    88  				}, 2*time.Minute).Should(And(HavePhase(operatorsv1alpha1.InstallPlanPhaseFailed), HaveMessage(errMessage)))
    89  			})
    90  		})
    91  	})
    92  })