Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Namespaced deployment overlay generation #301

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
HELM ?= $(LOCALBIN)/helm

## Tool Versions
KUSTOMIZE_VERSION ?= v5.0.1
KUSTOMIZE_VERSION ?= v5.5.0
CONTROLLER_TOOLS_VERSION ?= v0.14.0
OPENSHIFT_GOIMPORTS_VERSION ?= c70783e636f2213cac683f6865d88c5edace3157
KIND_VERSION = v0.20.0
Expand Down
6 changes: 6 additions & 0 deletions config/local-setup/dns-operator/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ patches:
kind: CustomResourceDefinition
metadata:
name: dnsrecords.kuadrant.io
- patch: |-
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not getting why this is needed?

Copy link
Member Author

@mikenairn mikenairn Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ../../deploy/local kustomization which this is modifying adds the crds which prevents you from using it multiple times in an overlay. When we install multiple instances of the dns operator we can use this kustomization which removes the CRDs multiple times for each namespace we want to install into, and install the crds separately once.

$patch: delete
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: dnshealthcheckprobes.kuadrant.io
55 changes: 35 additions & 20 deletions make/kustomize_overlays.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,49 @@ DEPLOYMENT_NAMESPACE ?= dns-operator
DEPLOYMENT_NAME_SUFFIX ?= 1
DEPLOYMENT_WATCH_NAMESPACES ?=

GCP_CREDENTIALS_FILE ?= config/local-setup/dns-provider/gcp/gcp-credentials.env
AWS_CREDENTIALS_FILE ?= config/local-setup/dns-provider/aws/aws-credentials.env
AZURE_CREDENTIALS_FILE ?= config/local-setup/dns-provider/azure/azure-credentials.env

## Location to generate cluster overlays
CLUSTER_OVERLAY_DIR ?= $(shell pwd)/tmp/overlays
$(CLUSTER_OVERLAY_DIR):
mkdir -p $(CLUSTER_OVERLAY_DIR)

.PHONY: generate-cluster-overlay
generate-cluster-overlay: remove-cluster-overlay ## Generate a cluster overlay with namespaced deployments for the current cluster (CLUSTER_NAME)
# Generate cluster overlay
mkdir -p $(CLUSTER_OVERLAY_DIR)/$(CLUSTER_NAME)
cd $(CLUSTER_OVERLAY_DIR)/$(CLUSTER_NAME) && \
touch kustomization.yaml && \
$(KUSTOMIZE) edit add resource "../../../config/crd"

# Generate common dns provider kustomization
mkdir -p $(CLUSTER_OVERLAY_DIR)/$(CLUSTER_NAME)/dns-providers
cd $(CLUSTER_OVERLAY_DIR)/$(CLUSTER_NAME)/dns-providers && \
touch kustomization.yaml && \
$(KUSTOMIZE) edit add secret dns-provider-credentials-inmemory --disableNameSuffixHash --from-literal=INMEM_INIT_ZONES=kuadrant.local --type "kuadrant.io/inmemory"

# Add dns providers that require credentials
@if [[ -f $(GCP_CREDENTIALS_FILE) ]]; then\
cp config/local-setup/dns-provider/gcp/gcp-credentials.env $(CLUSTER_OVERLAY_DIR)/$(CLUSTER_NAME)/dns-providers/ ;\
cd $(CLUSTER_OVERLAY_DIR)/$(CLUSTER_NAME)/dns-providers && \
$(KUSTOMIZE) edit add secret dns-provider-credentials-gcp --disableNameSuffixHash --from-env-file=gcp-credentials.env --type "kuadrant.io/gcp" ;\
fi
@if [[ -f $(AWS_CREDENTIALS_FILE) ]]; then\
cp config/local-setup/dns-provider/aws/aws-credentials.env $(CLUSTER_OVERLAY_DIR)/$(CLUSTER_NAME)/dns-providers/ ;\
cd $(CLUSTER_OVERLAY_DIR)/$(CLUSTER_NAME)/dns-providers && \
$(KUSTOMIZE) edit add secret dns-provider-credentials-aws --disableNameSuffixHash --from-env-file=aws-credentials.env --type "kuadrant.io/aws" ;\
fi
@if [[ -f $(AZURE_CREDENTIALS_FILE) ]]; then\
cp config/local-setup/dns-provider/azure/azure-credentials.env $(CLUSTER_OVERLAY_DIR)/$(CLUSTER_NAME)/dns-providers/ ;\
cd $(CLUSTER_OVERLAY_DIR)/$(CLUSTER_NAME)/dns-providers && \
$(KUSTOMIZE) edit add secret dns-provider-credentials-azure --disableNameSuffixHash --from-env-file=azure-credentials.env --type "kuadrant.io/azure" ;\
fi

