Skip to content

Commit c85e4df

Browse files
committed
Add azureclusteridentity to templates
1 parent d9c4806 commit c85e4df

File tree

77 files changed

+687
-4670
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+687
-4670
lines changed

Tiltfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,19 @@ def capz():
169169

170170
k8s_yaml(blob(yaml))
171171

172+
def create_identity_secret():
173+
#create secret for identity password
174+
local("kubectl delete secret cluster-identity-secret --ignore-not-found=true")
175+
176+
os.putenv('AZURE_CLUSTER_IDENTITY_SECRET_NAME', 'cluster-identity-secret')
177+
os.putenv('AZURE_CLUSTER_IDENTITY_SECRET_NAMESPACE', 'default')
178+
os.putenv('CLUSTER_IDENTITY_NAME', 'cluster-identity')
179+
180+
substitutions = settings.get("kustomize_substitutions", {})
181+
os.putenv('AZURE_CLIENT_SECRET_B64', substitutions.get("AZURE_CLIENT_SECRET_B64"))
182+
183+
local("cat templates/azure-cluster-identity/secret.yaml | " + envsubst_cmd + " | kubectl apply -f -", quiet=True)
184+
172185
def create_crs():
173186
# create config maps
174187
local("kubectl delete configmaps calico-addon --ignore-not-found=true")
@@ -324,6 +337,8 @@ if settings.get("deploy_cert_manager"):
324337

325338
deploy_capi()
326339

340+
create_identity_secret()
341+
327342
capz()
328343

329344
waitforsystem()

