From eb051a3202da74304d080db3fca6eb9149ea975c Mon Sep 17 00:00:00 2001 From: Howard Lau Date: Sun, 1 Nov 2020 06:43:45 +0000 Subject: [PATCH] Use Kubernetes recommended labels Signed-off-by: Howard Lau --- controllers/controller_filer.go | 7 ++++++- controllers/controller_master.go | 7 ++++++- controllers/controller_volume.go | 7 ++++++- controllers/label/label.go | 18 ++++++++++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 controllers/label/label.go diff --git a/controllers/controller_filer.go b/controllers/controller_filer.go index 19bc33e..16770e6 100644 --- a/controllers/controller_filer.go +++ b/controllers/controller_filer.go @@ -10,6 +10,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" seaweedv1 "github.com/seaweedfs/seaweedfs-operator/api/v1" + label "github.com/seaweedfs/seaweedfs-operator/controllers/label" ) func (r *SeaweedReconciler) ensureFilerServers(seaweedCR *seaweedv1.Seaweed) (done bool, result ctrl.Result, err error) { @@ -98,5 +99,9 @@ func (r *SeaweedReconciler) ensureFilerConfigMap(seaweedCR *seaweedv1.Seaweed) ( } func labelsForFiler(name string) map[string]string { - return map[string]string{"app": "seaweedfs", "role": "filer", "name": name} + return map[string]string{ + label.NameLabelKey: "seaweedfs", + label.ComponentLabelKey: "filer", + label.InstanceLabelKey: name, + } } diff --git a/controllers/controller_master.go b/controllers/controller_master.go index f6b6b71..00cb756 100644 --- a/controllers/controller_master.go +++ b/controllers/controller_master.go @@ -10,6 +10,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" seaweedv1 "github.com/seaweedfs/seaweedfs-operator/api/v1" + label "github.com/seaweedfs/seaweedfs-operator/controllers/label" ) func (r *SeaweedReconciler) ensureMaster(seaweedCR *seaweedv1.Seaweed) (done bool, result ctrl.Result, err error) { @@ -117,5 +118,9 @@ func (r *SeaweedReconciler) ensureMasterPeerService(seaweedCR *seaweedv1.Seaweed } func labelsForMaster(name string) map[string]string { - return map[string]string{"app": "seaweedfs", "role": "master", "name": name} + return map[string]string{ + label.NameLabelKey: "seaweedfs", + label.ComponentLabelKey: "master", + label.InstanceLabelKey: name, + } } diff --git a/controllers/controller_volume.go b/controllers/controller_volume.go index 05e3db6..03b448b 100644 --- a/controllers/controller_volume.go +++ b/controllers/controller_volume.go @@ -10,6 +10,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" seaweedv1 "github.com/seaweedfs/seaweedfs-operator/api/v1" + label "github.com/seaweedfs/seaweedfs-operator/controllers/label" ) func (r *SeaweedReconciler) ensureVolumeServers(seaweedCR *seaweedv1.Seaweed) (done bool, result ctrl.Result, err error) { @@ -80,5 +81,9 @@ func (r *SeaweedReconciler) ensureVolumeServerService(seaweedCR *seaweedv1.Seawe } func labelsForVolumeServer(name string) map[string]string { - return map[string]string{"app": "seaweedfs", "role": "volume", "name": name} + return map[string]string{ + label.NameLabelKey: "seaweedfs", + label.ComponentLabelKey: "volume", + label.InstanceLabelKey: name, + } } diff --git a/controllers/label/label.go b/controllers/label/label.go new file mode 100644 index 0000000..cfa4f7e --- /dev/null +++ b/controllers/label/label.go @@ -0,0 +1,18 @@ +package label + +const ( + // The following labels are recommended by kubernetes https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/ + + // ManagedByLabelKey is Kubernetes recommended label key, it represents the tool being used to manage the operation of an application + // For resources managed by SeaweedFS Operator, its value is always seaweedfs-operator + ManagedByLabelKey string = "app.kubernetes.io/managed-by" + // ComponentLabelKey is Kubernetes recommended label key, it represents the component within the architecture + ComponentLabelKey string = "app.kubernetes.io/component" + // NameLabelKey is Kubernetes recommended label key, it represents the name of the application + NameLabelKey string = "app.kubernetes.io/name" + // InstanceLabelKey is Kubernetes recommended label key, it represents a unique name identifying the instance of an application + // It's set by helm when installing a release + InstanceLabelKey string = "app.kubernetes.io/instance" + // VersionLabelKey is Kubernetes recommended label key, it represents the version of the app + VersionLabelKey string = "app.kubernetes.io/version" +)