diff --git a/backend/service/k8s/cache_test.go b/backend/service/k8s/cache_test.go index 868e6a087c..c68700beac 100644 --- a/backend/service/k8s/cache_test.go +++ b/backend/service/k8s/cache_test.go @@ -29,7 +29,7 @@ func TestProcessInformerEvent(t *testing.T) { Name: "test-pod-1", Namespace: "testing-namespace", Labels: map[string]string{ - clusterClutchNameLabel: "cluster", + clutchLabelClusterName: "cluster", }, }, } diff --git a/backend/service/k8s/configmap.go b/backend/service/k8s/configmap.go index 08c9d4bd38..9ebf91ff44 100644 --- a/backend/service/k8s/configmap.go +++ b/backend/service/k8s/configmap.go @@ -69,7 +69,7 @@ func (s *svc) ListConfigMaps(ctx context.Context, clientset, cluster, namespace } func protoForConfigMap(cluster string, k8sconfigMap *v1.ConfigMap) *k8sapiv1.ConfigMap { - clusterName := GetKubeCluster(k8sconfigMap) + clusterName := GetKubeClusterName(k8sconfigMap) if clusterName == "" { clusterName = cluster } diff --git a/backend/service/k8s/configmap_test.go b/backend/service/k8s/configmap_test.go index 7ac72e4a89..a27ee645d2 100644 --- a/backend/service/k8s/configmap_test.go +++ b/backend/service/k8s/configmap_test.go @@ -171,7 +171,7 @@ func TestProtoForConfigMap(t *testing.T) { configMap: &v1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - "cluster.clutch.sh/name": "production", + clutchLabelClusterName: "production", }, }, }, @@ -183,7 +183,7 @@ func TestProtoForConfigMap(t *testing.T) { configMap: &v1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - "cluster.clutch.sh/name": "staging", + clutchLabelClusterName: "staging", }, }, }, @@ -195,7 +195,7 @@ func TestProtoForConfigMap(t *testing.T) { configMap: &v1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - "cluster.clutch.sh/name": "test", + clutchLabelClusterName: "test", }, }, Data: map[string]string{ diff --git a/backend/service/k8s/cronjob.go b/backend/service/k8s/cronjob.go index 5b5b6eb615..d3688d1662 100644 --- a/backend/service/k8s/cronjob.go +++ b/backend/service/k8s/cronjob.go @@ -70,7 +70,7 @@ func (s *svc) DeleteCronJob(ctx context.Context, clientset, cluster, namespace, } func ProtoForCronJob(cluster string, k8scronJob *v1beta1.CronJob) *k8sapiv1.CronJob { - clusterName := GetKubeCluster(k8scronJob) + clusterName := GetKubeClusterName(k8scronJob) if clusterName == "" { clusterName = cluster } diff --git a/backend/service/k8s/cronjob_test.go b/backend/service/k8s/cronjob_test.go index 62a090bf48..90cbdabcd2 100644 --- a/backend/service/k8s/cronjob_test.go +++ b/backend/service/k8s/cronjob_test.go @@ -88,7 +88,7 @@ func TestProtoForCron(t *testing.T) { cron: &v1beta1.CronJob{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - clusterClutchNameLabel: "production", + clutchLabelClusterName: "production", }, Name: "test1", }, @@ -102,7 +102,7 @@ func TestProtoForCron(t *testing.T) { cron: &v1beta1.CronJob{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - clusterClutchNameLabel: "", + clutchLabelClusterName: "", }, Name: "test2", }, diff --git a/backend/service/k8s/deployment.go b/backend/service/k8s/deployment.go index 71d2f63559..90895eb9a6 100644 --- a/backend/service/k8s/deployment.go +++ b/backend/service/k8s/deployment.go @@ -65,7 +65,7 @@ func (s *svc) ListDeployments(ctx context.Context, clientset, cluster, namespace } func ProtoForDeployment(cluster string, deployment *appsv1.Deployment) *k8sapiv1.Deployment { - clusterName := GetKubeCluster(deployment) + clusterName := GetKubeClusterName(deployment) if clusterName == "" { clusterName = cluster } diff --git a/backend/service/k8s/deployment_test.go b/backend/service/k8s/deployment_test.go index 67a1cb64e8..47bad492cc 100644 --- a/backend/service/k8s/deployment_test.go +++ b/backend/service/k8s/deployment_test.go @@ -227,7 +227,7 @@ func TestProtoForDeploymentClusterName(t *testing.T) { deployment: &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - clusterClutchNameLabel: "production", + clutchLabelClusterName: "production", }, }, }, @@ -239,7 +239,7 @@ func TestProtoForDeploymentClusterName(t *testing.T) { deployment: &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - clusterClutchNameLabel: "", + clutchLabelClusterName: "", }, }, }, diff --git a/backend/service/k8s/event.go b/backend/service/k8s/event.go index 96a056b6ad..e4411e99fb 100644 --- a/backend/service/k8s/event.go +++ b/backend/service/k8s/event.go @@ -35,7 +35,7 @@ func (s *svc) ListEvents(ctx context.Context, clientset, cluster, namespace, obj } func ProtoForEvent(cluster string, k8sEvent *corev1.Event) *k8sapiv1.Event { - clusterName := GetKubeCluster(k8sEvent) + clusterName := GetKubeClusterName(k8sEvent) if clusterName == "" { clusterName = cluster } diff --git a/backend/service/k8s/hpa.go b/backend/service/k8s/hpa.go index 2709634fea..9f21f94b5b 100644 --- a/backend/service/k8s/hpa.go +++ b/backend/service/k8s/hpa.go @@ -35,7 +35,7 @@ func (s *svc) DescribeHPA(ctx context.Context, clientset, cluster, namespace, na } func ProtoForHPA(cluster string, autoscaler *autoscalingv1.HorizontalPodAutoscaler) *k8sapiv1.HPA { - clusterName := GetKubeCluster(autoscaler) + clusterName := GetKubeClusterName(autoscaler) if clusterName == "" { clusterName = cluster } diff --git a/backend/service/k8s/hpa_test.go b/backend/service/k8s/hpa_test.go index f23d09984a..09927f1771 100644 --- a/backend/service/k8s/hpa_test.go +++ b/backend/service/k8s/hpa_test.go @@ -135,7 +135,7 @@ func TestProtoForHPAClusterName(t *testing.T) { hpa: &autoscalingv1.HorizontalPodAutoscaler{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - clusterClutchNameLabel: "production", + clutchLabelClusterName: "production", }, }, Spec: autoscalingv1.HorizontalPodAutoscalerSpec{ @@ -151,7 +151,7 @@ func TestProtoForHPAClusterName(t *testing.T) { hpa: &autoscalingv1.HorizontalPodAutoscaler{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - clusterClutchNameLabel: "", + clutchLabelClusterName: "", }, }, Spec: autoscalingv1.HorizontalPodAutoscalerSpec{ diff --git a/backend/service/k8s/job.go b/backend/service/k8s/job.go index 3b38eb0636..73015bdea1 100644 --- a/backend/service/k8s/job.go +++ b/backend/service/k8s/job.go @@ -85,7 +85,7 @@ func (s *svc) ListJobs(ctx context.Context, clientset, cluster, namespace string } func protoForJob(cluster string, k8sJob *v1.Job) *k8sapiv1.Job { - clusterName := GetKubeCluster(k8sJob) + clusterName := GetKubeClusterName(k8sJob) if clusterName == "" { clusterName = cluster } diff --git a/backend/service/k8s/job_test.go b/backend/service/k8s/job_test.go index fe7641d0e1..8d84c455c1 100644 --- a/backend/service/k8s/job_test.go +++ b/backend/service/k8s/job_test.go @@ -185,7 +185,7 @@ func TestProtoForJob(t *testing.T) { job: &v1.Job{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - clusterClutchNameLabel: "production", + clutchLabelClusterName: "production", }, }, }, @@ -197,7 +197,7 @@ func TestProtoForJob(t *testing.T) { job: &v1.Job{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - clusterClutchNameLabel: "staging", + clutchLabelClusterName: "staging", }, }, }, diff --git a/backend/service/k8s/kube_cluster.go b/backend/service/k8s/kube_cluster.go index 4f54439b18..7a2d2dd4b2 100644 --- a/backend/service/k8s/kube_cluster.go +++ b/backend/service/k8s/kube_cluster.go @@ -2,7 +2,7 @@ // // Previously we relied on the `clusterName` field on objectmeta // https://github.com/kubernetes/apimachinery/blob/2456ebdaba229616fab2161a615148884b46644b/pkg/apis/meta/v1/types.go#L266-L270 -// This has since be depreacted as of https://github.com/kubernetes/kubernetes/commit/331525670b772eb8956b7f5204078c51c00aaef3 +// This has since be deprecated as of https://github.com/kubernetes/kubernetes/commit/331525670b772eb8956b7f5204078c51c00aaef3 // and there was no replacement to this objectmeta field. // // To replace this we utilize our own label to denote which cluster the object belongs to, @@ -15,9 +15,9 @@ import ( "k8s.io/apimachinery/pkg/runtime" ) -const clusterClutchNameLabel = "cluster.clutch.sh/name" +const clutchLabelClusterName = "cluster.clutch.sh/name" -func GetKubeCluster(obj any) string { +func GetKubeClusterName(obj any) string { objectMeta, err := meta.Accessor(obj) if err != nil { // Callers are expected to handle nil cases @@ -25,7 +25,7 @@ func GetKubeCluster(obj any) string { } labels := objectMeta.GetLabels() - if cluster, ok := labels[clusterClutchNameLabel]; ok { + if cluster, ok := labels[clutchLabelClusterName]; ok { return cluster } @@ -39,7 +39,7 @@ func ApplyClusterLabels(cluster string, obj runtime.Object) error { } objMeta.SetLabels(labels.Merge(objMeta.GetLabels(), labels.Set{ - clusterClutchNameLabel: cluster, + clutchLabelClusterName: cluster, })) return nil diff --git a/backend/service/k8s/kube_cluster_test.go b/backend/service/k8s/kube_cluster_test.go index b7de3ef808..7176484dc1 100644 --- a/backend/service/k8s/kube_cluster_test.go +++ b/backend/service/k8s/kube_cluster_test.go @@ -10,7 +10,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" ) -func TestGetKubeCluster(t *testing.T) { +func TestGetKubeClusterName(t *testing.T) { t.Parallel() tests := []struct { name string @@ -21,7 +21,7 @@ func TestGetKubeCluster(t *testing.T) { name: "should find cluster", obj: &metav1.ObjectMeta{ Labels: map[string]string{ - clusterClutchNameLabel: "meow", + clutchLabelClusterName: "meow", }, }, expect: "meow", @@ -39,7 +39,7 @@ func TestGetKubeCluster(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - assert.Equal(t, tt.expect, GetKubeCluster(tt.obj)) + assert.Equal(t, tt.expect, GetKubeClusterName(tt.obj)) }) } } @@ -79,7 +79,7 @@ func TestApplyClusterLabels(t *testing.T) { err := ApplyClusterLabels(tt.cluster, tt.obj) if !tt.shouldError { assert.NoError(t, err) - assert.Equal(t, tt.cluster, GetKubeCluster(tt.obj)) + assert.Equal(t, tt.cluster, GetKubeClusterName(tt.obj)) } else { assert.Error(t, err) } diff --git a/backend/service/k8s/lightweightinformer.go b/backend/service/k8s/lightweightinformer.go index b7a6cff505..5b3c2e3dad 100644 --- a/backend/service/k8s/lightweightinformer.go +++ b/backend/service/k8s/lightweightinformer.go @@ -72,7 +72,7 @@ func NewLightweightInformer( } incomingObjectMeta.SetLabels(labels.Merge(incomingObjectMeta.GetLabels(), labels.Set{ - clusterClutchNameLabel: clusterName, + clutchLabelClusterName: clusterName, })) switch d.Type { @@ -91,8 +91,7 @@ func NewLightweightInformer( if err := cacheStore.Add(lightweightObj); err != nil { return err } - // (mikecutalo) : double check what isInInitialList is doing - h.OnAdd(d.Object, false) + h.OnAdd(d.Object, isInInitialList) } case cache.Deleted: if err := cacheStore.Delete(lightweightObj); err != nil { diff --git a/backend/service/k8s/log_test.go b/backend/service/k8s/log_test.go index 886f23f128..65f07260a1 100644 --- a/backend/service/k8s/log_test.go +++ b/backend/service/k8s/log_test.go @@ -24,7 +24,7 @@ func TestGetPodLogs(t *testing.T) { Namespace: "testing-namespace", Labels: map[string]string{ "foo": "bar", - clusterClutchNameLabel: "core-testing", + clutchLabelClusterName: "core-testing", }, Annotations: map[string]string{"baz": "quuz"}, }, diff --git a/backend/service/k8s/namespace.go b/backend/service/k8s/namespace.go index da8b0a9297..c44880758f 100644 --- a/backend/service/k8s/namespace.go +++ b/backend/service/k8s/namespace.go @@ -33,7 +33,7 @@ func (s *svc) DescribeNamespace(ctx context.Context, clientset, cluster, name st } func ProtoForNamespace(cluster string, k8snamespace *corev1.Namespace) *k8sapiv1.Namespace { - clusterName := GetKubeCluster(k8snamespace) + clusterName := GetKubeClusterName(k8snamespace) if clusterName == "" { clusterName = cluster } diff --git a/backend/service/k8s/node.go b/backend/service/k8s/node.go index e6be3c3aa8..8527da4101 100644 --- a/backend/service/k8s/node.go +++ b/backend/service/k8s/node.go @@ -34,7 +34,7 @@ func (s *svc) DescribeNode(ctx context.Context, clientset, cluster, name string) } func ProtoForNode(cluster string, k8snode *corev1.Node) *k8sapiv1.Node { - clusterName := GetKubeCluster(k8snode) + clusterName := GetKubeClusterName(k8snode) if clusterName == "" { clusterName = cluster } diff --git a/backend/service/k8s/pods.go b/backend/service/k8s/pods.go index b2fdec99dd..e9e40a21d1 100644 --- a/backend/service/k8s/pods.go +++ b/backend/service/k8s/pods.go @@ -171,7 +171,7 @@ func podDescription(k8spod *corev1.Pod, cluster string) *k8sapiv1.Pod { // if converted, err := ptypes.TimestampProto(k8spod.Status.StartTime.Time); err == nil { // launch = converted // } - clusterName := GetKubeCluster(k8spod) + clusterName := GetKubeClusterName(k8spod) if clusterName == "" { clusterName = cluster } diff --git a/backend/service/k8s/pods_test.go b/backend/service/k8s/pods_test.go index 7af67a4fed..4ed382b3b7 100644 --- a/backend/service/k8s/pods_test.go +++ b/backend/service/k8s/pods_test.go @@ -37,7 +37,7 @@ func testPodClientset() *fake.Clientset { Namespace: "testing-namespace", Labels: map[string]string{ "foo": "bar", - clusterClutchNameLabel: "production", + clutchLabelClusterName: "production", }, Annotations: map[string]string{"baz": "quuz"}, }, @@ -56,7 +56,7 @@ func testPodClientset() *fake.Clientset { Namespace: "testing-namespace", Labels: map[string]string{ "foo": "bar", - clusterClutchNameLabel: "staging", + clutchLabelClusterName: "staging", }, Annotations: map[string]string{"baz": "quuz"}, }, @@ -102,7 +102,7 @@ func testListFakeClientset(numPods int) *fake.Clientset { Name: fmt.Sprintf("testing-pod-name-%b", i), Namespace: "testing-namespace", Labels: map[string]string{ - clusterClutchNameLabel: "staging", + clutchLabelClusterName: "staging", }, }, }) @@ -237,7 +237,7 @@ func TestPodDescription(t *testing.T) { pod: &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - clusterClutchNameLabel: "production", + clutchLabelClusterName: "production", }, }, Status: corev1.PodStatus{ @@ -269,7 +269,7 @@ func TestPodDescription(t *testing.T) { pod: &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - clusterClutchNameLabel: "", + clutchLabelClusterName: "", }, }, Status: corev1.PodStatus{ @@ -323,7 +323,7 @@ func TestUpdatePod(t *testing.T) { Namespace: "testing-namespace", Labels: map[string]string{ "foo": "bar", - clusterClutchNameLabel: "staging", + clutchLabelClusterName: "staging", }, Annotations: map[string]string{"baz": "quuz"}, }, @@ -547,7 +547,7 @@ func TestPodStatus(t *testing.T) { pod: &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - clusterClutchNameLabel: "production", + clutchLabelClusterName: "production", }, }, Status: corev1.PodStatus{ @@ -572,7 +572,7 @@ func TestPodStatus(t *testing.T) { pod: &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - clusterClutchNameLabel: "production", + clutchLabelClusterName: "production", }, }, Status: corev1.PodStatus{ @@ -597,7 +597,7 @@ func TestPodStatus(t *testing.T) { pod: &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - clusterClutchNameLabel: "production", + clutchLabelClusterName: "production", }, }, Status: corev1.PodStatus{ @@ -632,7 +632,7 @@ func TestPodStatus(t *testing.T) { pod: &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - clusterClutchNameLabel: "production", + clutchLabelClusterName: "production", }, }, Status: corev1.PodStatus{ @@ -657,7 +657,7 @@ func TestPodStatus(t *testing.T) { pod: &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - clusterClutchNameLabel: "production", + clutchLabelClusterName: "production", }, }, Status: corev1.PodStatus{ diff --git a/backend/service/k8s/service.go b/backend/service/k8s/service.go index 78dc4918b5..f2a56e8b5a 100644 --- a/backend/service/k8s/service.go +++ b/backend/service/k8s/service.go @@ -69,7 +69,7 @@ func (s *svc) DeleteService(ctx context.Context, clientset, cluster, namespace, } func ProtoForService(cluster string, k8sservice *corev1.Service) *k8sapiv1.Service { - clusterName := GetKubeCluster(k8sservice) + clusterName := GetKubeClusterName(k8sservice) if clusterName == "" { clusterName = cluster } diff --git a/backend/service/k8s/service_test.go b/backend/service/k8s/service_test.go index a4cca19cee..2d61db1333 100644 --- a/backend/service/k8s/service_test.go +++ b/backend/service/k8s/service_test.go @@ -105,7 +105,7 @@ func TestProtoForServiceClusterName(t *testing.T) { service: &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - clusterClutchNameLabel: "production", + clutchLabelClusterName: "production", }, }, }, @@ -117,7 +117,7 @@ func TestProtoForServiceClusterName(t *testing.T) { service: &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - clusterClutchNameLabel: "", + clutchLabelClusterName: "", }, }, }, diff --git a/backend/service/k8s/statefulset.go b/backend/service/k8s/statefulset.go index de258b0aa3..997f686fea 100644 --- a/backend/service/k8s/statefulset.go +++ b/backend/service/k8s/statefulset.go @@ -63,7 +63,7 @@ func (s *svc) ListStatefulSets(ctx context.Context, clientset, cluster, namespac // ProtoForStatefulSet maps a Kubernetes Stateful Set object to a k8sapiv1 object func ProtoForStatefulSet(cluster string, statefulSet *appsv1.StatefulSet) *k8sapiv1.StatefulSet { - clusterName := GetKubeCluster(statefulSet) + clusterName := GetKubeClusterName(statefulSet) if clusterName == "" { clusterName = cluster } diff --git a/backend/service/k8s/statefulset_test.go b/backend/service/k8s/statefulset_test.go index 48f8624a1a..5c7f86a5fa 100644 --- a/backend/service/k8s/statefulset_test.go +++ b/backend/service/k8s/statefulset_test.go @@ -183,7 +183,7 @@ func TestProtoForStatefulSetClusterName(t *testing.T) { statefulSet: &appsv1.StatefulSet{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - clusterClutchNameLabel: "production", + clutchLabelClusterName: "production", }, }, }, @@ -195,7 +195,7 @@ func TestProtoForStatefulSetClusterName(t *testing.T) { statefulSet: &appsv1.StatefulSet{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - clusterClutchNameLabel: "", + clutchLabelClusterName: "", }, }, },