Skip to content

Commit

Permalink
Minified environment overrides now only contain replicas for services. (
Browse files Browse the repository at this point in the history
  • Loading branch information
ezodude authored Jul 9, 2021
1 parent 866164b commit fc52e71
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 34 deletions.
15 changes: 15 additions & 0 deletions pkg/kev/config/minify.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,28 @@

package config

import (
"reflect"
)

// MinifySvcK8sExtension creates a minimal service extension configuration using the supplied src.
func MinifySvcK8sExtension(src map[string]interface{}) (map[string]interface{}, error) {
srcCfg, err := ParseSvcK8sConfigFromMap(src)
if err != nil {
return nil, err
}

isDefaultLivenessProbe := srcCfg.Workload.LivenessProbe.Type == ProbeTypeExec.String() &&
reflect.DeepEqual(srcCfg.Workload.LivenessProbe.Exec.Command, DefaultLivenessProbeCommand)

if isDefaultLivenessProbe {
return SvcK8sConfig{
Workload: Workload{
Replicas: srcCfg.Workload.Replicas,
},
}.Map()
}

var probeConfig ProbeConfig
switch srcCfg.Workload.LivenessProbe.Type {
case ProbeTypeExec.String():
Expand Down
2 changes: 1 addition & 1 deletion pkg/kev/config/svcext.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ type Workload struct {
ServiceAccountName string `yaml:"serviceAccountName,omitempty" validate:"subdomainIfAny"`
RollingUpdateMaxSurge int `yaml:"rollingUpdateMaxSurge,omitempty" validate:""`
Annotations map[string]string `yaml:"annotations,omitempty"`
LivenessProbe LivenessProbe `yaml:"livenessProbe" validate:"required"`
LivenessProbe LivenessProbe `yaml:"livenessProbe,omitempty"`
ReadinessProbe ReadinessProbe `yaml:"readinessProbe,omitempty"`
RestartPolicy RestartPolicy `yaml:"restartPolicy,omitempty" validate:"restartPolicy"`
ImagePull ImagePull `yaml:"imagePull,omitempty"`
Expand Down
9 changes: 0 additions & 9 deletions pkg/kev/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,6 @@ var _ = Describe("InitRunner", func() {

svcK8sConfig, err := config.ParseSvcK8sConfigFromMap(svc.Extensions, config.SkipValidation())
Expect(err).NotTo(HaveOccurred())

Expect(svcK8sConfig.Workload.LivenessProbe).To(Equal(config.LivenessProbe{
Type: config.ProbeTypeExec.String(),
ProbeConfig: config.ProbeConfig{
Exec: config.ExecProbe{
Command: config.DefaultLivenessProbeCommand,
},
},
}))
Expect(svcK8sConfig.Workload.Replicas).NotTo(BeZero())
})
})
Expand Down
27 changes: 15 additions & 12 deletions pkg/kev/kev_reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ var _ = Describe("Reconcile", func() {
})

It("should configure the added service extension value defaults in all environments", func() {
expected, err := newMinifiedServiceExtensions("wordpress")
expected, err := newMinifiedServiceExtensions("wordpress", false)
Expect(err).NotTo(HaveOccurred())

envs, err := manifest.GetEnvironments([]string{"dev", "stage"})
Expand Down Expand Up @@ -302,7 +302,7 @@ var _ = Describe("Reconcile", func() {
})

It("should configure parse config into extensions", func() {
expected, err := newMinifiedServiceExtensions("wordpress", config.SvcK8sConfig{
expected, err := newMinifiedServiceExtensions("wordpress", false, config.SvcK8sConfig{
Workload: config.Workload{
Replicas: 3,
},
Expand All @@ -323,7 +323,7 @@ var _ = Describe("Reconcile", func() {
})

It("should configure the added service extensions from healthcheck config", func() {
expected, err := newMinifiedServiceExtensions("wordpress")
expected, err := newMinifiedServiceExtensions("wordpress", true)
Expect(err).NotTo(HaveOccurred())
expected["x-k8s"].(map[string]interface{})["workload"].(map[string]interface{})["livenessProbe"] = map[string]interface{}{
"type": config.ProbeTypeNone.String(),
Expand Down Expand Up @@ -562,22 +562,25 @@ var _ = Describe("Reconcile", func() {
})
})

func newMinifiedServiceExtensions(_ string, svcK8sConfigs ...config.SvcK8sConfig) (map[string]interface{}, error) {
func newMinifiedServiceExtensions(_ string, includeLivenessProbe bool, svcK8sConfigs ...config.SvcK8sConfig) (map[string]interface{}, error) {
livenessProbe := config.DefaultLivenessProbe()
k8s := config.SvcK8sConfig{
Workload: config.Workload{
LivenessProbe: config.LivenessProbe{
Type: livenessProbe.Type,
ProbeConfig: config.ProbeConfig{
Exec: config.ExecProbe{
Command: livenessProbe.Exec.Command,
},
},
},
Replicas: config.DefaultReplicaNumber,
},
}

if includeLivenessProbe {
k8s.Workload.LivenessProbe = config.LivenessProbe{
Type: livenessProbe.Type,
ProbeConfig: config.ProbeConfig{
Exec: config.ExecProbe{
Command: livenessProbe.Exec.Command,
},
},
}
}

for _, conf := range svcK8sConfigs {
c, err := k8s.Merge(conf)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ services:
db:
x-k8s:
workload:
livenessProbe:
exec:
command:
- echo
- Define healthcheck command for service
type: exec
replicas: 10
volumes:
db_data:
Expand Down
6 changes: 0 additions & 6 deletions pkg/kev/testdata/init-default/compose-yaml/output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ services:
db:
x-k8s:
workload:
livenessProbe:
exec:
command:
- echo
- Define healthcheck command for service
type: exec
replicas: 1
volumes:
db_data:
Expand Down

0 comments on commit fc52e71

Please sign in to comment.