Skip to content

Commit a558e70

Browse files
blakepetterssonjsfpdnBlake Pettersson
authored
Support cluster metadata (#140)
* deps: bump argo-cd to v2.2.0-rc1 and its dependencies * add: metadata support for clusters * add: docs: cluster metadata block * deps: bump argo-cd and its dependencies to v2.2.5 Co-authored-by: Josef Podany <[email protected]> Co-authored-by: Blake Pettersson <[email protected]>
1 parent 8ebb397 commit a558e70

File tree

5 files changed

+780
-32
lines changed

5 files changed

+780
-32
lines changed

argocd/schema_cluster.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,29 @@ func clusterSchema() map[string]*schema.Schema {
181181
},
182182
},
183183
},
184+
"metadata": {
185+
Type: schema.TypeList,
186+
Description: "Standard cluster secret's metadata. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata",
187+
Optional: true,
188+
MaxItems: 2,
189+
Elem: &schema.Resource{
190+
Schema: map[string]*schema.Schema{
191+
"annotations": {
192+
Type: schema.TypeMap,
193+
Description: "An unstructured key value map stored with the cluster secret that may be used to store arbitrary metadata. More info: http://kubernetes.io/docs/user-guide/annotations",
194+
Optional: true,
195+
Elem: &schema.Schema{Type: schema.TypeString},
196+
ValidateFunc: validateMetadataAnnotations,
197+
},
198+
"labels": {
199+
Type: schema.TypeMap,
200+
Description: "Map of string keys and values that can be used to organize and categorize (scope and select) the cluster secret. May match selectors of replication controllers and services. More info: http://kubernetes.io/docs/user-guide/labels",
201+
Optional: true,
202+
Elem: &schema.Schema{Type: schema.TypeString},
203+
ValidateFunc: validateMetadataLabels,
204+
},
205+
},
206+
},
207+
},
184208
}
185209
}

argocd/structure_cluster.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ func expandCluster(d *schema.ResourceData) (*application.Cluster, error) {
3030
if v, ok := d.GetOk("config"); ok {
3131
cluster.Config = expandClusterConfig(v.([]interface{})[0])
3232
}
33+
34+
m := expandMetadata(d)
35+
cluster.Annotations = m.Annotations
36+
cluster.Labels = m.Labels
37+
3338
return cluster, err
3439
}
3540

docs/resources/cluster.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ resource "argocd_cluster" "eks" {
120120
* `shard` - (Optional) Shard contains optional shard number. Calculated on the fly by the application controller if not specified.
121121
* `namespaces` - (Optional) Holds list of namespaces which are accessible in that cluster. Cluster level resources would be ignored if namespace list is not empty..
122122
* `config` - (Optional) The configuration specification, nested attributes are documented below.
123+
* `metadata` - (Optional) Cluster metadata, nested attributes are documented below.
123124

124125
The `config` block can have the following attributes:
125126

@@ -151,6 +152,11 @@ The `config.tls_client_config` block can have the following attributes:
151152
* `insecure` - (Optional) boolean. For when the server should be accessed without verifying the TLS certificate.
152153
* `server_name` - (Optional) string. Passed to the server for SNI and is used in the client to check server certificates against. If empty, the hostname used to contact the server is used.
153154

155+
The `metadata` block can have the following attributes:
156+
157+
* `annotations` - (Optional) An unstructured key value map stored with the config map that may be used to store arbitrary metadata. **By default, the provider ignores any annotations whose key names end with kubernetes.io. This is necessary because such annotations can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such annotations in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem)**. For more info see [Kubernetes reference](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/).
158+
* `labels` - (Optional) Map of string keys and values that can be used to organize and categorize (scope and select) the config map. May match selectors of replication controllers and services. **By default, the provider ignores any labels whose key names end with kubernetes.io. This is necessary because such labels can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such labels in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem).** For more info see [Kubernetes reference](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/).
159+
154160
## Attribute Reference
155161

156162
* `info.0.server_version` - The version of the remote Kubernetes cluster.

