Skip to content

Commit 4e29479

Browse files
committed
Add e2e tests
1 parent 2c5c09e commit 4e29479

File tree

16 files changed

+82
-86
lines changed

16 files changed

+82
-86
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ E2E_TIMEOUT ?= 3h
293293
run-e2e: e2e-essentials ## Run e2e testing. JOB is an optional REGEXP to select certainn test cases to run. e.g. JOB=PR-Blocking, JOB=Conformance
294294
$(KUBECTL) apply -f cloud-config.yaml && \
295295
cd test/e2e && \
296-
$(GINKGO) -v --trace --tags=e2e --focus=$(JOB) --timeout=$(E2E_TIMEOUT) --skip=Conformance --skip-package=kubeconfig_helper --nodes=1 --no-color=false ./... -- \
296+
$(GINKGO) -vv --trace --tags=e2e --focus=$(JOB) --timeout=$(E2E_TIMEOUT) --skip=Conformance --skip-package=kubeconfig_helper --nodes=1 --no-color=false ./... -- \
297297
-e2e.artifacts-folder=${REPO_ROOT}/_artifacts \
298298
-e2e.config=${E2E_CONFIG} \
299299
-e2e.skip-resource-cleanup=false -e2e.use-existing-cluster=true

api/v1beta2/cloudstackcluster_conversion.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta2
1818

1919
import (
20+
machineryconversion "k8s.io/apimachinery/pkg/conversion"
2021
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
2122
"sigs.k8s.io/controller-runtime/pkg/conversion"
2223
)
@@ -30,3 +31,11 @@ func (dst *CloudStackCluster) ConvertFrom(srcRaw conversion.Hub) error { // noli
3031
src := srcRaw.(*v1beta3.CloudStackCluster)
3132
return Convert_v1beta3_CloudStackCluster_To_v1beta2_CloudStackCluster(src, dst, nil)
3233
}
34+
35+
func Convert_v1beta3_CloudStackClusterSpec_To_v1beta2_CloudStackClusterSpec(in *v1beta3.CloudStackClusterSpec, out *CloudStackClusterSpec, s machineryconversion.Scope) error { // nolint
36+
return autoConvert_v1beta3_CloudStackClusterSpec_To_v1beta2_CloudStackClusterSpec(in, out, s)
37+
}
38+
39+
func Convert_v1beta3_CloudStackClusterStatus_To_v1beta2_CloudStackClusterStatus(in *v1beta3.CloudStackClusterStatus, out *CloudStackClusterStatus, s machineryconversion.Scope) error { // nolint
40+
return autoConvert_v1beta3_CloudStackClusterStatus_To_v1beta2_CloudStackClusterStatus(in, out, s)
41+
}

api/v1beta2/zz_generated.conversion.go

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

api/v1beta3/cloudstackcluster_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type CloudStackClusterSpec struct {
3737

3838
// SyncWithACS determines if an externalManaged CKS cluster should be created on ACS.
3939
// +optional
40-
SyncWithACS bool `json:"syncWithACS"`
40+
SyncWithACS bool `json:"syncWithACS,omitempty"`
4141
}
4242

4343
// The status of the CloudStackCluster object.

controllers/cloudstackcluster_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ func (r *CloudStackClusterReconciliationRunner) Reconcile() (res ctrl.Result, re
9595
r.GetFailureDomains(r.FailureDomains),
9696
r.RemoveExtraneousFailureDomains(r.FailureDomains),
9797
r.VerifyFailureDomainCRDs,
98-
r.GetOrCreateUnmanagedCluster,
99-
r.SetReady)
98+
r.SetReady,
99+
r.GetOrCreateUnmanagedCluster)
100100
}
101101

102102
// GetOrCreateUnmanagedCluster checks if an unmanaged cluster is present in Cloudstack else creates one.

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module sigs.k8s.io/cluster-api-provider-cloudstack
33
go 1.21
44

