Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for PodDisruptionBudget #308

Merged
merged 2 commits into from
Jan 29, 2020
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
8 changes: 8 additions & 0 deletions deploy/crds/apps_v1alpha1_apimanager_cr_pdb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: apps.3scale.net/v1alpha1
kind: APIManager
metadata:
name: example-apimanager
spec:
wildcardDomain: example.com
podDisruptionBudget:
enabled: true
5 changes: 5 additions & 0 deletions deploy/crds/apps_v1alpha1_apimanager_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ spec:
type: object
imageStreamTagImportInsecure:
type: boolean
podDisruptionBudget:
properties:
enabled:
type: boolean
type: object
resourceRequirementsEnabled:
type: boolean
system:
Expand Down
11 changes: 11 additions & 0 deletions deploy/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ rules:
verbs:
- get
- create
- apiGroups:
- policy
resources:
- poddisruptionbudgets
verbs:
- get
- list
- create
- update
- watch
- delete
- apiGroups:
- apps.3scale.net
resources:
Expand Down
8 changes: 8 additions & 0 deletions doc/apimanager-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ This resource is the resource used to deploy a 3scale API Management solution.
| SystemSpec | `system` | \*SystemSpec | No | See [SystemSpec](#SystemSpec) reference | Spec of the System part |
| ZyncSpec | `zync` | \*ZyncSpec | No | See [ZyncSpec](#ZyncSpec) reference | Spec of the Zync part |
| HighAvailabilitySpec | `highAvailability` | \*HighAvailabilitySpec | No | See [HighAvailabilitySpec](#HighAvailabilitySpec) reference | Spec of the HighAvailability part |
| PodDisruptionBudgetSpec | `podDisruptionBudget` | \*PodDisruptionBudgetSpec | No | See [PodDisruptionBudgetSpec](#PodDisruptionBudgetSpec) reference | Spec of the PodDisruptionBudgetSpec part |

#### ApicastSpec

Expand Down Expand Up @@ -206,6 +207,13 @@ pre-created by the user:
with the value pointing to the desired external databases. The databases
should be configured in high-availability mode

#### PodDisruptionBudgetSpec

| **Field** | **json/yaml field**| **Type** | **Required** | **Default value** | **Description** |
| --- | --- | --- | --- | --- | --- |
| Enabled | `enabled` | bool | No | `false` | Enable to automatically create [PodDisruptionBudgets](https://kubernetes.io/docs/concepts/workloads/pods/disruptions/) for components that can scale. Not including any of the databases or redis services.|


#### APIManagerStatus

Used by the Operator/Kubernetes to control the state of the APIManager.
Expand Down
169 changes: 169 additions & 0 deletions pkg/3scale/amp/auto-generated-templates/amp/amp-ha.yml
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,63 @@ objects:
route_endpoint: https://backend-${TENANT_NAME}.${WILDCARD_DOMAIN}
service_endpoint: http://backend-listener:3000
type: Opaque
- apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
creationTimestamp: null
labels:
app: ${APP_LABEL}
threescale_component: backend
threescale_component_element: worker
name: backend-worker
spec:
maxUnavailable: 1
selector:
matchLabels:
deploymentConfig: backend-worker
status:
currentHealthy: 0
desiredHealthy: 0
disruptionsAllowed: 0
expectedPods: 0
- apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
creationTimestamp: null
labels:
app: ${APP_LABEL}
threescale_component: backend
threescale_component_element: cron
name: backend-cron
spec:
maxUnavailable: 1
selector:
matchLabels:
deploymentConfig: backend-cron
status:
currentHealthy: 0
desiredHealthy: 0
disruptionsAllowed: 0
expectedPods: 0
- apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
creationTimestamp: null
labels:
app: ${APP_LABEL}
threescale_component: backend
threescale_component_element: listener
name: backend-listener
spec:
maxUnavailable: 1
selector:
matchLabels:
deploymentConfig: backend-listener
status:
currentHealthy: 0
desiredHealthy: 0
disruptionsAllowed: 0
expectedPods: 0
- apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
Expand Down Expand Up @@ -2905,6 +2962,44 @@ objects:
stringData:
SERVERS: system-memcache:11211
type: Opaque
- apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
creationTimestamp: null
labels:
app: ${APP_LABEL}
threescale_component: system
threescale_component_element: app
name: system-app
spec:
maxUnavailable: 1
selector:
matchLabels:
deploymentConfig: system-app
status:
currentHealthy: 0
desiredHealthy: 0
disruptionsAllowed: 0
expectedPods: 0
- apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
creationTimestamp: null
labels:
app: ${APP_LABEL}
threescale_component: system
threescale_component_element: sidekiq
name: system-sidekiq
spec:
maxUnavailable: 1
selector:
matchLabels:
deploymentConfig: system-sidekiq
status:
currentHealthy: 0
desiredHealthy: 0
disruptionsAllowed: 0
expectedPods: 0
- apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
Expand Down Expand Up @@ -3344,6 +3439,42 @@ objects:
ZYNC_AUTHENTICATION_TOKEN: ${ZYNC_AUTHENTICATION_TOKEN}
ZYNC_DATABASE_PASSWORD: ${ZYNC_DATABASE_PASSWORD}
type: Opaque
- apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
creationTimestamp: null
labels:
app: ${APP_LABEL}
threescale_component: zync
name: zync
spec:
maxUnavailable: 1
selector:
matchLabels:
deploymentConfig: zync
status:
currentHealthy: 0
desiredHealthy: 0
disruptionsAllowed: 0
expectedPods: 0
- apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
creationTimestamp: null
labels:
app: ${APP_LABEL}
threescale_component: zync
name: zync-que
spec:
maxUnavailable: 1
selector:
matchLabels:
deploymentConfig: zync-que
status:
currentHealthy: 0
desiredHealthy: 0
disruptionsAllowed: 0
expectedPods: 0
- apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
Expand Down Expand Up @@ -3651,6 +3782,44 @@ objects:
app: ${APP_LABEL}
threescale_component: apicast
name: apicast-environment
- apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
creationTimestamp: null
labels:
app: ${APP_LABEL}
threescale_component: apicast
threescale_component_element: staging
name: apicast-staging
spec:
maxUnavailable: 1
selector:
matchLabels:
deploymentConfig: apicast-staging
status:
currentHealthy: 0
desiredHealthy: 0
disruptionsAllowed: 0
expectedPods: 0
- apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
creationTimestamp: null
labels:
app: ${APP_LABEL}
threescale_component: apicast
threescale_component_element: production
name: apicast-production
spec:
maxUnavailable: 1
selector:
matchLabels:
deploymentConfig: apicast-production
status:
currentHealthy: 0
desiredHealthy: 0
disruptionsAllowed: 0
expectedPods: 0
- apiVersion: v1
kind: Secret
metadata:
Expand Down
56 changes: 56 additions & 0 deletions pkg/3scale/amp/component/apicast.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package component

import (
"github.com/3scale/3scale-operator/pkg/common"
"k8s.io/api/policy/v1beta1"

appsv1 "github.com/openshift/api/apps/v1"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -34,6 +35,15 @@ func (apicast *Apicast) Objects() []common.KubernetesObject {
return objects
}

func (apicast *Apicast) PDBObjects() []common.KubernetesObject {
stagingPDB := apicast.StagingPodDisruptionBudget()
prodPDB := apicast.ProductionPodDisruptionBudget()
return []common.KubernetesObject{
stagingPDB,
prodPDB,
}
}

func (apicast *Apicast) StagingService() *v1.Service {
return &v1.Service{
TypeMeta: metav1.TypeMeta{
Expand Down Expand Up @@ -391,3 +401,49 @@ func (apicast *Apicast) EnvironmentConfigMap() *v1.ConfigMap {
},
}
}

func (apicast *Apicast) StagingPodDisruptionBudget() *v1beta1.PodDisruptionBudget {
return &v1beta1.PodDisruptionBudget{
TypeMeta: metav1.TypeMeta{
Kind: "PodDisruptionBudget",
APIVersion: "policy/v1beta1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "apicast-staging",
Labels: map[string]string{
"app": apicast.Options.appLabel,
"threescale_component": "apicast",
"threescale_component_element": "staging",
},
},
Spec: v1beta1.PodDisruptionBudgetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{"deploymentConfig": "apicast-staging"},
},
MaxUnavailable: &intstr.IntOrString{IntVal: PDB_MAX_UNAVAILABLE_POD_NUMBER},
},
}
}

func (apicast *Apicast) ProductionPodDisruptionBudget() *v1beta1.PodDisruptionBudget {
return &v1beta1.PodDisruptionBudget{
TypeMeta: metav1.TypeMeta{
Kind: "PodDisruptionBudget",
APIVersion: "policy/v1beta1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "apicast-production",
Labels: map[string]string{
"app": apicast.Options.appLabel,
"threescale_component": "apicast",
"threescale_component_element": "production",
},
},
Spec: v1beta1.PodDisruptionBudgetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{"deploymentConfig": "apicast-production"},
},
MaxUnavailable: &intstr.IntOrString{IntVal: PDB_MAX_UNAVAILABLE_POD_NUMBER},
},
}
}
Loading