Skip to content

Commit

Permalink
chore: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
twelvemo authored and vvagaytsev committed Jul 4, 2024
1 parent 4908259 commit 8d8bb8e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 47 deletions.
2 changes: 1 addition & 1 deletion core/src/plugins/kubernetes/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ export function sanitizeVolumesForPodRunner(podSpec: V1PodSpec | undefined, cont
})
// We also make sure the defaultMode of a configMap volume is an octal number.
podSpec.volumes.forEach((volume) => {
if (volume.configMap && volume.configMap.defaultMode && isOctal(volume.configMap.defaultMode.toString())) {
if (volume.configMap && volume.configMap.defaultMode && !isOctal(volume.configMap.defaultMode.toString())) {
volume.configMap!.defaultMode = parseInt(`0${volume.configMap?.defaultMode}`, 8)
}
})
Expand Down
64 changes: 18 additions & 46 deletions core/test/integ/src/plugins/kubernetes/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,13 +632,15 @@ describe("kubernetes Pod runner functions", () => {
action: helmAction,
provider: helmCtx.provider,
})
})
beforeEach(async () => {
helmTarget = await getTargetResource({
ctx: helmCtx,
log: helmLog,
provider: helmCtx.provider,
manifests: helmManifests,
action: helmAction,
query: { ...helmResourceSpec, name: helmAction.getSpec().releaseName },
query: { ...helmResourceSpec, podSelector: undefined, name: helmAction.getSpec().releaseName },
})
helmContainer = getResourceContainer(helmTarget, helmResourceSpec.containerName)
})
Expand Down Expand Up @@ -805,7 +807,7 @@ describe("kubernetes Pod runner functions", () => {
})

it("should include configMaps and secrets in the generated pod spec", async () => {
const podSpec = getResourcePodSpec(helmTarget)
const podSpecWithVolumes = getResourcePodSpec(helmTarget)
const volumes = [
{
name: "myconfigmap",
Expand All @@ -831,14 +833,14 @@ describe("kubernetes Pod runner functions", () => {
mountPath: "/secret",
},
]
podSpec!.volumes = volumes
podSpecWithVolumes!.volumes = volumes
const helmContainerWithVolumeMounts = {
...helmContainer,
volumeMounts,
}
sanitizeVolumesForPodRunner(podSpec, helmContainerWithVolumeMounts)
sanitizeVolumesForPodRunner(podSpecWithVolumes, helmContainerWithVolumeMounts)
const generatedPodSpec = await prepareRunPodSpec({
podSpec,
podSpec: podSpecWithVolumes,
getArtifacts: false,
api: helmApi,
provider: helmProvider,
Expand All @@ -858,41 +860,11 @@ describe("kubernetes Pod runner functions", () => {
// This test case is intended for `kubernetes-pod` Runs and Tests.
})

expect(pruneEmpty(generatedPodSpec)).to.eql({
volumes, // <------
containers: [
{
name: "main",
image: "foo",
imagePullPolicy: "IfNotPresent",
args: ["sh", "-c"],
ports: [
{
name: "http",
containerPort: 80,
protocol: "TCP",
},
],
resources: getResourceRequirements(resources),
env: [
{
name: "GARDEN_ACTION_VERSION",
value: helmAction.versionString(),
},
{
name: "GARDEN_MODULE_VERSION",
value: helmAction.versionString(),
},
],
volumeMounts, // <------
command: ["echo", "foo"],
},
],
imagePullSecrets: [],
})
expect(generatedPodSpec.volumes).to.eql(volumes)
expect(generatedPodSpec.containers[0].volumeMounts).to.eql(volumeMounts)
})
it("should not include persistentVolumes in the generated pod spec", async () => {
const podSpec = getResourcePodSpec(helmTarget)
const podSpecWithPersistentVolume = getResourcePodSpec(helmTarget)
const volumes: V1Volume[] = [
{
name: "myvolume",
Expand All @@ -907,14 +879,14 @@ describe("kubernetes Pod runner functions", () => {
mountPath: "/data",
},
]
podSpec!.volumes = volumes
podSpecWithPersistentVolume!.volumes = volumes
const helmContainerWithVolumeMounts = {
...helmContainer,
volumeMounts,
}
sanitizeVolumesForPodRunner(podSpec, helmContainerWithVolumeMounts)
sanitizeVolumesForPodRunner(podSpecWithPersistentVolume, helmContainerWithVolumeMounts)
const generatedPodSpec = await prepareRunPodSpec({
podSpec: undefined,
podSpec: podSpecWithPersistentVolume,
getArtifacts: false,
api: helmApi,
provider: helmProvider,
Expand All @@ -937,7 +909,7 @@ describe("kubernetes Pod runner functions", () => {
expect(generatedPodSpec.containers[0].volumeMounts).to.eql([])
})
it("should make sure configMap file permissions are in octal", async () => {
const podSpec = getResourcePodSpec(helmTarget)
const podSpecWithConfigMap = getResourcePodSpec(helmTarget)
const volumes = [
{
name: "myconfigmap",
Expand All @@ -953,14 +925,14 @@ describe("kubernetes Pod runner functions", () => {
mountPath: "/config",
},
]
podSpec!.volumes = volumes
podSpecWithConfigMap!.volumes = volumes
const helmContainerWithVolumeMounts = {
...helmContainer,
volumeMounts,
}
sanitizeVolumesForPodRunner(podSpec, helmContainerWithVolumeMounts)
sanitizeVolumesForPodRunner(podSpecWithConfigMap, helmContainerWithVolumeMounts)
const generatedPodSpec = await prepareRunPodSpec({
podSpec,
podSpec: podSpecWithConfigMap,
getArtifacts: false,
api: helmApi,
provider: helmProvider,
Expand All @@ -979,7 +951,7 @@ describe("kubernetes Pod runner functions", () => {
// Note: We're not passing the `volumes` param here, since that's for `container` Runs/Tests.
// This test case is intended for `kubernetes-pod` Runs and Tests.
})
expect(generatedPodSpec.volumes![0].configMap?.defaultMode).to.eql(0o755)
expect(generatedPodSpec.volumes![0].configMap?.defaultMode).to.eql(493)
})
it("should apply security context fields to the main container when provided", async () => {
const generatedPodSpec = await prepareRunPodSpec({
Expand Down

0 comments on commit 8d8bb8e

Please sign in to comment.