@n=1 ; while [[ $$n -le $(DEPLOYMENT_COUNT) ]] ; do \
$(MAKE) -s generate-operator-deployment-overlay DEPLOYMENT_NAME_SUFFIX=$$n DEPLOYMENT_NAMESPACE=${DEPLOYMENT_NAMESPACE}-$$n DEPLOYMENT_WATCH_NAMESPACES=${DEPLOYMENT_NAMESPACE}-$$n ;\
cd $(CLUSTER_OVERLAY_DIR)/$(CLUSTER_NAME) && $(KUSTOMIZE) edit add resource namespace-${DEPLOYMENT_NAMESPACE}-$$n && cd - > /dev/null ;\
((n = n + 1)) ;\
done ;\

Expand All @@ -45,23 +79,4 @@ generate-operator-deployment-overlay: ## Generate a DNS Operator deployment over
touch kustomization.yaml && \
$(KUSTOMIZE) edit set namespace $(DEPLOYMENT_NAMESPACE) && \
$(KUSTOMIZE) edit add resource "./dns-operator" && \
$(KUSTOMIZE) edit add resource "../../../../config/local-setup/dns-provider/inmemory"

# Add dns providers
@if [[ -f "config/local-setup/dns-provider/gcp/gcp-credentials.env" ]]; then\
cd $(CLUSTER_OVERLAY_DIR)/$(CLUSTER_NAME)/namespace-$(DEPLOYMENT_NAMESPACE) && \
$(KUSTOMIZE) edit add resource "../../../../config/local-setup/dns-provider/gcp" ;\
fi
@if [[ -f "config/local-setup/dns-provider/aws/aws-credentials.env" ]]; then\
cd $(CLUSTER_OVERLAY_DIR)/$(CLUSTER_NAME)/namespace-$(DEPLOYMENT_NAMESPACE) && \
$(KUSTOMIZE) edit add resource "../../../../config/local-setup/dns-provider/aws" ;\
fi
@if [[ -f "config/local-setup/dns-provider/azure/azure-credentials.env" ]]; then\
cd $(CLUSTER_OVERLAY_DIR)/$(CLUSTER_NAME)/namespace-$(DEPLOYMENT_NAMESPACE) && \
$(KUSTOMIZE) edit add resource "../../../../config/local-setup/dns-provider/azure" ;\
fi

# Generate cluster overlay with namespace resources
cd $(CLUSTER_OVERLAY_DIR)/$(CLUSTER_NAME) && \
touch kustomization.yaml && \
$(KUSTOMIZE) edit add resource namespace-$(DEPLOYMENT_NAMESPACE)
$(KUSTOMIZE) edit add resource "../dns-providers"
5 changes: 3 additions & 2 deletions test/e2e/multi_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ var _ = Describe("Multi Record Test", Labels{"multi_record"}, func() {
if !provider.IsISO3166Alpha2Code(geoCode) {
awsGeoCodeKey = "aws/geolocation-continent-code"
}
awsGeoCodeValue := strings.TrimPrefix(geoCode, "GEO-")

Expect(zoneEndpoints).To(ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{
"DNSName": Equal(klbHostName),
Expand All @@ -621,7 +622,7 @@ var _ = Describe("Multi Record Test", Labels{"multi_record"}, func() {
"RecordTTL": Equal(externaldnsendpoint.TTL(300)),
"ProviderSpecific": Equal(externaldnsendpoint.ProviderSpecific{
{Name: "alias", Value: "false"},
{Name: awsGeoCodeKey, Value: geoCode},
{Name: awsGeoCodeKey, Value: awsGeoCodeValue},
}),
}))))
totalEndpointsChecked++
Expand All @@ -633,7 +634,7 @@ var _ = Describe("Multi Record Test", Labels{"multi_record"}, func() {
"SetIdentifier": Equal(geoCode),
"RecordTTL": Equal(externaldnsendpoint.TTL(300)),
"ProviderSpecific": Equal(externaldnsendpoint.ProviderSpecific{
{Name: awsGeoCodeKey, Value: geoCode},
{Name: awsGeoCodeKey, Value: awsGeoCodeValue},
}),
}))))
totalEndpointsChecked++
Expand Down
Loading