Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Fix: Remove PDB for single replica deployment
Browse files Browse the repository at this point in the history
Signed-off-by: Daishan Peng <[email protected]>
  • Loading branch information
StrongMonkey committed Feb 16, 2024
1 parent b5a6c7f commit 9da0484
Show file tree
Hide file tree
Showing 23 changed files with 18 additions and 868 deletions.
11 changes: 9 additions & 2 deletions pkg/controller/appdefinition/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,10 @@ func ToFunctions(req router.Request, appInstance *v1.AppInstance, tag name.Refer
}
result = append(result, perms...)
}
result = append(result, sa, dep, pdb.ToPodDisruptionBudget(dep))
result = append(result, sa, dep)
if dep.Spec.Replicas != nil && *dep.Spec.Replicas > 1 {
result = append(result, pdb.ToPodDisruptionBudget(dep))
}
}

return result, nil
Expand Down Expand Up @@ -1036,7 +1039,11 @@ func ToDeployments(req router.Request, appInstance *v1.AppInstance, tag name.Ref
}
result = append(result, perms...)
}
result = append(result, sa, dep, pdb.ToPodDisruptionBudget(dep))
result = append(result, sa, dep)

if dep.Spec.Replicas != nil && *dep.Spec.Replicas > 1 {
result = append(result, pdb.ToPodDisruptionBudget(dep))
}
}

return result, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/appdefinition/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func TestFiles(t *testing.T) {
assert.Equal(t, "/a/b2/c", dep.Spec.Template.Spec.Containers[1].VolumeMounts[1].MountPath)
assert.Equal(t, toHash("ZA=="), dep.Spec.Template.Spec.Containers[1].VolumeMounts[1].SubPath)

configMap := objs[6].(*corev1.Secret)
configMap := objs[4].(*corev1.Secret)

assert.Len(t, configMap.Data, 2)
assert.Equal(t, []byte("d"), configMap.Data[toHash("ZA==")])
Expand Down
11 changes: 8 additions & 3 deletions pkg/controller/appdefinition/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func toRouter(appInstance *v1.AppInstance, routerName string, router v1.Router,
dep.Spec.Replicas = new(int32)
}

return []kclient.Object{
objects := []kclient.Object{
dep,
&corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{},
Expand All @@ -180,8 +180,13 @@ func toRouter(appInstance *v1.AppInstance, routerName string, router v1.Router,
Annotations: deploymentAnnotations,
},
},
pdb.ToPodDisruptionBudget(dep),
}, nil
}

if dep.Spec.Replicas != nil && *dep.Spec.Replicas > 1 {
objects = append(objects, pdb.ToPodDisruptionBudget(dep))
}

return objects, nil
}

