Skip to content

Commit

Permalink
Support cluster metadata (#140)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Feb 22, 2022
1 parent 8ebb397 commit a558e70
Show file tree
Hide file tree
Showing 5 changed files with 780 additions and 32 deletions.
24 changes: 24 additions & 0 deletions argocd/schema_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,29 @@ func clusterSchema() map[string]*schema.Schema {
},
},
},
"metadata": {
Type: schema.TypeList,
Description: "Standard cluster secret's metadata. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata",
Optional: true,
MaxItems: 2,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"annotations": {
Type: schema.TypeMap,
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",
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
ValidateFunc: validateMetadataAnnotations,
},
"labels": {
Type: schema.TypeMap,
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",
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
ValidateFunc: validateMetadataLabels,
},
},
},
},
}
}
5 changes: 5 additions & 0 deletions argocd/structure_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func expandCluster(d *schema.ResourceData) (*application.Cluster, error) {
if v, ok := d.GetOk("config"); ok {
cluster.Config = expandClusterConfig(v.([]interface{})[0])
}

m := expandMetadata(d)
cluster.Annotations = m.Annotations
cluster.Labels = m.Labels

return cluster, err
}

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

The `config` block can have the following attributes:

Expand Down Expand Up @@ -151,6 +152,11 @@ The `config.tls_client_config` block can have the following attributes:
* `insecure` - (Optional) boolean. For when the server should be accessed without verifying the TLS certificate.
* `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.

The `metadata` block can have the following attributes:

* `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/).
* `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/).

## Attribute Reference

* `info.0.server_version` - The version of the remote Kubernetes cluster.
Expand Down
76 changes: 44 additions & 32 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,38 @@ require (
cloud.google.com/go/storage v1.14.0 // indirect
github.com/Masterminds/semver v1.5.0
github.com/apparentlymart/go-cidr v1.1.0 // indirect
github.com/argoproj/argo-cd/v2 v2.1.9
github.com/argoproj/gitops-engine v0.4.2
github.com/argoproj/argo-cd/v2 v2.2.5
github.com/argoproj/gitops-engine v0.5.2
github.com/argoproj/pkg v0.11.1-0.20211203175135-36c59d8fafe0
github.com/aws/aws-sdk-go v1.38.65 // indirect
github.com/caddyserver/caddy v1.0.3 // indirect
github.com/casbin/casbin v1.9.1 // indirect
github.com/checkpoint-restore/go-criu/v4 v4.1.0 // indirect
github.com/cristalhq/jwt/v3 v3.1.0
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.4.3
github.com/go-bindata/go-bindata v3.1.1+incompatible // indirect
github.com/golang/protobuf v1.5.2
github.com/golang/snappy v0.0.3 // indirect
github.com/hashicorp/go-getter v1.5.4 // indirect
github.com/hashicorp/go-uuid v1.0.2 // indirect
github.com/hashicorp/hcl/v2 v2.8.2 // indirect
github.com/hashicorp/terraform-json v0.13.0 // indirect
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.1
github.com/klauspost/compress v1.13.1 // indirect
github.com/miekg/dns v1.1.35 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/robfig/cron v1.1.0
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/stretchr/testify v1.7.0
github.com/thecodeteam/goscaleio v0.1.0 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
go.etcd.io/etcd v0.5.0-alpha.5.0.20200910180754-dd1b699fc489 // indirect
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
golang.org/x/tools v0.1.3 // indirect
google.golang.org/api v0.44.0-impersonate-preview // indirect
google.golang.org/grpc v1.38.0 // indirect
google.golang.org/protobuf v1.26.0-rc.1 // indirect
k8s.io/apimachinery v0.21.0
k8s.io/apimachinery v0.22.2
k8s.io/client-go v11.0.1-0.20190816222228-6d55c1b1f1ca+incompatible
k8s.io/heapster v1.2.0-beta.1 // indirect
modernc.org/mathutil v1.0.0
)

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

k8s.io/api => k8s.io/api v0.21.0
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.21.0
k8s.io/apimachinery => k8s.io/apimachinery v0.21.0
k8s.io/apiserver => k8s.io/apiserver v0.21.0
k8s.io/cli-runtime => k8s.io/cli-runtime v0.21.0
k8s.io/client-go => k8s.io/client-go v0.21.0
k8s.io/cloud-provider => k8s.io/cloud-provider v0.21.0
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.21.0
k8s.io/code-generator => k8s.io/code-generator v0.21.0
k8s.io/component-base => k8s.io/component-base v0.21.0
k8s.io/component-helpers => k8s.io/component-helpers v0.21.0
k8s.io/controller-manager => k8s.io/controller-manager v0.21.0
k8s.io/cri-api => k8s.io/cri-api v0.21.0
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.21.0
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.21.0
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.21.0
k8s.io/kube-proxy => k8s.io/kube-proxy v0.21.0
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.21.0
k8s.io/kubectl => k8s.io/kubectl v0.21.0
k8s.io/kubelet => k8s.io/kubelet v0.21.0
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.21.0
k8s.io/metrics => k8s.io/metrics v0.21.0
k8s.io/mount-utils => k8s.io/mount-utils v0.21.0
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.21.0
k8s.io/api => k8s.io/api v0.22.2
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.22.2
k8s.io/apimachinery => k8s.io/apimachinery v0.22.4-rc.0
k8s.io/apiserver => k8s.io/apiserver v0.22.2
k8s.io/cli-runtime => k8s.io/cli-runtime v0.22.2
k8s.io/client-go => k8s.io/client-go v0.22.2
k8s.io/cloud-provider => k8s.io/cloud-provider v0.22.2
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.22.2
k8s.io/code-generator => k8s.io/code-generator v0.22.4-rc.0
k8s.io/component-base => k8s.io/component-base v0.22.2
k8s.io/component-helpers => k8s.io/component-helpers v0.22.2
k8s.io/controller-manager => k8s.io/controller-manager v0.22.2
k8s.io/cri-api => k8s.io/cri-api v0.23.0-alpha.0
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.22.2
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.22.2
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.22.2
k8s.io/kube-proxy => k8s.io/kube-proxy v0.22.2
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.22.2
k8s.io/kubectl => k8s.io/kubectl v0.22.2
k8s.io/kubelet => k8s.io/kubelet v0.22.2
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.22.2
k8s.io/metrics => k8s.io/metrics v0.22.2
k8s.io/mount-utils => k8s.io/mount-utils v0.22.4-rc.0
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.22.2
)

replace k8s.io/pod-security-admission => k8s.io/pod-security-admission v0.22.2

replace k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.22.2

replace k8s.io/sample-controller => k8s.io/sample-controller v0.22.2
Loading

0 comments on commit a558e70

Please sign in to comment.