Skip to content

Commit dbf3c08

Browse files
committed
tests: e2e tests implemented
Signed-off-by: Bharath Nallapeta <bnallapeta@mirantis.com>
1 parent 67bf142 commit dbf3c08

18 files changed

Lines changed: 265 additions & 37 deletions

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ e2e-templates: $(addprefix $(E2E_NO_ARTIFACT_TEMPLATES_DIR)/, \
187187
cluster-template-k8s-upgrade.yaml \
188188
cluster-template-flatcar-sysext.yaml \
189189
cluster-template-no-bastion.yaml \
190-
cluster-template-health-monitor.yaml)
190+
cluster-template-health-monitor.yaml \
191+
cluster-template-cluster-identity.yaml)
191192
# Currently no templates that require CI artifacts
192193
# $(addprefix $(E2E_TEMPLATES_DIR)/, add-templates-here.yaml) \
193194

api/v1beta1/identity_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ package v1beta1
1919
// OpenStackIdentityReference is a reference to an infrastructure
2020
// provider identity to be used to provision cluster resources.
2121
// +kubebuilder:validation:XValidation:rule="(!has(self.region) && !has(oldSelf.region)) || self.region == oldSelf.region",message="region is immutable"
22-
// +kubebuilder:validation:XValidation:rule="has(self.name)",message="name is required"
23-
// +kubebuilder:validation:XValidation:rule="has(self.cloudName)",message="cloudName is required"
2422
type OpenStackIdentityReference struct {
2523
// Type specifies the identity reference type. Defaults to Secret for backward compatibility.
2624
// +kubebuilder:validation:Enum=Secret;ClusterIdentity
@@ -33,10 +31,12 @@ type OpenStackIdentityReference struct {
3331
// The Secret must contain a key named `clouds.yaml` which contains an OpenStack clouds.yaml file.
3432
// The Secret may optionally contain a key named `cacert` containing a PEM-encoded CA certificate.
3533
// +kubebuilder:validation:Required
34+
// +kubebuilder:validation:MinLength=1
3635
Name string `json:"name"`
3736

3837
// CloudName specifies the name of the entry in the clouds.yaml file to use.
3938
// +kubebuilder:validation:Required
39+
// +kubebuilder:validation:MinLength=1
4040
CloudName string `json:"cloudName"`
4141

4242
// Region specifies an OpenStack region to use. If specified, it overrides

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml

Lines changed: 4 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml

Lines changed: 4 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackfloatingippools.yaml

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackservers.yaml

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ labels:
88
# It should be run by config/
99
resources:
1010
- bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml
11+
- bases/infrastructure.cluster.x-k8s.io_openstackclusteridentities.yaml
1112
- bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml
1213
- bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml
1314
- bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml

controllers/openstackcluster_controller_test.go

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ var _ = Describe("OpenStackCluster controller", func() {
9090
},
9191
},
9292
},
93-
Spec: infrav1.OpenStackClusterSpec{},
93+
Spec: infrav1.OpenStackClusterSpec{
94+
IdentityRef: infrav1.OpenStackIdentityReference{
95+
Name: "test-creds",
96+
CloudName: "openstack",
97+
},
98+
},
9499
Status: infrav1.OpenStackClusterStatus{},
95100
}
96101
capiCluster = &clusterv1.Cluster{
@@ -256,6 +261,32 @@ var _ = Describe("OpenStackCluster controller", func() {
256261
Expect(fetched.Spec.IdentityRef.Type).To(Equal("Secret"))
257262
})
258263

264+
It("should fail when namespace is denied access to ClusterIdentity", func() {
265+
testCluster.SetName("identity-access-denied")
266+
testCluster.Spec.IdentityRef = infrav1.OpenStackIdentityReference{
267+
Type: "ClusterIdentity",
268+
Name: "test-cluster-identity",
269+
CloudName: "openstack",
270+
}
271+
272+
err := k8sClient.Create(ctx, testCluster)
273+
Expect(err).To(BeNil())
274+
err = k8sClient.Create(ctx, capiCluster)
275+
Expect(err).To(BeNil())
276+
277+
identityAccessErr := &scope.IdentityAccessDeniedError{
278+
IdentityName: "test-cluster-identity",
279+
RequesterNamespace: testNamespace,
280+
}
281+
mockScopeFactory.SetClientScopeCreateError(identityAccessErr)
282+
283+
req := createRequestFromOSCluster(testCluster)
284+
result, err := reconciler.Reconcile(ctx, req)
285+
286+
Expect(err).To(MatchError(identityAccessErr))
287+
Expect(result).To(Equal(reconcile.Result{}))
288+
})
289+
259290
It("should reject updates that modify identityRef.region (immutable)", func() {
260291
testCluster.Spec = infrav1.OpenStackClusterSpec{
261292
IdentityRef: infrav1.OpenStackIdentityReference{
@@ -326,6 +357,10 @@ var _ = Describe("OpenStackCluster controller", func() {
326357
It("should be able to reconcile when bastion is explicitly disabled and does not exist", func() {
327358
testCluster.SetName("no-bastion-explicit")
328359
testCluster.Spec = infrav1.OpenStackClusterSpec{
360+
IdentityRef: infrav1.OpenStackIdentityReference{
361+
Name: "test-creds",
362+
CloudName: "openstack",
363+
},
329364
Bastion: &infrav1.Bastion{Enabled: ptr.To(false)},
330365
}
331366
err := k8sClient.Create(ctx, testCluster)
@@ -350,7 +385,12 @@ var _ = Describe("OpenStackCluster controller", func() {
350385
})
351386
It("should delete an existing bastion even if its uuid is not stored in status", func() {
352387
testCluster.SetName("delete-existing-bastion")
353-
testCluster.Spec = infrav1.OpenStackClusterSpec{}
388+
testCluster.Spec = infrav1.OpenStackClusterSpec{
389+
IdentityRef: infrav1.OpenStackIdentityReference{
390+
Name: "test-creds",
391+
CloudName: "openstack",
392+
},
393+
}
354394
err := k8sClient.Create(ctx, testCluster)
355395
Expect(err).To(BeNil())
356396
err = k8sClient.Create(ctx, capiCluster)
@@ -381,6 +421,10 @@ var _ = Describe("OpenStackCluster controller", func() {
381421

382422
testCluster.SetName("subnet-filtering")
383423
testCluster.Spec = infrav1.OpenStackClusterSpec{
424+
IdentityRef: infrav1.OpenStackIdentityReference{
425+
Name: "test-creds",
426+
CloudName: "openstack",
427+
},
384428
Bastion: &infrav1.Bastion{
385429
Enabled: ptr.To(true),
386430
Spec: &bastionSpec,
@@ -451,6 +495,10 @@ var _ = Describe("OpenStackCluster controller", func() {
451495

452496
testCluster.SetName("subnet-filtering")
453497
testCluster.Spec = infrav1.OpenStackClusterSpec{
498+
IdentityRef: infrav1.OpenStackIdentityReference{
499+
Name: "test-creds",
500+
CloudName: "openstack",
501+
},
454502
Bastion: &infrav1.Bastion{
455503
Enabled: ptr.To(true),
456504
Spec: &bastionSpec,
@@ -528,6 +576,10 @@ var _ = Describe("OpenStackCluster controller", func() {
528576

529577
testCluster.SetName("subnet-filtering")
530578
testCluster.Spec = infrav1.OpenStackClusterSpec{
579+
IdentityRef: infrav1.OpenStackIdentityReference{
580+
Name: "test-creds",
581+
CloudName: "openstack",
582+
},
531583
DisableAPIServerFloatingIP: ptr.To(true),
532584
APIServerFixedIP: ptr.To("10.0.0.1"),
533585
DisableExternalNetwork: ptr.To(true),
@@ -571,6 +623,10 @@ var _ = Describe("OpenStackCluster controller", func() {
571623

572624
testCluster.SetName("pre-existing-network-components-by-id")
573625
testCluster.Spec = infrav1.OpenStackClusterSpec{
626+
IdentityRef: infrav1.OpenStackIdentityReference{
627+
Name: "test-creds",
628+
CloudName: "openstack",
629+
},
574630
Network: &infrav1.NetworkParam{
575631
ID: ptr.To(clusterNetworkID),
576632
},
@@ -630,6 +686,10 @@ var _ = Describe("OpenStackCluster controller", func() {
630686

631687
testCluster.SetName("pre-existing-network-components-by-id")
632688
testCluster.Spec = infrav1.OpenStackClusterSpec{
689+
IdentityRef: infrav1.OpenStackIdentityReference{
690+
Name: "test-creds",
691+
CloudName: "openstack",
692+
},
633693
Network: &infrav1.NetworkParam{
634694
Filter: &infrav1.NetworkFilter{
635695
Name: clusterNetworkName,

0 commit comments

Comments
 (0)