Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
Add TerminationGracePeriodSeconds to BOSH AgentSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
mudler authored and Vlad Iovanov committed Nov 9, 2020
1 parent 1b6e08a commit bdee813
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 19 deletions.
58 changes: 58 additions & 0 deletions docs/examples/bosh-deployment/quarks-gora-termination.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
name: ops-scale
data:
ops: |
- type: replace
path: /instance_groups/name=quarks-gora?/instances
value: 2
---
apiVersion: v1
kind: ConfigMap
metadata:
name: quarks-gora-manifest
data:
manifest: |
---
name: quarks-gora-deployment
releases:
- name: quarks-gora
version: "0.0.15"
url: ghcr.io/cloudfoundry-incubator
stemcell:
os: SLE_15_SP1
version: 27.10-7.0.0_374.gb8e8e6af
instance_groups:
- name: quarks-gora
instances: 1
env:
bosh:
agent:
settings:
terminationGracePeriodSeconds: 900
jobs:
- name: quarks-gora
release: quarks-gora
properties:
quarks-gora:
port: 55556
ssl: false
quarks:
ports:
- name: "quarks-gora"
protocol: "TCP"
internal: 55556
---
apiVersion: quarks.cloudfoundry.org/v1alpha1
kind: BOSHDeployment
metadata:
name: quarks-gora-deployment
spec:
manifest:
name: quarks-gora-manifest
type: configmap
ops:
- name: ops-scale
type: configmap
2 changes: 1 addition & 1 deletion e2e/kube/examples_count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ var _ = Describe("Examples Directory Files", func() {
})
Expect(err).NotTo(HaveOccurred())
// If this testcase fails that means a test case is missing for an example in the docs folder
Expect(countFile).To(Equal(33))
Expect(countFile).To(Equal(34))
})
})
35 changes: 35 additions & 0 deletions e2e/kube/terminationgraceperiod_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package kube_test

import (
"path"

cmdHelper "code.cloudfoundry.org/quarks-utils/testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("BOSHDeployment", func() {
When("specifying terminationGracePeriodSeconds in bosh.env", func() {
BeforeEach(func() {
By("Creating bdpl")
f := path.Join(examplesDir, "bosh-deployment/quarks-gora-termination.yaml")
err := cmdHelper.Create(namespace, f)
Expect(err).ToNot(HaveOccurred())

By("Checking for pods")
err = kubectl.Wait(namespace, "ready", "pod/quarks-gora-0", kubectl.PollTimeout)
Expect(err).ToNot(HaveOccurred())
err = kubectl.Wait(namespace, "ready", "pod/quarks-gora-1", kubectl.PollTimeout)
Expect(err).ToNot(HaveOccurred())
})

It("should create containers with the requested resources/limits", func() {
for _, pod := range []string{"quarks-gora-0", "quarks-gora-1"} {
requestedGrace, err := cmdHelper.GetData(namespace, "pods", pod, "jsonpath={.spec.terminationGracePeriodSeconds}")
Expect(err).ToNot(HaveOccurred())
Expect(string(requestedGrace)).To(Equal("900"))
}
})
})
})
9 changes: 5 additions & 4 deletions pkg/bosh/bpmconverter/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,11 @@ func (kc *BPMConverter) serviceToQuarksStatefulSet(
Annotations: instanceGroup.Env.AgentEnvBoshConfig.Agent.Settings.Annotations,
},
Spec: corev1.PodSpec{
Affinity: instanceGroup.Env.AgentEnvBoshConfig.Agent.Settings.Affinity,
Volumes: volumes,
InitContainers: initContainers,
Containers: containers,
TerminationGracePeriodSeconds: instanceGroup.Env.AgentEnvBoshConfig.Agent.Settings.TerminationGracePeriodSeconds,
Affinity: instanceGroup.Env.AgentEnvBoshConfig.Agent.Settings.Affinity,
Volumes: volumes,
InitContainers: initContainers,
Containers: containers,
SecurityContext: &corev1.PodSecurityContext{
FSGroup: &admGroupID,
},
Expand Down
4 changes: 3 additions & 1 deletion pkg/bosh/bpmconverter/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ var _ = Describe("BPM Converter", func() {
})

It("converts the instance group to an QuarksStatefulSet", func() {

t := int64(1000)
tolerations := []corev1.Toleration{
{
Key: "key",
Expand All @@ -196,6 +196,7 @@ var _ = Describe("BPM Converter", func() {
},
}
m.InstanceGroups[1].Env.AgentEnvBoshConfig.Agent.Settings.Tolerations = tolerations
m.InstanceGroups[1].Env.AgentEnvBoshConfig.Agent.Settings.TerminationGracePeriodSeconds = &t

activePassiveProbes := map[string]corev1.Probe{
"rep-server": corev1.Probe{
Expand Down Expand Up @@ -233,6 +234,7 @@ var _ = Describe("BPM Converter", func() {
qstsv1a1.LabelPodOrdinal: "0",
qstsv1a1.LabelActivePod: "active",
}))
Expect(stS.Spec.TerminationGracePeriodSeconds).To(Equal(&t))
})

It("converts the instance group to an QuarksStatefulSet", func() {
Expand Down
27 changes: 14 additions & 13 deletions pkg/bosh/manifest/instance_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,19 +253,20 @@ type PreRenderOps struct {
// These annotations and labels are added to kube resources.
// Affinity & tolerations are added into the pod's definition.
type AgentSettings struct {
Annotations map[string]string `json:"annotations,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
DisableLogSidecar bool `json:"disable_log_sidecar,omitempty" yaml:"disable_log_sidecar,omitempty"`
ServiceAccountName string `json:"serviceAccountName,omitempty" yaml:"serviceAccountName,omitempty"`
AutomountServiceAccountToken *bool `json:"automountServiceAccountToken,omitempty" yaml:"automountServiceAccountToken,omitempty"`
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
EphemeralAsPVC bool `json:"ephemeralAsPVC,omitempty"`
Disks Disks `json:"disks,omitempty"`
JobBackoffLimit *int32 `json:"jobBackoffLimit,omitempty"`
PreRenderOps *PreRenderOps `json:"preRenderOps,omitempty"`
InjectReplicasEnv *bool `json:"injectReplicasEnv,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
DisableLogSidecar bool `json:"disable_log_sidecar,omitempty" yaml:"disable_log_sidecar,omitempty"`
ServiceAccountName string `json:"serviceAccountName,omitempty" yaml:"serviceAccountName,omitempty"`
AutomountServiceAccountToken *bool `json:"automountServiceAccountToken,omitempty" yaml:"automountServiceAccountToken,omitempty"`
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
EphemeralAsPVC bool `json:"ephemeralAsPVC,omitempty"`
Disks Disks `json:"disks,omitempty"`
JobBackoffLimit *int32 `json:"jobBackoffLimit,omitempty"`
PreRenderOps *PreRenderOps `json:"preRenderOps,omitempty"`
InjectReplicasEnv *bool `json:"injectReplicasEnv,omitempty"`
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty" yaml:"terminationGracePeriodSeconds,omitempty"`
}

// Set overrides labels and annotations with operator-owned metadata.
Expand Down

0 comments on commit bdee813

Please sign in to comment.