From f06031f2479cc847f864a9db9204585d2788df08 Mon Sep 17 00:00:00 2001 From: Mohammed Firdous <124298708+mohammedfirdouss@users.noreply.github.com> Date: Sun, 17 May 2026 08:05:19 +0000 Subject: [PATCH] fix(kubernetes_multicluster): pin Is* methods to exact Kubernetes API groups Signed-off-by: Mohammed Firdous <124298708+mohammedfirdouss@users.noreply.github.com> --- .../config/application.go | 2 - .../provider/diff_test.go | 20 +++---- .../provider/manifest.go | 57 ++++--------------- 3 files changed, 21 insertions(+), 58 deletions(-) diff --git a/pkg/app/pipedv1/plugin/kubernetes_multicluster/config/application.go b/pkg/app/pipedv1/plugin/kubernetes_multicluster/config/application.go index ca51727db0..eb7da09fbb 100644 --- a/pkg/app/pipedv1/plugin/kubernetes_multicluster/config/application.go +++ b/pkg/app/pipedv1/plugin/kubernetes_multicluster/config/application.go @@ -109,8 +109,6 @@ type KubernetesDeploymentInput struct { // Default is false. AutoCreateNamespace bool `json:"autoCreateNamespace,omitempty"` - // TODO: Define fields for KubernetesDeploymentInput. - MultiTargets []KubernetesMultiTarget `json:"multiTargets,omitempty"` } diff --git a/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/diff_test.go b/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/diff_test.go index 6aa687227f..5c62bf9987 100644 --- a/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/diff_test.go +++ b/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/diff_test.go @@ -38,12 +38,12 @@ func TestDiff(t *testing.T) { }{ { name: "Secret no diff 1", - manifests: `apiVersion: apps/v1 + manifests: `apiVersion: v1 kind: Secret metadata: name: secret-management --- -apiVersion: apps/v1 +apiVersion: v1 kind: Secret metadata: name: secret-management @@ -53,7 +53,7 @@ metadata: }, { name: "Secret no diff 2", - manifests: `apiVersion: apps/v1 + manifests: `apiVersion: v1 kind: Secret metadata: name: secret-management @@ -62,7 +62,7 @@ data: stringData: foo: bar --- -apiVersion: apps/v1 +apiVersion: v1 kind: Secret metadata: name: secret-management @@ -76,7 +76,7 @@ stringData: }, { name: "Secret no diff with merge", - manifests: `apiVersion: apps/v1 + manifests: `apiVersion: v1 kind: Secret metadata: name: secret-management @@ -84,7 +84,7 @@ data: password: hoge foo: YmFy --- -apiVersion: apps/v1 +apiVersion: v1 kind: Secret metadata: name: secret-management @@ -98,7 +98,7 @@ stringData: }, { name: "Secret no diff override false-positive", - manifests: `apiVersion: apps/v1 + manifests: `apiVersion: v1 kind: Secret metadata: name: secret-management @@ -106,7 +106,7 @@ data: password: hoge foo: YmFy --- -apiVersion: apps/v1 +apiVersion: v1 kind: Secret metadata: name: secret-management @@ -122,14 +122,14 @@ stringData: }, { name: "Secret has diff", - manifests: `apiVersion: apps/v1 + manifests: `apiVersion: v1 kind: Secret metadata: name: secret-management data: foo: YmFy --- -apiVersion: apps/v1 +apiVersion: v1 kind: Secret metadata: name: secret-management diff --git a/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/manifest.go b/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/manifest.go index ab76fc1db2..dbebe53682 100644 --- a/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/manifest.go +++ b/pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/manifest.go @@ -25,34 +25,6 @@ import ( sdk "github.com/pipe-cd/piped-plugin-sdk-go" ) -var builtinAPIGroups = map[string]struct{}{ - "admissionregistration.k8s.io": {}, - "apiextensions.k8s.io": {}, - "apiregistration.k8s.io": {}, - "apps": {}, - "authentication.k8s.io": {}, - "authorization.k8s.io": {}, - "autoscaling": {}, - "batch": {}, - "certificates.k8s.io": {}, - "coordination.k8s.io": {}, - "extensions": {}, - "internal.autoscaling.k8s.io": {}, - "metrics.k8s.io": {}, - "networking.k8s.io": {}, - "node.k8s.io": {}, - "policy": {}, - "rbac.authorization.k8s.io": {}, - "scheduling.k8s.io": {}, - "storage.k8s.io": {}, - "": {}, -} - -func isBuiltinAPIGroup(apiGroup string) bool { - _, ok := builtinAPIGroups[apiGroup] - return ok -} - // Manifest represents a Kubernetes resource manifest. type Manifest struct { body *unstructured.Unstructured @@ -121,13 +93,12 @@ func (m Manifest) Name() string { // IsWorkload returns true if the manifest is a Deployment, StatefulSet, DaemonSet, ReplicaSet, or Pod. // It checks the API group and the kind of the manifest. func (m Manifest) IsWorkload() bool { - // TODO: check the API group more strictly. - if !isBuiltinAPIGroup(m.body.GroupVersionKind().Group) { - return false - } + group := m.body.GroupVersionKind().Group switch m.body.GetKind() { - case KindDeployment, KindStatefulSet, KindDaemonSet, KindReplicaSet, KindPod: - return true + case KindDeployment, KindStatefulSet, KindDaemonSet, KindReplicaSet: + return group == "apps" + case KindPod: + return group == "" default: return false } @@ -136,43 +107,37 @@ func (m Manifest) IsWorkload() bool { // IsService returns true if the manifest is a Service. // It checks the API group and the kind of the manifest. func (m Manifest) IsService() bool { - // TODO: check the API group more strictly. - return isBuiltinAPIGroup(m.body.GroupVersionKind().Group) && m.body.GetKind() == KindService + return m.body.GroupVersionKind().Group == "" && m.body.GetKind() == KindService } // IsDeployment returns true if the manifest is a Deployment. // It checks the API group and the kind of the manifest. func (m Manifest) IsDeployment() bool { - // TODO: check the API group more strictly. - return isBuiltinAPIGroup(m.body.GroupVersionKind().Group) && m.body.GetKind() == KindDeployment + return m.body.GroupVersionKind().Group == "apps" && m.body.GetKind() == KindDeployment } // IsStatefulSet returns true if the manifest is a StatefulSet. // It checks the API group and the kind of the manifest. func (m Manifest) IsStatefulSet() bool { - // TODO: check the API group more strictly. - return isBuiltinAPIGroup(m.body.GroupVersionKind().Group) && m.body.GetKind() == KindStatefulSet + return m.body.GroupVersionKind().Group == "apps" && m.body.GetKind() == KindStatefulSet } // IsDaemonSet returns true if the manifest is a DaemonSet. // It checks the API group and the kind of the manifest. func (m Manifest) IsDaemonSet() bool { - // TODO: check the API group more strictly. - return isBuiltinAPIGroup(m.body.GroupVersionKind().Group) && m.body.GetKind() == KindDaemonSet + return m.body.GroupVersionKind().Group == "apps" && m.body.GetKind() == KindDaemonSet } // IsSecret returns true if the manifest is a Secret. // It checks the API group and the kind of the manifest. func (m Manifest) IsSecret() bool { - // TODO: check the API group more strictly. - return isBuiltinAPIGroup(m.body.GroupVersionKind().Group) && m.body.GetKind() == KindSecret + return m.body.GroupVersionKind().Group == "" && m.body.GetKind() == KindSecret } // IsConfigMap returns true if the manifest is a ConfigMap. // It checks the API group and the kind of the manifest. func (m Manifest) IsConfigMap() bool { - // TODO: check the API group more strictly. - return isBuiltinAPIGroup(m.body.GroupVersionKind().Group) && m.body.GetKind() == KindConfigMap + return m.body.GroupVersionKind().Group == "" && m.body.GetKind() == KindConfigMap } // UnmarshalJSON implements the json.Unmarshaler interface.