diff --git a/docs/examples/bosh-deployment/quarks-gora-termination.yaml b/docs/examples/bosh-deployment/quarks-gora-termination.yaml new file mode 100644 index 000000000..ad9b5d22d --- /dev/null +++ b/docs/examples/bosh-deployment/quarks-gora-termination.yaml @@ -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 diff --git a/e2e/kube/examples_count_test.go b/e2e/kube/examples_count_test.go index 165ebf569..5f56ef03d 100644 --- a/e2e/kube/examples_count_test.go +++ b/e2e/kube/examples_count_test.go @@ -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)) }) }) diff --git a/e2e/kube/terminationgraceperiod_test.go b/e2e/kube/terminationgraceperiod_test.go new file mode 100644 index 000000000..5d99d8972 --- /dev/null +++ b/e2e/kube/terminationgraceperiod_test.go @@ -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")) + } + }) + }) +}) diff --git a/pkg/bosh/bpmconverter/resources.go b/pkg/bosh/bpmconverter/resources.go index 2e48d0ee1..a2416874d 100644 --- a/pkg/bosh/bpmconverter/resources.go +++ b/pkg/bosh/bpmconverter/resources.go @@ -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, }, diff --git a/pkg/bosh/bpmconverter/resources_test.go b/pkg/bosh/bpmconverter/resources_test.go index e06db7fac..374e374b4 100644 --- a/pkg/bosh/bpmconverter/resources_test.go +++ b/pkg/bosh/bpmconverter/resources_test.go @@ -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", @@ -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{ @@ -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() { diff --git a/pkg/bosh/manifest/instance_group.go b/pkg/bosh/manifest/instance_group.go index ef395496e..374f318bd 100644 --- a/pkg/bosh/manifest/instance_group.go +++ b/pkg/bosh/manifest/instance_group.go @@ -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.