Skip to content

Commit

Permalink
support daemonset apps/v1beta2 (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
nschhina authored Mar 18, 2019
1 parent 61d5cd8 commit e9d3d15
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cmd/automountServiceAccountToken_fixes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ func TestFixServiceAccountTokenDeprecatedV2(t *testing.T) {
case *DaemonSetV1Beta1:
assert.Equal("fakeDeprecatedServiceAccount", t.Spec.Template.Spec.ServiceAccountName)
assert.Equal("", t.Spec.Template.Spec.DeprecatedServiceAccount)
case *DaemonSetV1Beta2:
assert.Equal("fakeDeprecatedServiceAccount", t.Spec.Template.Spec.ServiceAccountName)
assert.Equal("", t.Spec.Template.Spec.DeprecatedServiceAccount)
case *DeploymentExtensionsV1Beta1:
assert.Equal("fakeDeprecatedServiceAccount", t.Spec.Template.Spec.ServiceAccountName)
assert.Equal("", t.Spec.Template.Spec.DeprecatedServiceAccount)
Expand Down Expand Up @@ -70,6 +73,8 @@ func TestFixServiceAccountTokenTrueAndNoNameV2(t *testing.T) {
assert.False(*t.Spec.Template.Spec.AutomountServiceAccountToken)
case *DaemonSetV1Beta1:
assert.False(*t.Spec.Template.Spec.AutomountServiceAccountToken)
case *DaemonSetV1Beta2:
assert.False(*t.Spec.Template.Spec.AutomountServiceAccountToken)
case *DeploymentExtensionsV1Beta1:
assert.False(*t.Spec.Template.Spec.AutomountServiceAccountToken)
case *DeploymentV1:
Expand Down
17 changes: 17 additions & 0 deletions cmd/k8sruntime_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func setContainers(resource Resource, containers []ContainerV1) Resource {
case *DaemonSetV1Beta1:
t.Spec.Template.Spec.Containers = containers
return t.DeepCopyObject()
case *DaemonSetV1Beta2:
t.Spec.Template.Spec.Containers = containers
return t.DeepCopyObject()
case *DeploymentExtensionsV1Beta1:
t.Spec.Template.Spec.Containers = containers
return t.DeepCopyObject()
Expand Down Expand Up @@ -74,6 +77,10 @@ func disableDSA(resource Resource) Resource {
t.Spec.Template.Spec.ServiceAccountName = t.Spec.Template.Spec.DeprecatedServiceAccount
t.Spec.Template.Spec.DeprecatedServiceAccount = ""
return t.DeepCopyObject()
case *DaemonSetV1Beta2:
t.Spec.Template.Spec.ServiceAccountName = t.Spec.Template.Spec.DeprecatedServiceAccount
t.Spec.Template.Spec.DeprecatedServiceAccount = ""
return t.DeepCopyObject()
case *DeploymentExtensionsV1Beta1:
t.Spec.Template.Spec.ServiceAccountName = t.Spec.Template.Spec.DeprecatedServiceAccount
t.Spec.Template.Spec.DeprecatedServiceAccount = ""
Expand Down Expand Up @@ -127,6 +134,9 @@ func setASAT(resource Resource, b bool) Resource {
case *DaemonSetV1Beta1:
t.Spec.Template.Spec.AutomountServiceAccountToken = boolean
return t.DeepCopyObject()
case *DaemonSetV1Beta2:
t.Spec.Template.Spec.AutomountServiceAccountToken = boolean
return t.DeepCopyObject()
case *DeploymentExtensionsV1Beta1:
t.Spec.Template.Spec.AutomountServiceAccountToken = boolean
return t.DeepCopyObject()
Expand Down Expand Up @@ -166,6 +176,9 @@ func setPodAnnotations(resource Resource, annotations map[string]string) Resourc
case *DaemonSetV1Beta1:
kubeType.Spec.Template.ObjectMeta.SetAnnotations(annotations)
return kubeType.DeepCopyObject()
case *DaemonSetV1Beta2:
kubeType.Spec.Template.ObjectMeta.SetAnnotations(annotations)
return kubeType.DeepCopyObject()
case *DeploymentExtensionsV1Beta1:
kubeType.Spec.Template.ObjectMeta.SetAnnotations(annotations)
return kubeType.DeepCopyObject()
Expand Down Expand Up @@ -202,6 +215,8 @@ func getContainers(resource Resource) (container []ContainerV1) {
container = kubeType.Spec.Template.Spec.Containers
case *DaemonSetV1Beta1:
container = kubeType.Spec.Template.Spec.Containers
case *DaemonSetV1Beta2:
container = kubeType.Spec.Template.Spec.Containers
case *DeploymentExtensionsV1Beta1:
container = kubeType.Spec.Template.Spec.Containers
case *DeploymentV1:
Expand Down Expand Up @@ -240,6 +255,8 @@ func getPodAnnotations(resource Resource) (annotations map[string]string) {
annotations = kubeType.Spec.Template.ObjectMeta.GetAnnotations()
case *DaemonSetV1Beta1:
annotations = kubeType.Spec.Template.ObjectMeta.GetAnnotations()
case *DaemonSetV1Beta2:
annotations = kubeType.Spec.Template.ObjectMeta.GetAnnotations()
case *DeploymentExtensionsV1Beta1:
annotations = kubeType.Spec.Template.ObjectMeta.GetAnnotations()
case *DeploymentV1:
Expand Down
5 changes: 4 additions & 1 deletion cmd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ type DaemonSetV1 = appsv1.DaemonSet
// DaemonSetV1Beta1 is a type alias for the v1beta1 version of the k8s extensions API.
type DaemonSetV1Beta1 = extensionsv1beta1.DaemonSet

// DaemonSetV1Beta2 is a type alias for the v1beta2 version of the k8s extensions API.
type DaemonSetV1Beta2 = appsv1beta2.DaemonSet

// DeploymentExtensionsV1Beta1 is a type alias for the v1beta1 version of the k8s extensions API.
type DeploymentExtensionsV1Beta1 = extensionsv1beta1.Deployment

Expand Down Expand Up @@ -106,7 +109,7 @@ type UnsupportedType = apiv1.Binding
func IsSupportedResourceType(obj Resource) bool {
switch obj.(type) {
case *CronJobV1Beta1,
*DaemonSetListV1, *DaemonSetV1, *DaemonSetV1Beta1,
*DaemonSetListV1, *DaemonSetV1, *DaemonSetV1Beta1, *DaemonSetV1Beta2,
*DeploymentExtensionsV1Beta1, *DeploymentV1, *DeploymentV1Beta1, *DeploymentV1Beta2, *DeploymentListV1,
*NamespaceListV1, *NamespaceV1,
*NetworkPolicyListV1, *NetworkPolicyV1,
Expand Down
9 changes: 9 additions & 0 deletions cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func newResultFromResource(resource Resource) (*Result, error, error) {
result.Labels = kubeType.Spec.Template.Labels
result.Name = kubeType.Name
result.Namespace = kubeType.Namespace
case *DaemonSetV1Beta2:
result.KubeType = "daemonSet"
result.Labels = kubeType.Spec.Template.Labels
result.Name = kubeType.Name
result.Namespace = kubeType.Namespace
case *DeploymentExtensionsV1Beta1:
result.KubeType = "deployment"
result.Labels = kubeType.Spec.Template.Labels
Expand Down Expand Up @@ -123,6 +128,10 @@ func newResultFromResourceWithServiceAccountInfo(resource Resource) (*Result, er
result.DSA = kubeType.Spec.Template.Spec.DeprecatedServiceAccount
result.SA = kubeType.Spec.Template.Spec.ServiceAccountName
result.Token = kubeType.Spec.Template.Spec.AutomountServiceAccountToken
case *DaemonSetV1Beta2:
result.DSA = kubeType.Spec.Template.Spec.DeprecatedServiceAccount
result.SA = kubeType.Spec.Template.Spec.ServiceAccountName
result.Token = kubeType.Spec.Template.Spec.AutomountServiceAccountToken
case *DaemonSetV1:
result.DSA = kubeType.Spec.Template.Spec.DeprecatedServiceAccount
result.SA = kubeType.Spec.Template.Spec.ServiceAccountName
Expand Down
16 changes: 16 additions & 0 deletions fixtures/apparmor_annotation_missing_multiple_resources_v1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ spec:
status:
replicas: 0
---
apiVersion: apps/v1beta2
kind: DaemonSet
metadata:
name: fakeReplicationController1
namespace: fakeReplicationController
spec:
template:
metadata:
labels:
apps: fakeAutomountServiceAccountToken
spec:
containers:
- name: fakeContainer
status:
replicas: 0
---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ spec:
status:
replicas: 0
---
apiVersion: apps/v1beta2
kind: DaemonSet
metadata:
creationTimestamp: null
name: fakeReplicationControllerASAT1
namespace: fakeReplicationControllerASAT
spec:
template:
metadata:
creationTimestamp: null
labels:
apps: fakeAutomountServiceAccountToken
spec:
containers:
- name: fakeContainerASAT
resources: {}
serviceAccount: fakeDeprecatedServiceAccount
---
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ spec:
status:
replicas: 0
---
apiVersion: apps/v1beta2
kind: DaemonSet
metadata:
creationTimestamp: null
name: fakeReplicationControllerASAT1
namespace: fakeReplicationControllerASAT
spec:
template:
metadata:
creationTimestamp: null
labels:
apps: fakeAutomountServiceAccountToken
spec:
containers:
- name: fakeContainerASAT
resources: {}
automountServiceAccountToken: true
status:
replicas: 0
---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down

0 comments on commit e9d3d15

Please sign in to comment.