Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit ed4720c

Browse files
committed
added working unit test for controlEndpoint
1 parent 948481e commit ed4720c

File tree

7 files changed

+56
-29
lines changed

7 files changed

+56
-29
lines changed

api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1/nutanixcluster_types.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,12 @@ type NutanixClusterSpec struct {
4444

4545
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
4646
// host can be either DNS name or ip address
47-
// +optional
4847
ControlPlaneEndpoint capiv1.APIEndpoint `json:"controlPlaneEndpoint"`
4948

5049
// prismCentral holds the endpoint address and port to access the Nutanix Prism Central.
5150
// When a cluster-wide proxy is installed, by default, this endpoint will be accessed via the proxy.
5251
// Should you wish for communication with this endpoint not to be proxied, please add the endpoint to the
5352
// proxy spec.noProxy list.
54-
// +optional
5553
PrismCentral *credentialTypes.NutanixPrismEndpoint `json:"prismCentral"`
5654

5755
// failureDomains configures failure domains information for the Nutanix platform.
@@ -60,7 +58,7 @@ type NutanixClusterSpec struct {
6058
// +listType=map
6159
// +listMapKey=name
6260
// +optional
63-
FailureDomains []NutanixFailureDomain `json:"failureDomains"`
61+
FailureDomains []NutanixFailureDomain `json:"failureDomains,omitempty"`
6462
}
6563

6664
// NutanixClusterStatus defines the observed state of NutanixCluster

api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1/nutanixmachine_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type NutanixMachineSpec struct {
7373
Subnets []NutanixResourceIdentifier `json:"subnet"`
7474
// List of categories that need to be added to the machines. Categories must already exist in Prism Central
7575
// +kubebuilder:validation:Optional
76+
// +optional
7677
AdditionalCategories []NutanixCategoryIdentifier `json:"additionalCategories,omitempty"`
7778
// Add the machine resources to a Prism Central project
7879
// +optional
@@ -94,6 +95,7 @@ type NutanixMachineSpec struct {
9495

9596
// List of GPU devices that need to be added to the machines.
9697
// +kubebuilder:validation:Optional
98+
// +optional
9799
GPUs []NutanixGPU `json:"gpus,omitempty"`
98100
}
99101

hack/examples/bases/nutanix/cluster/kustomization.yaml.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apiVersion: kustomize.config.k8s.io/v1beta1
55
kind: Kustomization
66

77
resources:
8-
- https://raw.githubusercontent.com/nutanix-cloud-native/cluster-api-provider-nutanix/main/templates/cluster-template-topology.yaml
8+
- https://raw.githubusercontent.com/nutanix-cloud-native/cluster-api-provider-nutanix/jira/KRBN-8094/templates/cluster-template-topology.yaml
99

1010
sortOptions:
1111
order: fifo

hack/examples/bases/nutanix/clusterclass/kustomization.yaml.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apiVersion: kustomize.config.k8s.io/v1beta1
55
kind: Kustomization
66

77
resources:
8-
- https://raw.githubusercontent.com/nutanix-cloud-native/cluster-api-provider-nutanix/main/templates/cluster-template-clusterclass.yaml
8+
- https://raw.githubusercontent.com/nutanix-cloud-native/cluster-api-provider-nutanix/jira/KRBN-8094/templates/cluster-template-clusterclass.yaml
99

1010
configurations:
1111
- kustomizeconfig.yaml

pkg/handlers/nutanix/mutation/controlplaneendpoint/inject.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1010
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
11+
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1112
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
1213
ctrl "sigs.k8s.io/controller-runtime"
1314
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -93,8 +94,10 @@ func (h *nutanixControlPlaneEndpoint) Mutate(
9394
"patchedObjectName", client.ObjectKeyFromObject(obj),
9495
).Info("setting controlPlaneEndpoint in NutanixCluster spec")
9596

96-
obj.Spec.Template.Spec.ControlPlaneEndpoint.Host = controlPlaneEndpointVar.Host
97-
obj.Spec.Template.Spec.ControlPlaneEndpoint.Port = controlPlaneEndpointVar.Port
97+
obj.Spec.Template.Spec.ControlPlaneEndpoint = capiv1.APIEndpoint{
98+
Host: controlPlaneEndpointVar.Host,
99+
Port: controlPlaneEndpointVar.Port,
100+
}
98101

99102
return nil
100103
},

pkg/handlers/nutanix/mutation/controlplaneendpoint/tests/generate_patches.go

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ package tests
66
import (
77
"testing"
88

9+
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
910
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
1011
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
12+
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request"
13+
"github.com/onsi/gomega"
14+
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
1115
)
1216

1317
func TestGeneratePatches(
@@ -24,26 +28,47 @@ func TestGeneratePatches(
2428
capitest.PatchTestDef{
2529
Name: "unset variable",
2630
},
27-
// capitest.PatchTestDef{
28-
// Name: "ControlPlaneEndpoint set to valid host",
29-
// Vars: []runtimehooksv1.Variable{
30-
// capitest.VariableWithValue(
31-
// variableName,
32-
// v1alpha1.NutanixControlPlaneEndpointSpec{
33-
// Host: "10.20.100.10",
34-
// Port: 6443,
35-
// },
36-
// variablePath...,
37-
// ),
38-
// },
39-
// RequestItem: request.NewNutanixClusterTemplateRequestItem("1234"),
40-
// ExpectedPatchMatchers: []capitest.JSONPatchMatcher{{
41-
// Operation: "add",
42-
// Path: "/spec/template/spec/controlPlaneEndpoint",
43-
// ValueMatcher: gomega.HaveKeyWithValue(
44-
// "host", "10.20.100.10",
45-
// ),
46-
// }},
47-
// },
31+
capitest.PatchTestDef{
32+
Name: "ControlPlaneEndpoint set to valid host",
33+
Vars: []runtimehooksv1.Variable{
34+
capitest.VariableWithValue(
35+
variableName,
36+
v1alpha1.NutanixControlPlaneEndpointSpec{
37+
Host: "10.20.100.10",
38+
Port: 6443,
39+
},
40+
variablePath...,
41+
),
42+
},
43+
RequestItem: request.NewNutanixClusterTemplateRequestItem("1"),
44+
ExpectedPatchMatchers: []capitest.JSONPatchMatcher{
45+
{
46+
Operation: "replace",
47+
Path: "/spec/template/spec/controlPlaneEndpoint/host",
48+
ValueMatcher: gomega.Equal("10.20.100.10"),
49+
},
50+
},
51+
},
52+
capitest.PatchTestDef{
53+
Name: "ControlPlaneEndpoint set to valid host",
54+
Vars: []runtimehooksv1.Variable{
55+
capitest.VariableWithValue(
56+
variableName,
57+
v1alpha1.NutanixControlPlaneEndpointSpec{
58+
Host: "10.20.100.10",
59+
Port: 6443,
60+
},
61+
variablePath...,
62+
),
63+
},
64+
RequestItem: request.NewNutanixClusterTemplateRequestItem("2"),
65+
ExpectedPatchMatchers: []capitest.JSONPatchMatcher{
66+
{
67+
Operation: "replace",
68+
Path: "/spec/template/spec/controlPlaneEndpoint/port",
69+
ValueMatcher: gomega.BeEquivalentTo(6443),
70+
},
71+
},
72+
},
4873
)
4974
}

pkg/handlers/nutanix/mutation/metapatch_handler_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package mutation
66
import (
77
"testing"
88

9-
"k8s.io/client-go/rest"
109
"sigs.k8s.io/controller-runtime/pkg/manager"
1110

1211
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"

0 commit comments

Comments
 (0)