@@ -6,22 +6,45 @@ import (
6
6
7
7
corev1 "k8s.io/api/core/v1"
8
8
"k8s.io/apimachinery/pkg/types"
9
- clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
10
9
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
11
10
12
11
prismgoclient "github.com/nutanix-cloud-native/prism-go-client"
13
12
prismcredentials "github.com/nutanix-cloud-native/prism-go-client/environment/credentials"
13
+ prismv4 "github.com/nutanix-cloud-native/prism-go-client/v4"
14
14
15
15
carenv1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
16
16
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/webhook/preflight"
17
17
)
18
18
19
19
const credentialsSecretDataKey = "credentials"
20
20
21
+ func newV4Client (ctx context.Context ,
22
+ client ctrlclient.Client ,
23
+ clusterNamespace string ,
24
+ prismCentralEndpointSpec * carenv1.NutanixPrismCentralEndpointSpec ,
25
+ ) (* prismv4.Client , []preflight.Cause ) {
26
+ credentials , causes := getCredentials (ctx , client , clusterNamespace , prismCentralEndpointSpec )
27
+ if len (causes ) > 0 {
28
+ return nil , causes
29
+ }
30
+
31
+ nv4client , err := prismv4 .NewV4Client (* credentials )
32
+ if err != nil {
33
+ return nil , []preflight.Cause {
34
+ {
35
+ Message : fmt .Sprintf ("failed to create Prism Central client: %s" , err ),
36
+ Field : "cluster.spec.topology.variables[.name=clusterConfig].nutanix.prismCentralEndpoint" ,
37
+ },
38
+ }
39
+ }
40
+
41
+ return nv4client , nil
42
+ }
43
+
21
44
func getCredentials (
22
45
ctx context.Context ,
23
46
client ctrlclient.Client ,
24
- cluster * clusterv1. Cluster ,
47
+ clusterNamespace string ,
25
48
prismCentralEndpointSpec * carenv1.NutanixPrismCentralEndpointSpec ,
26
49
) (* prismgoclient.Credentials , []preflight.Cause ) {
27
50
if prismCentralEndpointSpec == nil {
@@ -36,7 +59,7 @@ func getCredentials(
36
59
if prismCentralEndpointSpec .Credentials .SecretRef .Name == "" {
37
60
return nil , []preflight.Cause {
38
61
{
39
- Message : "Prism Central credentials secret reference is missing the name" ,
62
+ Message : "Prism Central credentials reference is missing the name" ,
40
63
Field : "cluster.spec.topology.variables[.name=clusterConfig].nutanix.prismCentralEndpoint.credentials.secretRef.name" ,
41
64
},
42
65
}
@@ -46,14 +69,14 @@ func getCredentials(
46
69
if err := client .Get (
47
70
ctx ,
48
71
types.NamespacedName {
49
- Namespace : cluster . Namespace ,
72
+ Namespace : clusterNamespace ,
50
73
Name : prismCentralEndpointSpec .Credentials .SecretRef .Name ,
51
74
},
52
75
credentialsSecret ,
53
76
); err != nil {
54
77
return nil , []preflight.Cause {
55
78
{
56
- Message : fmt .Sprintf ("failed to get the credentials Secret: %s" , err ),
79
+ Message : fmt .Sprintf ("failed to get credentials Secret: %s" , err ),
57
80
Field : "cluster.spec.topology.variables[.name=clusterConfig].nutanix.prismCentralEndpoint.credentials.secretRef" ,
58
81
},
59
82
}
0 commit comments