func toNginxConf(internalClusterDomain, namespace, routerName string, router v1.Router) (string, string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,36 +112,6 @@ spec:
terminationGracePeriodSeconds: 10
status: {}

---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
annotations:
acorn.io/config-hash: ""
creationTimestamp: null
labels:
acorn.io/app-name: app-name
acorn.io/app-namespace: app-namespace
acorn.io/app-public-name: app-name
acorn.io/container-name: oneimage
acorn.io/managed: "true"
acorn.io/project-name: app-namespace
name: oneimage
namespace: app-created-namespace
spec:
maxUnavailable: 25%
selector:
matchLabels:
acorn.io/app-name: app-name
acorn.io/app-namespace: app-namespace
acorn.io/container-name: oneimage
acorn.io/managed: "true"
status:
currentHealthy: 0
desiredHealthy: 0
disruptionsAllowed: 0
expectedPods: 0

---
apiVersion: internal.acorn.io/v1
kind: ServiceInstance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,36 +112,6 @@ spec:
terminationGracePeriodSeconds: 10
status: {}

---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
annotations:
acorn.io/config-hash: ""
creationTimestamp: null
labels:
acorn.io/app-name: app-name
acorn.io/app-namespace: app-namespace
acorn.io/app-public-name: app-name
acorn.io/container-name: oneimage
acorn.io/managed: "true"
acorn.io/project-name: app-namespace
name: oneimage
namespace: app-created-namespace
spec:
maxUnavailable: 25%
selector:
matchLabels:
acorn.io/app-name: app-name
acorn.io/app-namespace: app-namespace
acorn.io/container-name: oneimage
acorn.io/managed: "true"
status:
currentHealthy: 0
desiredHealthy: 0
disruptionsAllowed: 0
expectedPods: 0

---
apiVersion: internal.acorn.io/v1
kind: ServiceInstance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,36 +112,6 @@ spec:
terminationGracePeriodSeconds: 10
status: {}

---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
annotations:
acorn.io/config-hash: ""
creationTimestamp: null
labels:
acorn.io/app-name: app-name
acorn.io/app-namespace: app-namespace
acorn.io/app-public-name: app-name
acorn.io/container-name: oneimage
acorn.io/managed: "true"
acorn.io/project-name: app-namespace
name: oneimage
namespace: app-created-namespace
spec:
maxUnavailable: 25%
selector:
matchLabels:
acorn.io/app-name: app-name
acorn.io/app-namespace: app-namespace
acorn.io/container-name: oneimage
acorn.io/managed: "true"
status:
currentHealthy: 0
desiredHealthy: 0
disruptionsAllowed: 0
expectedPods: 0

---
apiVersion: internal.acorn.io/v1
kind: ServiceInstance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,36 +112,6 @@ spec:
terminationGracePeriodSeconds: 10
status: {}

---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
annotations:
acorn.io/config-hash: ""
creationTimestamp: null
labels:
acorn.io/app-name: app-name
acorn.io/app-namespace: app-namespace
acorn.io/app-public-name: app-name
acorn.io/container-name: oneimage
acorn.io/managed: "true"
acorn.io/project-name: app-namespace
name: oneimage
namespace: app-created-namespace
spec:
maxUnavailable: 25%
selector:
matchLabels:
acorn.io/app-name: app-name
acorn.io/app-namespace: app-namespace
acorn.io/container-name: oneimage
acorn.io/managed: "true"
status:
currentHealthy: 0
desiredHealthy: 0
disruptionsAllowed: 0
expectedPods: 0

---
apiVersion: v1
kind: ServiceAccount
Expand Down Expand Up @@ -229,36 +199,6 @@ spec:
terminationGracePeriodSeconds: 10
status: {}

---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
annotations:
acorn.io/config-hash: ""
creationTimestamp: null
labels:
acorn.io/app-name: app-name
acorn.io/app-namespace: app-namespace
acorn.io/app-public-name: app-name
acorn.io/container-name: twoimage
acorn.io/managed: "true"
acorn.io/project-name: app-namespace
name: twoimage
namespace: app-created-namespace
spec:
maxUnavailable: 25%
selector:
matchLabels:
acorn.io/app-name: app-name
acorn.io/app-namespace: app-namespace
acorn.io/container-name: twoimage
acorn.io/managed: "true"
status:
currentHealthy: 0
desiredHealthy: 0
disruptionsAllowed: 0
expectedPods: 0

---
apiVersion: internal.acorn.io/v1
kind: ServiceInstance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,36 +114,6 @@ spec:
terminationGracePeriodSeconds: 10
status: {}

---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
annotations:
acorn.io/config-hash: ""
creationTimestamp: null
labels:
acorn.io/app-name: app-name
acorn.io/app-namespace: app-namespace
acorn.io/app-public-name: app-name
acorn.io/container-name: oneimage
acorn.io/managed: "true"
acorn.io/project-name: app-namespace
name: oneimage
namespace: app-created-namespace
spec:
maxUnavailable: 25%
selector:
matchLabels:
acorn.io/app-name: app-name
acorn.io/app-namespace: app-namespace
acorn.io/container-name: oneimage
acorn.io/managed: "true"
status:
currentHealthy: 0
desiredHealthy: 0
disruptionsAllowed: 0
expectedPods: 0

---
apiVersion: internal.acorn.io/v1
kind: ServiceInstance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,36 +112,6 @@ spec:
terminationGracePeriodSeconds: 10
status: {}

---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
annotations:
acorn.io/config-hash: ""
creationTimestamp: null
labels:
acorn.io/app-name: app-name
acorn.io/app-namespace: app-namespace
acorn.io/app-public-name: app-name
acorn.io/container-name: oneimage
acorn.io/managed: "true"
acorn.io/project-name: app-namespace
name: oneimage
namespace: app-created-namespace
spec:
maxUnavailable: 25%
selector:
matchLabels:
acorn.io/app-name: app-name
acorn.io/app-namespace: app-namespace
acorn.io/container-name: oneimage
acorn.io/managed: "true"
status:
currentHealthy: 0
desiredHealthy: 0
disruptionsAllowed: 0
expectedPods: 0

---
apiVersion: internal.acorn.io/v1
kind: ServiceInstance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,36 +112,6 @@ spec:
terminationGracePeriodSeconds: 10
status: {}

---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
annotations:
acorn.io/config-hash: ""
creationTimestamp: null
labels:
acorn.io/app-name: app-name
acorn.io/app-namespace: app-namespace
acorn.io/app-public-name: app-name
acorn.io/container-name: oneimage
acorn.io/managed: "true"
acorn.io/project-name: app-namespace
name: oneimage
namespace: app-created-namespace
spec:
maxUnavailable: 25%
selector:
matchLabels:
acorn.io/app-name: app-name
acorn.io/app-namespace: app-namespace
acorn.io/container-name: oneimage
acorn.io/managed: "true"
status:
currentHealthy: 0
desiredHealthy: 0
disruptionsAllowed: 0
expectedPods: 0

---
apiVersion: v1
kind: ServiceAccount
Expand Down Expand Up @@ -215,36 +185,6 @@ spec:
terminationGracePeriodSeconds: 10
status: {}

---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
annotations:
acorn.io/config-hash: ""
creationTimestamp: null
labels:
acorn.io/app-name: app-name
acorn.io/app-namespace: app-namespace
acorn.io/app-public-name: app-name
acorn.io/container-name: twoimage
acorn.io/managed: "true"
acorn.io/project-name: app-namespace
name: twoimage
namespace: app-created-namespace
spec:
maxUnavailable: 25%
selector:
matchLabels:
acorn.io/app-name: app-name
acorn.io/app-namespace: app-namespace
acorn.io/container-name: twoimage
acorn.io/managed: "true"
status:
currentHealthy: 0
desiredHealthy: 0
disruptionsAllowed: 0
expectedPods: 0

---
apiVersion: internal.acorn.io/v1
kind: ServiceInstance
Expand Down
Loading

0 comments on commit 9da0484

Please sign in to comment.