Skip to content

Commit

Permalink
MGMT-18013: Add subsystem tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eliorerz committed Aug 7, 2024
1 parent 73e895d commit 588df6b
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ var _ = Describe("cluster reconcile", func() {
Name: agentClusterInstallName,
}

err = c.Get(ctx, agentClusterInstallKey, clusterInstall)
Expect(c.Get(ctx, agentClusterInstallKey, clusterInstall)).ShouldNot(HaveOccurred())
Expect(clusterInstall.Status.MirrorRegistryConfigurationInfo).To(BeNil())

Expect(FindStatusCondition(clusterInstall.Status.Conditions, hiveext.ClusterSpecSyncedCondition).Reason).To(Equal(hiveext.ClusterInputErrorReason))
Expand All @@ -648,8 +648,7 @@ var _ = Describe("cluster reconcile", func() {
})

It("fails to create a new cluster with invalid mirror registry configmap missing the source in the registries.conf", func() {
err := getClusterInstallFailure(getRegistryMissingSourceToml(), mirrorRegistryCertificate, true)

Expect(getClusterInstallFailure(getRegistryMissingSourceToml(), mirrorRegistryCertificate, true)).ShouldNot(HaveOccurred())
clusterInstall := &hiveext.AgentClusterInstall{}
agentClusterInstallKey := types.NamespacedName{
Namespace: testNamespace,
Expand All @@ -662,18 +661,18 @@ var _ = Describe("cluster reconcile", func() {
Name: agentClusterInstallName,
}

err = c.Get(ctx, agentClusterInstallKey, clusterInstall)
Expect(c.Get(ctx, agentClusterInstallKey, clusterInstall)).ShouldNot(HaveOccurred())
Expect(clusterInstall.Status.MirrorRegistryConfigurationInfo).To(BeNil())

Expect(FindStatusCondition(clusterInstall.Status.Conditions, hiveext.ClusterSpecSyncedCondition).Reason).To(Equal(hiveext.ClusterInputErrorReason))
Expect(FindStatusCondition(clusterInstall.Status.Conditions, hiveext.ClusterSpecSyncedCondition).Message).To(Equal("The Spec could not be synced due to an input error: failed to find registry key in toml tree"))

err = c.Get(ctx, ClusterDeploymentKey, clusterDeployment)
err := c.Get(ctx, ClusterDeploymentKey, clusterDeployment)
Expect(err.Error()).To(Equal("clusterdeployments.hive.openshift.io \"test-cluster-aci\" not found"))
})

It("fails to create a new cluster with invalid mirror registry configmap missing the mirror in the registries.conf", func() {
err := getClusterInstallFailure(getRegistryMissingMirrorToml(), mirrorRegistryCertificate, true)
Expect(getClusterInstallFailure(getRegistryMissingMirrorToml(), mirrorRegistryCertificate, true)).ShouldNot(HaveOccurred())

clusterInstall := &hiveext.AgentClusterInstall{}
agentClusterInstallKey := types.NamespacedName{
Expand All @@ -687,13 +686,13 @@ var _ = Describe("cluster reconcile", func() {
Name: agentClusterInstallName,
}

err = c.Get(ctx, agentClusterInstallKey, clusterInstall)
Expect(c.Get(ctx, agentClusterInstallKey, clusterInstall)).ShouldNot(HaveOccurred())
Expect(clusterInstall.Status.MirrorRegistryConfigurationInfo).To(BeNil())

Expect(FindStatusCondition(clusterInstall.Status.Conditions, hiveext.ClusterSpecSyncedCondition).Reason).To(Equal(hiveext.ClusterInputErrorReason))
Expect(FindStatusCondition(clusterInstall.Status.Conditions, hiveext.ClusterSpecSyncedCondition).Message).To(Equal("The Spec could not be synced due to an input error: failed to find any image mirrors in registry.conf"))

err = c.Get(ctx, ClusterDeploymentKey, clusterDeployment)
err := c.Get(ctx, ClusterDeploymentKey, clusterDeployment)
Expect(err.Error()).To(Equal("clusterdeployments.hive.openshift.io \"test-cluster-aci\" not found"))
})
})
Expand Down
163 changes: 140 additions & 23 deletions subsystem/kubeapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -998,15 +998,15 @@ func verifyCleanUP(ctx context.Context, client k8sclient.Client) {
err := client.List(ctx, clusterDeploymentList, k8sclient.InNamespace(Options.Namespace))
Expect(err).To(BeNil())
return len(clusterDeploymentList.Items)
}, "2m", "2s").Should(Equal(0))
}, "1m", "20s").Should(Equal(0))