55
require (
6-
github.com/apache/cloudstack-go/v2 v2.16.0-rc.2
6+
github.com/apache/cloudstack-go/v2 v2.16.1
77
github.com/go-logr/logr v1.2.4
88
github.com/golang/mock v1.6.0
99
github.com/hashicorp/go-multierror v1.1.1
@@ -91,5 +91,3 @@ require (
9191
)
9292

9393
replace github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.0.0 // Indirect upgrade to address https://github.com/advisories/GHSA-w73w-5m7g-f7qc
94-
95-
replace github.com/apache/cloudstack-go/v2 => github.com/shapeblue/cloudstack-go/v2 v2.9.1-0.20230717062313-73e4efc8a510

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
2727
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
2828
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 h1:yL7+Jz0jTC6yykIK/Wh74gnTJnrGr5AyrNMXuA0gves=
2929
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
30+
github.com/apache/cloudstack-go/v2 v2.16.1 h1:2wOE4RKEjWPRZNO7ZNnZYmR3JJ+JJPQwhoc7W1fkiK4=
31+
github.com/apache/cloudstack-go/v2 v2.16.1/go.mod h1:cZsgFe+VmrgLBm7QjeHTJBXYe8E5+yGYkdfwGb+Pu9c=
3032
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
3133
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
3234
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
@@ -315,8 +317,6 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
315317
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
316318
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
317319
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
318-
github.com/shapeblue/cloudstack-go/v2 v2.9.1-0.20230717062313-73e4efc8a510 h1:FPRBv784robz6sZSqDGfZDZMse31lj96i+enH02Xzds=
319-
github.com/shapeblue/cloudstack-go/v2 v2.9.1-0.20230717062313-73e4efc8a510/go.mod h1:Mc+tXpujtslBuZFk5atoGT2LanVxOrXS2GGgidAoz1A=
320320
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
321321
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
322322
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=

pkg/cloud/cluster.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func withExternalManaged() cloudstack.OptionFunc {
5151
func (c *client) GetOrCreateUnmanagedCluster(cluster *clusterv1.Cluster, csCluster *infrav1.CloudStackCluster, fd *infrav1.CloudStackFailureDomainSpec) error {
5252
// Get cluster
5353
if csCluster.Status.CloudStackClusterID != "" {
54-
externalManagedCluster, count, err := c.cs.Kubernetes.GetKubernetesClusterByID(csCluster.Status.CloudStackClusterID, withExternalManaged())
54+
externalManagedCluster, count, err := c.cs.Kubernetes.GetKubernetesClusterByID(csCluster.Status.CloudStackClusterID, withExternalManaged(), cloudstack.WithProject(c.user.Project.ID))
5555
if err != nil {
5656
return err
5757
} else if count > 0 {
@@ -62,20 +62,14 @@ func (c *client) GetOrCreateUnmanagedCluster(cluster *clusterv1.Cluster, csClust
6262

6363
// Check if a cluster exists with the same name
6464
clusterName := fmt.Sprintf("%s - %s - %s", cluster.GetName(), csCluster.GetName(), csCluster.GetUID())
65-
externalManagedCluster, count, err := c.cs.Kubernetes.GetKubernetesClusterByName(clusterName, withExternalManaged())
65+
externalManagedCluster, count, err := c.cs.Kubernetes.GetKubernetesClusterByName(clusterName, withExternalManaged(), cloudstack.WithProject(c.user.Project.ID))
6666
if err != nil && !strings.Contains(err.Error(), "No match found for ") {
6767
return err
6868
}
6969
if count > 0 {
7070
csCluster.Status.CloudStackClusterID = externalManagedCluster.Id
7171
} else if err == nil || (err != nil && strings.Contains(err.Error(), "No match found for ")) {
7272
// Create cluster
73-
domain := Domain{Path: rootDomain}
74-
if csCluster.Spec.FailureDomains[0].Domain != "" {
75-
domain.Path = fd.Domain
76-
}
77-
_ = c.ResolveDomain(&domain)
78-
7973
accountName := csCluster.Spec.FailureDomains[0].Account
8074
if accountName == "" {
8175
userParams := c.cs.User.NewGetUserParams(c.config.APIKey)
@@ -88,10 +82,13 @@ func (c *client) GetOrCreateUnmanagedCluster(cluster *clusterv1.Cluster, csClust
8882
// NewCreateKubernetesClusterParams(description string, kubernetesversionid string, name string, serviceofferingid string, size int64, zoneid string) *CreateKubernetesClusterParams
8983
params := c.cs.Kubernetes.NewCreateKubernetesClusterParams(fmt.Sprintf("%s managed by CAPC", clusterName), "", clusterName, "", 0, fd.Zone.ID)
9084

85+
setIfNotEmpty(c.user.Project.ID, params.SetProjectid)
9186
setIfNotEmpty(accountName, params.SetAccount)
92-
setIfNotEmpty(domain.ID, params.SetDomainid)
87+
setIfNotEmpty(c.user.Domain.ID, params.SetDomainid)
9388
setIfNotEmpty(fd.Zone.Network.ID, params.SetNetworkid)
9489
setIfNotEmpty(csCluster.Spec.ControlPlaneEndpoint.Host, params.SetExternalloadbalanceripaddress)
90+
params.ResetKubernetesversionid()
91+
params.ResetServiceofferingid()
9592
params.SetClustertype("ExternalManaged")
9693

9794
cloudStackCKSCluster, err := c.cs.Kubernetes.CreateKubernetesCluster(params)

test/e2e/config/cloudstack.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ providers:
9898
- sourcePath: "../data/infrastructure-cloudstack/v1beta3/cluster-template-invalid-ip.yaml"
9999
- sourcePath: "../data/infrastructure-cloudstack/v1beta3/cluster-template-kubernetes-version-upgrade-before.yaml"
100100
- sourcePath: "../data/infrastructure-cloudstack/v1beta3/cluster-template-kubernetes-version-upgrade-after.yaml"
101+
- sourcePath: "../data/infrastructure-cloudstack/v1beta3/cluster-template-k8s-unmanaged.yaml"
101102
- sourcePath: "../data/shared/v1beta1_provider/metadata.yaml"
102103
versions:
103104
- name: v1.0.0

test/e2e/data/infrastructure-cloudstack/v1beta3/bases/cluster-with-kcp.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ spec:
3535
name : ${CLOUDSTACK_ZONE_NAME}
3636
network:
3737
name: ${CLOUDSTACK_NETWORK_NAME}
38+
syncWithACS: false
3839
---
3940
kind: KubeadmControlPlane
4041
apiVersion: controlplane.cluster.x-k8s.io/v1beta1

0 commit comments

Comments
 (0)