Skip to content

Commit d452405

Browse files
committed
tests: e2e tests implemented
Signed-off-by: Bharath Nallapeta <bnallapeta@mirantis.com>
1 parent 3b9bd1e commit d452405

18 files changed

+265
-37
lines changed

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-flatcar.yaml \
188188
cluster-template-k8s-upgrade.yaml \
189189
cluster-template-flatcar-sysext.yaml \
190-
cluster-template-no-bastion.yaml)
190+
cluster-template-no-bastion.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
@@ -6,6 +6,7 @@ commonLabels:
66
# It should be run by config/
77
resources:
88
- bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml
9+
- bases/infrastructure.cluster.x-k8s.io_openstackclusteridentities.yaml
910
- bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml
1011
- bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml
1112
- 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
@@ -89,7 +89,12 @@ var _ = Describe("OpenStackCluster controller", func() {
8989
},
9090
},
9191
},
92-
Spec: infrav1.OpenStackClusterSpec{},
92+
Spec: infrav1.OpenStackClusterSpec{
93+
IdentityRef: infrav1.OpenStackIdentityReference{
94+
Name: "test-creds",
95+
CloudName: "openstack",
96+
},
97+
},
9398
Status: infrav1.OpenStackClusterStatus{},
9499
}
95100
capiCluster = &clusterv1.Cluster{
@@ -255,6 +260,32 @@ var _ = Describe("OpenStackCluster controller", func() {
255260
Expect(fetched.Spec.IdentityRef.Type).To(Equal("Secret"))
256261
})
257262

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

381421
testCluster.SetName("subnet-filtering")
382422
testCluster.Spec = infrav1.OpenStackClusterSpec{
423+
IdentityRef: infrav1.OpenStackIdentityReference{
424+
Name: "test-creds",
425+
CloudName: "openstack",
426+
},
383427
Bastion: &infrav1.Bastion{
384428
Enabled: ptr.To(true),
385429
Spec: &bastionSpec,
@@ -450,6 +494,10 @@ var _ = Describe("OpenStackCluster controller", func() {
450494

451495
testCluster.SetName("subnet-filtering")
452496
testCluster.Spec = infrav1.OpenStackClusterSpec{
497+
IdentityRef: infrav1.OpenStackIdentityReference{
498+
Name: "test-creds",
499+
CloudName: "openstack",
500+
},
453501
Bastion: &infrav1.Bastion{
454502
Enabled: ptr.To(true),
455503
Spec: &bastionSpec,
@@ -527,6 +575,10 @@ var _ = Describe("OpenStackCluster controller", func() {
527575

528576
testCluster.SetName("subnet-filtering")
529577
testCluster.Spec = infrav1.OpenStackClusterSpec{
578+
IdentityRef: infrav1.OpenStackIdentityReference{
579+
Name: "test-creds",
580+
CloudName: "openstack",
581+
},
530582
DisableAPIServerFloatingIP: ptr.To(true),
531583
APIServerFixedIP: ptr.To("10.0.0.1"),
532584
DisableExternalNetwork: ptr.To(true),
@@ -570,6 +622,10 @@ var _ = Describe("OpenStackCluster controller", func() {
570622

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

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

0 commit comments

Comments
 (0)