@@ -25,33 +25,6 @@ import (
2525 sdk "github.com/pipe-cd/piped-plugin-sdk-go"
2626)
2727
28- var builtinAPIGroups = map [string ]struct {}{
29- "admissionregistration.k8s.io" : {},
30- "apiextensions.k8s.io" : {},
31- "apiregistration.k8s.io" : {},
32- "apps" : {},
33- "authentication.k8s.io" : {},
34- "authorization.k8s.io" : {},
35- "autoscaling" : {},
36- "batch" : {},
37- "certificates.k8s.io" : {},
38- "coordination.k8s.io" : {},
39- "extensions" : {},
40- "internal.autoscaling.k8s.io" : {},
41- "metrics.k8s.io" : {},
42- "networking.k8s.io" : {},
43- "node.k8s.io" : {},
44- "policy" : {},
45- "rbac.authorization.k8s.io" : {},
46- "scheduling.k8s.io" : {},
47- "storage.k8s.io" : {},
48- "" : {},
49- }
50-
51- func isBuiltinAPIGroup (apiGroup string ) bool {
52- _ , ok := builtinAPIGroups [apiGroup ]
53- return ok
54- }
5528
5629// Manifest represents a Kubernetes resource manifest.
5730type Manifest struct {
@@ -121,13 +94,12 @@ func (m Manifest) Name() string {
12194// IsWorkload returns true if the manifest is a Deployment, StatefulSet, DaemonSet, ReplicaSet, or Pod.
12295// It checks the API group and the kind of the manifest.
12396func (m Manifest ) IsWorkload () bool {
124- // TODO: check the API group more strictly.
125- if ! isBuiltinAPIGroup (m .body .GroupVersionKind ().Group ) {
126- return false
127- }
97+ group := m .body .GroupVersionKind ().Group
12898 switch m .body .GetKind () {
129- case KindDeployment , KindStatefulSet , KindDaemonSet , KindReplicaSet , KindPod :
130- return true
99+ case KindDeployment , KindStatefulSet , KindDaemonSet , KindReplicaSet :
100+ return group == "apps"
101+ case KindPod :
102+ return group == ""
131103 default :
132104 return false
133105 }
@@ -136,43 +108,37 @@ func (m Manifest) IsWorkload() bool {
136108// IsService returns true if the manifest is a Service.
137109// It checks the API group and the kind of the manifest.
138110func (m Manifest ) IsService () bool {
139- // TODO: check the API group more strictly.
140- return isBuiltinAPIGroup (m .body .GroupVersionKind ().Group ) && m .body .GetKind () == KindService
111+ return m .body .GroupVersionKind ().Group == "" && m .body .GetKind () == KindService
141112}
142113
143114// IsDeployment returns true if the manifest is a Deployment.
144115// It checks the API group and the kind of the manifest.
145116func (m Manifest ) IsDeployment () bool {
146- // TODO: check the API group more strictly.
147- return isBuiltinAPIGroup (m .body .GroupVersionKind ().Group ) && m .body .GetKind () == KindDeployment
117+ return m .body .GroupVersionKind ().Group == "apps" && m .body .GetKind () == KindDeployment
148118}
149119
150120// IsStatefulSet returns true if the manifest is a StatefulSet.
151121// It checks the API group and the kind of the manifest.
152122func (m Manifest ) IsStatefulSet () bool {
153- // TODO: check the API group more strictly.
154- return isBuiltinAPIGroup (m .body .GroupVersionKind ().Group ) && m .body .GetKind () == KindStatefulSet
123+ return m .body .GroupVersionKind ().Group == "apps" && m .body .GetKind () == KindStatefulSet
155124}
156125
157126// IsDaemonSet returns true if the manifest is a DaemonSet.
158127// It checks the API group and the kind of the manifest.
159128func (m Manifest ) IsDaemonSet () bool {
160- // TODO: check the API group more strictly.
161- return isBuiltinAPIGroup (m .body .GroupVersionKind ().Group ) && m .body .GetKind () == KindDaemonSet
129+ return m .body .GroupVersionKind ().Group == "apps" && m .body .GetKind () == KindDaemonSet
162130}
163131
164132// IsSecret returns true if the manifest is a Secret.
165133// It checks the API group and the kind of the manifest.
166134func (m Manifest ) IsSecret () bool {
167- // TODO: check the API group more strictly.
168- return isBuiltinAPIGroup (m .body .GroupVersionKind ().Group ) && m .body .GetKind () == KindSecret
135+ return m .body .GroupVersionKind ().Group == "" && m .body .GetKind () == KindSecret
169136}
170137
171138// IsConfigMap returns true if the manifest is a ConfigMap.
172139// It checks the API group and the kind of the manifest.
173140func (m Manifest ) IsConfigMap () bool {
174- // TODO: check the API group more strictly.
175- return isBuiltinAPIGroup (m .body .GroupVersionKind ().Group ) && m .body .GetKind () == KindConfigMap
141+ return m .body .GroupVersionKind ().Group == "" && m .body .GetKind () == KindConfigMap
176142}
177143
178144// UnmarshalJSON implements the json.Unmarshaler interface.
0 commit comments