Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -53,7 +53,7 @@ metadata:
},
{
name: "Secret no diff 2",
manifests: `apiVersion: apps/v1
manifests: `apiVersion: v1
kind: Secret
metadata:
name: secret-management
Expand All @@ -62,7 +62,7 @@ data:
stringData:
foo: bar
---
apiVersion: apps/v1
apiVersion: v1
kind: Secret
metadata:
name: secret-management
Expand All @@ -76,15 +76,15 @@ stringData:
},
{
name: "Secret no diff with merge",
manifests: `apiVersion: apps/v1
manifests: `apiVersion: v1
kind: Secret
metadata:
name: secret-management
data:
password: hoge
foo: YmFy
---
apiVersion: apps/v1
apiVersion: v1
kind: Secret
metadata:
name: secret-management
Expand All @@ -98,15 +98,15 @@ stringData:
},
{
name: "Secret no diff override false-positive",
manifests: `apiVersion: apps/v1
manifests: `apiVersion: v1
kind: Secret
metadata:
name: secret-management
data:
password: hoge
foo: YmFy
---
apiVersion: apps/v1
apiVersion: v1
kind: Secret
metadata:
name: secret-management
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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.
Expand Down
Loading