azure/scope/identity.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ func (p *AzureCredentialsProvider) GetAuthorizer(ctx context.Context, resourceMa
142142
if err != nil {
143143
return nil, err
144144
}
145+
146+
// AzureIdentity and AzureIdentityBinding will no longer have an OwnerRef starting from capz release v0.5.0 because of the following:
147+
// In Kubenetes v1.20+, if the garbage collector detects an invalid cross-namespace ownerReference, or a cluster-scoped dependent with
148+
// an ownerReference referencing a namespaced kind, a warning Event with a reason of OwnerRefInvalidNamespace and an involvedObject
149+
// of the invalid dependent is reported. You can check for that kind of Event by running kubectl get events -A --field-selector=reason=OwnerRefInvalidNamespace.
150+
145151
copiedIdentity := &aadpodv1.AzureIdentity{
146152
TypeMeta: metav1.TypeMeta{
147153
Kind: "AzureIdentity",
@@ -158,7 +164,6 @@ func (p *AzureCredentialsProvider) GetAuthorizer(ctx context.Context, resourceMa
158164
infrav1.ClusterLabelNamespace: clusterMeta.Namespace,
159165
clusterctl.ClusterctlMoveHierarchyLabelName: "true",
160166
},
161-
OwnerReferences: clusterMeta.OwnerReferences,
162167
},
163168
Spec: aadpodv1.AzureIdentitySpec{
164169
Type: azureIdentityType,
@@ -186,7 +191,6 @@ func (p *AzureCredentialsProvider) GetAuthorizer(ctx context.Context, resourceMa
186191
infrav1.ClusterLabelNamespace: clusterMeta.Namespace,
187192
clusterctl.ClusterctlMoveHierarchyLabelName: "true",
188193
},
189-
OwnerReferences: clusterMeta.OwnerReferences,
190194
},
191195
Spec: aadpodv1.AzureIdentityBindingSpec{
192196
AzureIdentity: copiedIdentity.Name,

hack/create-identity-secret.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
set -o errexit
1717
set -o nounset
1818
set -o pipefail
19+
set +o xtrace
1920

2021
REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
2122
cd "${REPO_ROOT}" || exit 1
@@ -25,11 +26,9 @@ source "${REPO_ROOT}/hack/ensure-kubectl.sh"
2526
# shellcheck source=hack/parse-prow-creds.sh
2627
source "${REPO_ROOT}/hack/parse-prow-creds.sh"
2728

28-
export CLUSTER_IDENTITY_SECRET_NAME="cluster-identity-secret"
29+
export AZURE_CLUSTER_IDENTITY_SECRET_NAME="cluster-identity-secret"
2930
export CLUSTER_IDENTITY_NAME=${CLUSTER_IDENTITY_NAME:="cluster-identity"}
3031
export AZURE_CLUSTER_IDENTITY_SECRET_NAMESPACE="default"
31-
export AZURE_CLUSTER_IDENTITY_CLIENT_ID="${AZURE_CLIENT_ID}"
3232

33-
kubectl create secret generic "${CLUSTER_IDENTITY_SECRET_NAME}" --from-literal=clientSecret="${AZURE_CLIENT_SECRET}"
34-
35-
kubectl label secret "${CLUSTER_IDENTITY_SECRET_NAME}" "clusterctl.cluster.x-k8s.io/move-hierarchy"="true"
33+
kubectl create secret generic "${AZURE_CLUSTER_IDENTITY_SECRET_NAME}" --from-literal=clientSecret="${AZURE_CLIENT_SECRET}"
34+
kubectl label secret "${AZURE_CLUSTER_IDENTITY_SECRET_NAME}" "clusterctl.cluster.x-k8s.io/move-hierarchy=true" --overwrite=true

hack/gen-flavors.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ flavors_dir="${root}/templates/flavors/"
2525
ci_dir="${root}/templates/test/ci/"
2626
dev_dir="${root}/templates/test/dev/"
2727

28-
find "${flavors_dir}"* -maxdepth 0 -type d -print0 | xargs -0 -I {} basename {} | grep -v base | xargs -I {} sh -c "${kustomize} build --reorder none ${flavors_dir}{} > ${root}/templates/cluster-template-{}.yaml"
28+
find "${flavors_dir}"* -maxdepth 0 -type d -print0 | xargs -0 -I {} basename {} | grep -v base | xargs -I {} sh -c "${kustomize} build --load-restrictor LoadRestrictionsNone --reorder none ${flavors_dir}{} > ${root}/templates/cluster-template-{}.yaml"
2929
# move the default template to the default file expected by clusterctl
3030
mv "${root}/templates/cluster-template-default.yaml" "${root}/templates/cluster-template.yaml"
3131

templates/test/ci/prow/azure-cluster-identity.yaml renamed to templates/azure-cluster-identity/azure-cluster-identity.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ spec:
77
type: ServicePrincipal
88
allowedNamespaces: {}
99
tenantID: "${AZURE_TENANT_ID}"
10-
clientID: "${AZURE_CLUSTER_IDENTITY_CLIENT_ID}"
10+
clientID: "${AZURE_CLIENT_ID}"
1111
clientSecret: {"name":"${AZURE_CLUSTER_IDENTITY_SECRET_NAME}","namespace":"${AZURE_CLUSTER_IDENTITY_SECRET_NAMESPACE}"}

templates/test/ci/patches/azurecluster-identity-ref.yaml renamed to templates/azure-cluster-identity/azurecluster-identity-ref.yaml

File renamed without changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace: default
2+
resources:
3+
- azure-cluster-identity.yaml

templates/flavors/multi-tenancy/patches/azurecluster-identity-ref.yaml renamed to templates/azure-cluster-identity/managedazurecluster-identity-ref.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
---
21
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha4
3-
kind: AzureCluster
2+
kind: AzureManagedControlPlane
43
metadata:
54
name: ${CLUSTER_NAME}
65
spec:
76
identityRef:
87
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha4
98
kind: AzureClusterIdentity
109
name: "${CLUSTER_IDENTITY_NAME}"
11-
namespace: "${CLUSTER_IDENTITY_NAMESPACE}"
1210

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: ${AZURE_CLUSTER_IDENTITY_SECRET_NAME}
5+
annotations:
6+
clusterctl.cluster.x-k8s.io/move-hierarchy: "true"
7+
type: Opaque
8+
data:
9+
clientSecret: ${AZURE_CLIENT_SECRET_B64}

templates/cluster-template-aad.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ metadata:
2525
name: ${CLUSTER_NAME}
2626
namespace: default
2727
spec:
28+
identityRef:
29+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha4
30+
kind: AzureClusterIdentity
31+
name: ${CLUSTER_IDENTITY_NAME}
2832
location: ${AZURE_LOCATION}
2933
networkSpec:
3034
vnet:
@@ -202,3 +206,17 @@ spec:
202206
cloud-provider: azure
203207
name: '{{ ds.meta_data["local_hostname"] }}'
204208
useExperimentalRetryJoin: true
209+
---
210+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha4
211+
kind: AzureClusterIdentity
212+
metadata:
213+
name: ${CLUSTER_IDENTITY_NAME}
214+
namespace: default
215+
spec:
216+
allowedNamespaces: {}
217+
clientID: ${AZURE_CLIENT_ID}
218+
clientSecret:
219+
name: ${AZURE_CLUSTER_IDENTITY_SECRET_NAME}
220+
namespace: ${AZURE_CLUSTER_IDENTITY_SECRET_NAMESPACE}
221+
tenantID: ${AZURE_TENANT_ID}
222+
type: ServicePrincipal

0 commit comments

Comments
 (0)