go.mod

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,38 @@ require (
66
cloud.google.com/go/storage v1.14.0 // indirect
77
github.com/Masterminds/semver v1.5.0
88
github.com/apparentlymart/go-cidr v1.1.0 // indirect
9-
github.com/argoproj/argo-cd/v2 v2.1.9
10-
github.com/argoproj/gitops-engine v0.4.2
9+
github.com/argoproj/argo-cd/v2 v2.2.5
10+
github.com/argoproj/gitops-engine v0.5.2
1111
github.com/argoproj/pkg v0.11.1-0.20211203175135-36c59d8fafe0
1212
github.com/aws/aws-sdk-go v1.38.65 // indirect
13+
github.com/caddyserver/caddy v1.0.3 // indirect
14+
github.com/casbin/casbin v1.9.1 // indirect
15+
github.com/checkpoint-restore/go-criu/v4 v4.1.0 // indirect
1316
github.com/cristalhq/jwt/v3 v3.1.0
14-
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
15-
github.com/golang/protobuf v1.4.3
17+
github.com/go-bindata/go-bindata v3.1.1+incompatible // indirect
18+
github.com/golang/protobuf v1.5.2
19+
github.com/golang/snappy v0.0.3 // indirect
1620
github.com/hashicorp/go-getter v1.5.4 // indirect
1721
github.com/hashicorp/go-uuid v1.0.2 // indirect
1822
github.com/hashicorp/hcl/v2 v2.8.2 // indirect
1923
github.com/hashicorp/terraform-json v0.13.0 // indirect
2024
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.1
21-
github.com/klauspost/compress v1.13.1 // indirect
25+
github.com/miekg/dns v1.1.35 // indirect
2226
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
2327
github.com/robfig/cron v1.1.0
28+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
2429
github.com/stretchr/testify v1.7.0
30+
github.com/thecodeteam/goscaleio v0.1.0 // indirect
2531
github.com/ulikunitz/xz v0.5.10 // indirect
32+
go.etcd.io/etcd v0.5.0-alpha.5.0.20200910180754-dd1b699fc489 // indirect
2633
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
2734
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
2835
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
2936
golang.org/x/tools v0.1.3 // indirect
3037
google.golang.org/api v0.44.0-impersonate-preview // indirect
31-
google.golang.org/grpc v1.38.0 // indirect
32-
google.golang.org/protobuf v1.26.0-rc.1 // indirect
33-
k8s.io/apimachinery v0.21.0
38+
k8s.io/apimachinery v0.22.2
3439
k8s.io/client-go v11.0.1-0.20190816222228-6d55c1b1f1ca+incompatible
40+
k8s.io/heapster v1.2.0-beta.1 // indirect
3541
modernc.org/mathutil v1.0.0
3642
)
3743

@@ -41,28 +47,34 @@ replace (
4147
github.com/grpc-ecosystem/grpc-gateway => github.com/grpc-ecosystem/grpc-gateway v1.16.0
4248
github.com/improbable-eng/grpc-web => github.com/improbable-eng/grpc-web v0.0.0-20181111100011-16092bd1d58a
4349

44-
k8s.io/api => k8s.io/api v0.21.0
45-
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.21.0
46-
k8s.io/apimachinery => k8s.io/apimachinery v0.21.0
47-
k8s.io/apiserver => k8s.io/apiserver v0.21.0
48-
k8s.io/cli-runtime => k8s.io/cli-runtime v0.21.0
49-
k8s.io/client-go => k8s.io/client-go v0.21.0
50-
k8s.io/cloud-provider => k8s.io/cloud-provider v0.21.0
51-
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.21.0
52-
k8s.io/code-generator => k8s.io/code-generator v0.21.0
53-
k8s.io/component-base => k8s.io/component-base v0.21.0
54-
k8s.io/component-helpers => k8s.io/component-helpers v0.21.0
55-
k8s.io/controller-manager => k8s.io/controller-manager v0.21.0
56-
k8s.io/cri-api => k8s.io/cri-api v0.21.0
57-
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.21.0
58-
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.21.0
59-
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.21.0
60-
k8s.io/kube-proxy => k8s.io/kube-proxy v0.21.0
61-
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.21.0
62-
k8s.io/kubectl => k8s.io/kubectl v0.21.0
63-
k8s.io/kubelet => k8s.io/kubelet v0.21.0
64-
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.21.0
65-
k8s.io/metrics => k8s.io/metrics v0.21.0
66-
k8s.io/mount-utils => k8s.io/mount-utils v0.21.0
67-
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.21.0
50+
k8s.io/api => k8s.io/api v0.22.2
51+
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.22.2
52+
k8s.io/apimachinery => k8s.io/apimachinery v0.22.4-rc.0
53+
k8s.io/apiserver => k8s.io/apiserver v0.22.2
54+
k8s.io/cli-runtime => k8s.io/cli-runtime v0.22.2
55+
k8s.io/client-go => k8s.io/client-go v0.22.2
56+
k8s.io/cloud-provider => k8s.io/cloud-provider v0.22.2
57+
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.22.2
58+
k8s.io/code-generator => k8s.io/code-generator v0.22.4-rc.0
59+
k8s.io/component-base => k8s.io/component-base v0.22.2
60+
k8s.io/component-helpers => k8s.io/component-helpers v0.22.2
61+
k8s.io/controller-manager => k8s.io/controller-manager v0.22.2
62+
k8s.io/cri-api => k8s.io/cri-api v0.23.0-alpha.0
63+
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.22.2
64+
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.22.2
65+
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.22.2
66+
k8s.io/kube-proxy => k8s.io/kube-proxy v0.22.2
67+
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.22.2
68+
k8s.io/kubectl => k8s.io/kubectl v0.22.2
69+
k8s.io/kubelet => k8s.io/kubelet v0.22.2
70+
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.22.2
71+
k8s.io/metrics => k8s.io/metrics v0.22.2
72+
k8s.io/mount-utils => k8s.io/mount-utils v0.22.4-rc.0
73+
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.22.2
6874
)
75+
76+
replace k8s.io/pod-security-admission => k8s.io/pod-security-admission v0.22.2
77+
78+
replace k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.22.2
79+
80+
replace k8s.io/sample-controller => k8s.io/sample-controller v0.22.2

0 commit comments

Comments
 (0)