Hello! I’m trying to use Pulumi to run a K8S batch...
# kubernetes
g
Hello! I’m trying to use Pulumi to run a K8S batch job in a cluster created on Scaleway. The cluster was created successfully, however I am unable to set the ‘completionMode’ field in the job spec. I want to set this to ‘Indexed’, so that I can make use of parallelism to run several jobs in parallel, with each job reading the JOB_COMPLETION_INDEX environment variable to determine which instance it is. When I try setting ‘completionMode’, Pulumi gives an error message stating that this field is immutable. Any advice would be greatly appreciated! The code I’m using to create the job is as follows:
Copy code
const k8sEnvironmentVariables: EnvVar[] = [
    {
        name: "ENV_AWS",
        value: stack,
    },
    {
        name: "PRIMARY_MONGODB_URI",
        value: mongoDbUri,
    },
];

const createJob = (name: string, env: EnvVar[], arraySize: number = 1, commandArgs: string[] = []): k8s.batch.v1.Job => {
    const jobName = `${camelToKebabCase((name))}-job`;

    return new k8s.batch.v1.Job(jobName, {
        metadata: {
            name: jobName,
        },
        spec: {
            parallelism: arraySize,
            completionMode: "Indexed",
            template: {
                spec: {
                    containers: [
                        {
                            name: "batch-job",
                            image: image.imageName,
                            command: ["/bin/sh", `/usr/local/bin/hkracing-batch${name}.sh`].concat(commandArgs),
                            env: env.concat([
                                {
                                    name: "BATCH_JOB_ARRAY_SIZE",
                                    value: arraySize.toString(),
                                },
                            ]),
                        },
                    ],
                    restartPolicy: "Never",
                },
            },
        },
    }, {provider: k8sProvider, dependsOn: [cluster, nodePool]});
}

const createFeatureBuildJob = (): k8s.batch.v1.Job => {
    return createJob("FeatureBuild",
        k8sEnvironmentVariables.concat(
            {
                name: "ST_TURF_MODEL_ID",
                value: "5fdb6e19b1cede6138bb3437",
            },
            {
                name: "LOCAL_MONGODB_URI",
                value: "<mongodb://localhost/hkr>"
            },
        ),
        10, [
            "20150901",
            "20240428",
            "5fdb67e7321e254e58378340",
            "RunFeature",
        ]);
};

const featureBuildJob = createFeatureBuildJob();
m
Can you share the precise error message you see? Is this a message by Pulumi, the Kubernetes provider, or Kubernetes itself? An observations at first glance: You don't specify the "completions" field which, according to the docs, has to be specified when setting "completionMode" to "Indexed"
g
Thanks, Kilian! I tried adding the “completions” field, but when I updated the stack it returned a similar error about that field also being immutable. Finally got it working by doing a “pulumi down” followed by “pulumi up” again.