By("Verify AgentClusterInstall Cleanup")
Eventually(func() int {
aciList := &hiveext.AgentClusterInstallList{}
err := client.List(ctx, aciList, k8sclient.InNamespace(Options.Namespace))
Expect(err).To(BeNil())
return len(aciList.Items)
}, "2m", "2s").Should(Equal(0))
}, "1m", "20s").Should(Equal(0))

By("Verify ClusterImageSet Cleanup")
Eventually(func() int {
Expand Down Expand Up @@ -1107,9 +1107,8 @@ var _ = Describe("[kube-api]cluster installation", func() {
return
}

ctx := context.Background()

var (
ctx context.Context
clusterDeploymentSpec *hivev1.ClusterDeploymentSpec
infraEnvSpec *v1beta1.InfraEnvSpec
infraNsName types.NamespacedName
Expand All @@ -1122,6 +1121,7 @@ var _ = Describe("[kube-api]cluster installation", func() {
)

BeforeEach(func() {
ctx = context.Background()
secretRef = deployLocalObjectSecretIfNeeded(ctx, kubeClient)
clusterDeploymentSpec = getDefaultClusterDeploymentSpec(secretRef)
aciSpec = getDefaultAgentClusterInstallSpec(clusterDeploymentSpec.ClusterName)
Expand All @@ -1138,14 +1138,131 @@ var _ = Describe("[kube-api]cluster installation", func() {
infraEnvSpec = getDefaultInfraEnvSpec(secretRef, clusterDeploymentSpec)
})

Context("Cluster mirror registry", func() {
const (
providedMirrorRegistryCMName = "user-provided-config-map"
mirrorRegistryCertificate = " -----BEGIN CERTIFICATE-----\n certificate contents\n -----END CERTIFICATE------"
sourceRegistry = "quay.io"
mirrorRegistry = "example-user-registry.com"
registryConfKey = "registries.conf"
registryCertKey = "ca-bundle.crt"
)

newUserProvidedRegistryCM := func(registry, certificate string) *corev1.ConfigMap {
data := map[string]string{}
if registry != "" {
data[registryConfKey] = registry
}
if certificate != "" {
data[registryCertKey] = certificate
}

return &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: providedMirrorRegistryCMName,
Namespace: Options.Namespace,
},
Data: data,
}
}

createUserMirrorRegistryConfigmap := func(client k8sclient.Client, registryToml string, certificate string) {
registryCM := newUserProvidedRegistryCM(registryToml, certificate)
Expect(client.Create(ctx, registryCM)).ShouldNot(HaveOccurred())
}

getSecureRegistryToml := func() string {
return fmt.Sprintf(`
[[registry]]
location = "%s"
[[registry.mirror]]
location = "%s"
`,
sourceRegistry,
mirrorRegistry,
)
}

AfterEach(func() {
cm := corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: providedMirrorRegistryCMName,
Namespace: Options.Namespace,
},
}
Expect(kubeClient.Delete(ctx, &cm)).ShouldNot(HaveOccurred())
})

When("the user di not provided a valid image registry ConfigMap", func() {
It("Failed to create the image registry configurations", func() {
aciSpec.MirrorRegistryRef = &hiveext.MirrorRegistryConfigMapReference{
Name: providedMirrorRegistryCMName,
Namespace: Options.Namespace,
}

deployClusterDeploymentCRD(ctx, kubeClient, clusterDeploymentSpec)
deployAgentClusterInstallCRD(ctx, kubeClient, aciSpec, clusterDeploymentSpec.ClusterInstallRef.Name)
var aci *hiveext.AgentClusterInstall
Eventually(func() bool {
aci = getAgentClusterInstallCRD(ctx, kubeClient, types.NamespacedName{
Namespace: Options.Namespace,
Name: clusterDeploymentSpec.ClusterInstallRef.Name,
})
return aci.Status.MirrorRegistryConfigurationInfo == nil
}, "1m", "20s").MustPassRepeatedly(3).Should(BeTrue())

Expect(aci.Spec.MirrorRegistryRef.Name).To(Equal(providedMirrorRegistryCMName))
Expect(aci.Status.MirrorRegistryConfigurationInfo).To(BeNil())

Expect(controllers.FindStatusCondition(aci.Status.Conditions, hiveext.ClusterSpecSyncedCondition).Reason).To(Equal(hiveext.ClusterInputErrorReason))
Expect(controllers.FindStatusCondition(aci.Status.Conditions, hiveext.ClusterSpecSyncedCondition).Message).To(Equal("The Spec could not be synced due to an input error: Failed to get referenced ConfigMap: ConfigMap \"user-provided-config-map\" not found"))

})
})

When("the user-provided image registry ConfigMap contains correct data", func() {
It("Successfully creates the image registry configurations", func() {
aciSpec.MirrorRegistryRef = &hiveext.MirrorRegistryConfigMapReference{
Name: providedMirrorRegistryCMName,
Namespace: Options.Namespace,
}

createUserMirrorRegistryConfigmap(kubeClient, getSecureRegistryToml(), mirrorRegistryCertificate)

deployClusterDeploymentCRD(ctx, kubeClient, clusterDeploymentSpec)
deployAgentClusterInstallCRD(ctx, kubeClient, aciSpec, clusterDeploymentSpec.ClusterInstallRef.Name)
var aci *hiveext.AgentClusterInstall
Eventually(func() bool {
aci = getAgentClusterInstallCRD(ctx, kubeClient, types.NamespacedName{
Namespace: Options.Namespace,
Name: clusterDeploymentSpec.ClusterInstallRef.Name,
})
return aci.Status.MirrorRegistryConfigurationInfo != nil
}, "1m", "20s").Should(BeTrue())

Expect(aci.Spec.MirrorRegistryRef.Name).To(Equal(providedMirrorRegistryCMName))

Expect(aci.Status.MirrorRegistryConfigurationInfo).NotTo(BeNil())
Expect(len(aci.Status.MirrorRegistryConfigurationInfo.ImageDigestMirrors)).To(Equal(1))
Expect(aci.Status.MirrorRegistryConfigurationInfo.ImageDigestMirrors[0].Source).To(Equal(sourceRegistry))
Expect(len(aci.Status.MirrorRegistryConfigurationInfo.ImageDigestMirrors[0].Mirrors)).To(Equal(1))
Expect(string(aci.Status.MirrorRegistryConfigurationInfo.ImageDigestMirrors[0].Mirrors[0])).To(Equal(mirrorRegistry))

Expect(len(aci.Status.MirrorRegistryConfigurationInfo.Insecure)).To(Equal(0))
Expect(len(aci.Status.MirrorRegistryConfigurationInfo.ImageTagMirrors)).To(Equal(0))
})
})

})

It("Should use full-iso for s390x cpu architecture", func() {
By("Request S390x infraenv")
infraEnvSpec.ClusterRef = nil
infraEnvSpec.CpuArchitecture = models.ClusterCPUArchitectureS390x
deployClusterDeploymentCRD(ctx, kubeClient, clusterDeploymentSpec)
deployAgentClusterInstallCRD(ctx, kubeClient, aciSpec, clusterDeploymentSpec.ClusterInstallRef.Name)
deployInfraEnvCRD(ctx, kubeClient, infraNsName.Name, infraEnvSpec)

By("Verify full-iso requested on creation of infra-env")
infraEnvKey := types.NamespacedName{
Namespace: Options.Namespace,
Expand Down Expand Up @@ -1474,8 +1591,8 @@ var _ = Describe("[kube-api]cluster installation", func() {

secretData := map[string]string{
"cloud-provider.yaml": `
vcn: <your vcn OCID>
`,
vcn: <your vcn OCID>
`,
}
deploySecret(ctx, kubeClient, name, secretData)
defer func() {
Expand Down Expand Up @@ -4869,14 +4986,14 @@ var _ = Describe("[kube-api]cluster installation", func() {
ref := &corev1.LocalObjectReference{Name: "cluster-install-config"}
aciSNOSpec.ManifestsConfigMapRef = ref
content := `apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfig
metadata:
labels:
machineconfiguration.openshift.io/role: master
name: 99-openshift-machineconfig-master-kargs
spec:
kernelArguments:
- 'loglevel=7'`
kind: MachineConfig
metadata:
labels:
machineconfiguration.openshift.io/role: master
name: 99-openshift-machineconfig-master-kargs
spec:
kernelArguments:
- 'loglevel=7'`

By("Start installation without config map")
deployClusterDeploymentCRD(ctx, kubeClient, clusterDeploymentSpec)
Expand Down Expand Up @@ -4939,14 +5056,14 @@ spec:
}
aciSNOSpec.ManifestsConfigMapRefs = refs
content := `apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfig
metadata:
labels:
machineconfiguration.openshift.io/role: master
name: 99-openshift-machineconfig-master-kargs
spec:
kernelArguments:
- 'loglevel=7'`
kind: MachineConfig
metadata:
labels:
machineconfiguration.openshift.io/role: master
name: 99-openshift-machineconfig-master-kargs
spec:
kernelArguments:
- 'loglevel=7'`

By("Start installation without config map")
deployClusterDeploymentCRD(ctx, kubeClient, clusterDeploymentSpec)
Expand Down

0 comments on commit 588df6b

Please sign in to comment.