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

Fix common-instancetypes func tests with HCO #952

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
40 changes: 39 additions & 1 deletion tests/common_instancetypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ var _ = Describe("Common Instance Types", func() {
strategy.RevertToOriginalSspCr()
})

Context("operand", func() {
Context("when SSP is not deployed by HCO", func() {

BeforeEach(func() {
strategy.SkipIfDeployedByHCO()
})

It("should reconcile resources from internal bundle by default", func() {
virtualMachineClusterInstancetypes, err := common_instancetypes.FetchBundleResource[instancetypev1beta1.VirtualMachineClusterInstancetype]("../" + common_instancetypes.BundleDir + common_instancetypes.ClusterInstancetypesBundle)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -127,6 +132,39 @@ var _ = Describe("Common Instance Types", func() {
}
})
})

Context("when SSP is deployed by HCO", func() {

BeforeEach(func() {
strategy.SkipIfNotDeployedByHCO()
})

It("should not claim ownership or remove existing resources deployed by virt-operator", func() {
virtualMachineClusterInstancetypes, err := common_instancetypes.FetchBundleResource[instancetypev1beta1.VirtualMachineClusterInstancetype]("../" + common_instancetypes.BundleDir + common_instancetypes.ClusterInstancetypesBundle)
Expect(err).ToNot(HaveOccurred())

virtualMachineClusterPreferences, err := common_instancetypes.FetchBundleResource[instancetypev1beta1.VirtualMachineClusterPreference]("../" + common_instancetypes.BundleDir + common_instancetypes.ClusterPreferencesBundle)
Expect(err).ToNot(HaveOccurred())

assertObjectManagedByVirtOperator := func(name string, obj client.Object) {
// The SSP provided bundle may be out of sync with virt-operator so don't assert err here and ignore any missing resources
if err := apiClient.Get(ctx, client.ObjectKey{Name: name}, obj); err == nil {
// Assert that anything we do find is managed by virt-operator
Expect(obj.GetLabels()).To(HaveKeyWithValue(virtv1.ManagedByLabel, virtv1.ManagedByLabelOperatorValue))
}
}

for _, instancetype := range virtualMachineClusterInstancetypes {
assertObjectManagedByVirtOperator(instancetype.Name, &instancetypev1beta1.VirtualMachineClusterInstancetype{})
}

for _, preference := range virtualMachineClusterPreferences {
assertObjectManagedByVirtOperator(preference.Name, &instancetypev1beta1.VirtualMachineClusterPreference{})
}
})

})

Context("webhook", func() {
DescribeTable("should reject URL", func(URL string) {
sspObj := getSsp()
Expand Down
5 changes: 5 additions & 0 deletions tests/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
envSspDeploymentName = "SSP_DEPLOYMENT_NAME"
envSspDeploymentNamespace = "SSP_DEPLOYMENT_NAMESPACE"
envSspWebhookServiceName = "SSP_WEBHOOK_SERVICE_NAME"
envSkipDeployedByHCO = "SKIP_SSP_DEPLOYED_BY_HCO"
)

const (
Expand Down Expand Up @@ -47,6 +48,10 @@ func ShouldSkipCleanupAfterTests() bool {
return getBoolEnv(envSkipCleanupAfterTests)
}

func IsDeployedByHCO() bool {
return getBoolEnv(envSkipDeployedByHCO)
}

var timeout time.Duration

func Timeout() time.Duration {
Expand Down
35 changes: 35 additions & 0 deletions tests/tests_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ type TestSuiteStrategy interface {
SkipUnlessHighlyAvailableTopologyMode()
SkipUnlessSingleReplicaTopologyMode()
SkipIfUpgradeLane()
SkipIfDeployedByHCO()
SkipIfNotDeployedByHCO()
}

type newSspStrategy struct {
Expand Down Expand Up @@ -127,6 +129,11 @@ func (s *newSspStrategy) Init() {
},
}

// When the original env is deployed by HCO skip common-instancetypes deployment and tests
if env.IsDeployedByHCO() {
newSsp.Spec.FeatureGates.DeployCommonInstancetypes = ptr.To(false)
}

Eventually(func() error {
return apiClient.Create(ctx, newSsp)
}, env.Timeout(), time.Second).ShouldNot(HaveOccurred())
Expand Down Expand Up @@ -226,6 +233,26 @@ func skipIfUpgradeLane() {
}
}

func (s *newSspStrategy) SkipIfDeployedByHCO() {
skipIfDeployedByHCO()
}

func (s *newSspStrategy) SkipIfNotDeployedByHCO() {
skipIfNotDeployedByHCO()
}

func skipIfDeployedByHCO() {
if env.IsDeployedByHCO() {
Skip("Skipping as SSP was deployed by HCO", 1)
}
}

func skipIfNotDeployedByHCO() {
if !env.IsDeployedByHCO() {
Skip("Skipping as SSP was not deployed by HCO", 1)
}
}

type existingSspStrategy struct {
Name string
Namespace string
Expand Down Expand Up @@ -357,6 +384,14 @@ func (s *existingSspStrategy) SkipIfUpgradeLane() {
skipIfUpgradeLane()
}

func (s *existingSspStrategy) SkipIfDeployedByHCO() {
skipIfDeployedByHCO()
}

func (s *existingSspStrategy) SkipIfNotDeployedByHCO() {
skipIfNotDeployedByHCO()
}

var (
apiClient client.Client
coreClient *kubernetes.Clientset
Expand Down