Skip to content

Commit

Permalink
Merge pull request #798 from netgroup-polito/qcfe/remove-service-links
Browse files Browse the repository at this point in the history
  • Loading branch information
kingmakerbot authored Jun 30, 2022
2 parents 94642b0 + 6468ddf commit cd3bf41
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
12 changes: 12 additions & 0 deletions operators/pkg/forge/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package forge
import (
"fmt"
"strconv"
"strings"

appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
Expand Down Expand Up @@ -135,6 +136,8 @@ func PodSpec(instance *clv1alpha2.Instance, environment *clv1alpha2.Environment,
AutomountServiceAccountToken: pointer.Bool(false),
TerminationGracePeriodSeconds: pointer.Int64(containersTerminationGracePeriod),
InitContainers: InitContainers(instance, environment, opts),
EnableServiceLinks: pointer.Bool(false),
Hostname: InstanceHostname(environment),
}
return spec
}
Expand Down Expand Up @@ -455,3 +458,12 @@ func MyDriveMountPath(environment *clv1alpha2.Environment) string {

return MyDriveDefaultMountPath
}

// InstanceHostname forges the hostname of the instance:
// empty for standard mode (will use pod name) or the lowercase mode otherwise.
func InstanceHostname(environment *clv1alpha2.Environment) string {
if environment.Mode != clv1alpha2.ModeStandard {
return strings.ToLower(string(environment.Mode))
}
return ""
}
47 changes: 47 additions & 0 deletions operators/pkg/forge/containers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ var _ = Describe("Containers and Deployment spec forging", func() {
Expect(spec.AutomountServiceAccountToken).To(PointTo(BeFalse()))
})

It("Should disable service links", func() {
Expect(spec.EnableServiceLinks).To(PointTo(BeFalse()))
})

It("Should set the container hostname accordingly", func() {
Expect(spec.Hostname).To(Equal(forge.InstanceHostname(&environment)))
})

When("the environment type is Standalone", func() {
When("the environment mode is Standard", ContainersWhenBody(PodSpecContainersCase{
Mode: clv1alpha2.ModeStandard,
Expand Down Expand Up @@ -1158,4 +1166,43 @@ var _ = Describe("Containers and Deployment spec forging", func() {
}))
})

Describe("The forge.InstanceHostname function", func() {
var actual string

JustBeforeEach(func() {
actual = forge.InstanceHostname(&environment)
})

type EnvModeCase struct {
EnvMode clv1alpha2.EnvironmentMode
ExpectedOutput string
}

WhenBody := func(c EnvModeCase) func() {
return func() {
BeforeEach(func() {
environment.Mode = c.EnvMode
})

It("Should return the correct hostname", func() {
Expect(actual).To(Equal(c.ExpectedOutput))
})
}
}

When("the environment mode is Exercise", WhenBody(EnvModeCase{
EnvMode: clv1alpha2.ModeExercise,
ExpectedOutput: "exercise",
}))

When("the environment mode is Exam", WhenBody(EnvModeCase{
EnvMode: clv1alpha2.ModeExam,
ExpectedOutput: "exam",
}))

When("the environment mode is Standard", WhenBody(EnvModeCase{
EnvMode: clv1alpha2.ModeStandard,
ExpectedOutput: "",
}))
})
})

0 comments on commit cd3bf41

Please sign in to comment.