@@ -20,62 +20,36 @@ import (
20
20
)
21
21
22
22
type IdentityParams struct {
23
- Group string
24
- Version string
25
- Kind string
26
- ClusterKind string
23
+ Group string
24
+ Versions [] string
25
+ Kind string
26
+ ClusterKinds [] string
27
27
}
28
28
29
29
var IdentityParamsList = []IdentityParams {
30
- // v3
31
30
{
32
- Group : "infrastructure.cluster.x-k8s.io" ,
33
- Version : "v1alpha3" ,
34
- Kind : "AWSClusterStaticIdentity" ,
35
- ClusterKind : "AWSCluster" ,
31
+ Group : "infrastructure.cluster.x-k8s.io" ,
32
+ Versions : [] string { "v1alpha3" , "v1alpha4" } ,
33
+ Kind : "AWSClusterStaticIdentity" ,
34
+ ClusterKinds : [] string { "AWSCluster" , "AWSManagedCluster" } ,
36
35
},
37
36
{
38
- Group : "infrastructure.cluster.x-k8s.io" ,
39
- Version : "v1alpha3" ,
40
- Kind : "AWSClusterRoleIdentity" ,
41
- ClusterKind : "AWSCluster" ,
37
+ Group : "infrastructure.cluster.x-k8s.io" ,
38
+ Versions : [] string { "v1alpha3" , "v1alpha4" } ,
39
+ Kind : "AWSClusterRoleIdentity" ,
40
+ ClusterKinds : [] string { "AWSCluster" , "AWSManagedCluster" } ,
42
41
},
43
42
{
44
- Group : "infrastructure.cluster.x-k8s.io" ,
45
- Version : "v1alpha3" ,
46
- Kind : "AzureClusterIdentity" ,
47
- ClusterKind : "AzureCluster" ,
43
+ Group : "infrastructure.cluster.x-k8s.io" ,
44
+ Versions : [] string { "v1alpha3" , "v1alpha4" } ,
45
+ Kind : "AzureClusterIdentity" ,
46
+ ClusterKinds : [] string { "AzureCluster" , "AzureManagedCluster" } ,
48
47
},
49
48
{
50
- Group : "infrastructure.cluster.x-k8s.io" ,
51
- Version : "v1alpha3" ,
52
- Kind : "VSphereClusterIdentity" ,
53
- ClusterKind : "VSphereCluster" ,
54
- },
55
- // v4
56
- {
57
- Group : "infrastructure.cluster.x-k8s.io" ,
58
- Version : "v1alpha4" ,
59
- Kind : "AWSClusterStaticIdentity" ,
60
- ClusterKind : "AWSCluster" ,
61
- },
62
- {
63
- Group : "infrastructure.cluster.x-k8s.io" ,
64
- Version : "v1alpha4" ,
65
- Kind : "AWSClusterRoleIdentity" ,
66
- ClusterKind : "AWSCluster" ,
67
- },
68
- {
69
- Group : "infrastructure.cluster.x-k8s.io" ,
70
- Version : "v1alpha4" ,
71
- Kind : "AzureClusterIdentity" ,
72
- ClusterKind : "AzureCluster" ,
73
- },
74
- {
75
- Group : "infrastructure.cluster.x-k8s.io" ,
76
- Version : "v1alpha4" ,
77
- Kind : "VSphereClusterIdentity" ,
78
- ClusterKind : "VSphereCluster" ,
49
+ Group : "infrastructure.cluster.x-k8s.io" ,
50
+ Versions : []string {"v1alpha3" , "v1alpha4" },
51
+ Kind : "VSphereClusterIdentity" ,
52
+ ClusterKinds : []string {"VSphereCluster" },
79
53
},
80
54
}
81
55
@@ -92,32 +66,34 @@ func isEmptyCredentials(creds *capiv1_proto.Credential) bool {
92
66
func FindCredentials (ctx context.Context , c client.Client , dc discovery.DiscoveryInterface ) ([]unstructured.Unstructured , error ) {
93
67
identities := []unstructured.Unstructured {}
94
68
for _ , identityParams := range IdentityParamsList {
95
- gvk := schema.GroupVersionKind {
96
- Group : identityParams .Group ,
97
- Version : identityParams .Version ,
98
- Kind : identityParams .Kind ,
99
- }
69
+ for _ , v := range identityParams .Versions {
70
+ gvk := schema.GroupVersionKind {
71
+ Group : identityParams .Group ,
72
+ Version : v ,
73
+ Kind : identityParams .Kind ,
74
+ }
100
75
101
- // We can skip this checkCRDExists check and let k8s do it.
102
- // BUT if any of the above Identities are missing, client-go will purge its
103
- // CRD cache and try and find all the available CRDs again, for each missing identity.
104
- // This is a lot of requests, they get throttled, this func blows out to 10s+.
105
- //
106
- exists , err := checkCRDExists (dc , gvk )
107
- if err != nil {
108
- return nil , fmt .Errorf ("failed to check if CRD exists, %v: %w" , gvk , err )
109
- }
110
- if ! exists {
111
- continue
112
- }
76
+ // We can skip this checkCRDExists check and let k8s do it.
77
+ // BUT if any of the above Identities are missing, client-go will purge its
78
+ // CRD cache and try and find all the available CRDs again, for each missing identity.
79
+ // This is a lot of requests, they get throttled, this func blows out to 10s+.
80
+ //
81
+ exists , err := checkCRDExists (dc , gvk )
82
+ if err != nil {
83
+ return nil , fmt .Errorf ("failed to check if CRD exists, %v: %w" , gvk , err )
84
+ }
85
+ if ! exists {
86
+ continue
87
+ }
113
88
114
- identityList := & unstructured.UnstructuredList {}
115
- identityList .SetGroupVersionKind (gvk )
116
- err = c .List (context .Background (), identityList )
117
- if err != nil {
118
- return nil , fmt .Errorf ("failed to list CRs of %v: %w" , gvk , err )
89
+ identityList := & unstructured.UnstructuredList {}
90
+ identityList .SetGroupVersionKind (gvk )
91
+ err = c .List (context .Background (), identityList )
92
+ if err != nil {
93
+ return nil , fmt .Errorf ("failed to list CRs of %v: %w" , gvk , err )
94
+ }
95
+ identities = append (identities , identityList .Items ... )
119
96
}
120
- identities = append (identities , identityList .Items ... )
121
97
}
122
98
123
99
// k8s doesn't internally differentiate between different apiVersions so we de-dup them
@@ -211,12 +187,15 @@ func InjectCredentials(tmplWithValues [][]byte, creds *capiv1_proto.Credential)
211
187
for _ , bit := range tmplWithValues {
212
188
var err error
213
189
for _ , identityParams := range IdentityParamsList {
214
- // see if we can find the capi type in the list here.
215
- if creds .Group == identityParams .Group && creds .Kind == identityParams .Kind && creds .Version == identityParams .Version {
216
- clusterKind := identityParams .ClusterKind
217
- bit , err = MaybeInjectCredentials (bit , clusterKind , creds )
218
- if err != nil {
219
- return nil , fmt .Errorf ("unable to inject credentials %v %v %v: %v" , creds , bit , clusterKind , err )
190
+ for _ , v := range identityParams .Versions {
191
+ // see if we can find the capi type in the list here.
192
+ if creds .Group == identityParams .Group && creds .Kind == identityParams .Kind && creds .Version == v {
193
+ for _ , clusterKind := range identityParams .ClusterKinds {
194
+ bit , err = MaybeInjectCredentials (bit , clusterKind , creds )
195
+ if err != nil {
196
+ return nil , fmt .Errorf ("unable to inject credentials %v %v %v: %v" , creds , bit , clusterKind , err )
197
+ }
198
+ }
220
199
}
221
200
}
222
201
}
0 commit comments