Skip to content

Commit

Permalink
create external dns cluster values (#1649)
Browse files Browse the repository at this point in the history
* allow adding labels and annotations from configmap spec

Signed-off-by: Matias Charriere <[email protected]>

* add external-dns-cluster-values configmap

Signed-off-by: Matias Charriere <[email protected]>

* replace null with nil

Signed-off-by: Matias Charriere <[email protected]>

* update changelog

Signed-off-by: Matias Charriere <[email protected]>

* add support for China and remove annotation from service account

China doesn't use its local Route53 instance. Instead it uses
external credentials to auth against the global Route53.

Signed-off-by: Matias Charriere <[email protected]>

---------

Signed-off-by: Matias Charriere <[email protected]>
  • Loading branch information
mcharriere authored Sep 19, 2023
1 parent 6ac7eb7 commit 138391e
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Create `external-dns-cluster-values` configmap on cluster creation.

## [5.8.0] - 2023-09-01

### Added
Expand Down
6 changes: 6 additions & 0 deletions service/controller/key/provider.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package key

import "strings"

func IsAWS(provider string) bool {
return provider == "aws"
}

func IsAWSChina(region string) bool {
return strings.HasPrefix(region, "cn-")
}
69 changes: 58 additions & 11 deletions service/controller/resource/clusterconfigmap/desired.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ func (r *Resource) GetDesiredState(ctx context.Context, obj interface{}) ([]*cor
},
}

externalDnsValues := map[string]interface{}{
"txtOwnerId": "giantswarm-io-external-dns",
"txtPrefix": key.ClusterID(&cr),
"annotationFilter": "giantswarm.io/external-dns=managed",
"sources": []string{
"service",
},
}

if key.IsAWS(r.provider) {
var irsa bool
var accountID string
Expand Down Expand Up @@ -135,6 +144,23 @@ func (r *Resource) GetDesiredState(ctx context.Context, obj interface{}) ([]*cor
"region": awsCluster.Spec.Provider.Region,
"vpcID": vpcID,
}

externalDnsValues["extraArgs"] = []string{
"--aws-batch-change-interval=10s",
}
externalDnsValues["aws"] = map[string]interface{}{
"batchChangeInterval": nil,
}
externalDnsValues["domainFilters"] = []string{
key.TenantEndpoint(&cr, bd),
}
if !key.IsAWSChina(awsCluster.Spec.Provider.Region) {
externalDnsValues["serviceAccount"] = map[string]interface{}{
"annotations": map[string]interface{}{
"eks.amazonaws.com/role-arn": fmt.Sprintf("arn:aws:iam::%s:role/%s-Route53Manager-Role", accountID, key.ClusterID(&cr)),
},
}
}
}

ciliumValues := map[string]interface{}{
Expand Down Expand Up @@ -263,6 +289,17 @@ func (r *Resource) GetDesiredState(ctx context.Context, obj interface{}) ([]*cor
Namespace: key.ClusterID(&cr),
Values: ciliumValues,
},
{
Name: "external-dns-cluster-values",
Namespace: key.ClusterID(&cr),
Values: externalDnsValues,
Labels: map[string]string{
"app.kubernetes.io/name": "external-dns",
},
Annotations: map[string]string{
"cluster-operator.giantswarm.io/app-config-priority": "130",
},
},
}

var configMaps []*corev1.ConfigMap
Expand All @@ -285,19 +322,29 @@ func newConfigMap(cr apiv1beta1.Cluster, configMapSpec configMapSpec) (*corev1.C
return nil, microerror.Mask(err)
}

annotations := map[string]string{
annotation.Notes: fmt.Sprintf("DO NOT EDIT. Values managed by %s.", project.Name()),
}
for k, v := range configMapSpec.Annotations {
annotations[k] = v
}

labels := map[string]string{
label.Cluster: key.ClusterID(&cr),
label.ManagedBy: project.Name(),
label.Organization: key.OrganizationID(&cr),
label.ServiceType: label.ServiceTypeManaged,
}
for k, v := range configMapSpec.Labels {
labels[k] = v
}

cm := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: configMapSpec.Name,
Namespace: configMapSpec.Namespace,
Annotations: map[string]string{
annotation.Notes: fmt.Sprintf("DO NOT EDIT. Values managed by %s.", project.Name()),
},
Labels: map[string]string{
label.Cluster: key.ClusterID(&cr),
label.ManagedBy: project.Name(),
label.Organization: key.OrganizationID(&cr),
label.ServiceType: label.ServiceTypeManaged,
},
Name: configMapSpec.Name,
Namespace: configMapSpec.Namespace,
Annotations: annotations,
Labels: labels,
},
Data: map[string]string{
"values": string(yamlValues),
Expand Down
8 changes: 5 additions & 3 deletions service/controller/resource/clusterconfigmap/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package clusterconfigmap

type configMapSpec struct {
Name string
Namespace string
Values map[string]interface{}
Name string
Namespace string
Values map[string]interface{}
Labels map[string]string
Annotations map[string]string
}

0 comments on commit 138391e

Please sign in to comment.