Page MenuHomePhabricator

Deploying CronJob object as tool 'bd808-pywikibot' with validation fails due to API permissions
Closed, ResolvedPublic

Description

$ kubectl create --validate=true -f cronjobs.yaml
error validating "cronjobs.yaml": error validating data: forbidden: User "bd808-pywikibot" cannot get path "/swaggerapi/apis/batch/v1beta1"; if you choose to ignore these errors, turn validation off with --validate=false
cronjobs.yaml
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: archivebot
  labels:
    name: archivebot
    toolforge: tool
spec:
  schedule: "34 2 2 * *"  # 02:34 on the 2nd of each month
  jobTemplate:
    spec:
      template:
        metadata:
          labels:
            toolforge: tool
        spec:
          containers:
          - name: archivebot
            workingDir: /data/project/bd808-pywikibot
            image: docker-registry.tools.wmflabs.org/toolforge-python37-sssd-base:latest
            args:
            - /usr/bin/python3
            - /data/project/shared/pywikipedia/core/scripts/archivebot.py
            - User:BryanDavis/archivebot
            env:
            - name: PYWIKIBOT_DIR
              value: /data/project/bd808-pywikibot
            - name: HOME
              value: /data/project/bd808-pywikibot
          restartPolicy: Never
      concurrencyPolicy: Forbid
      successfulJobsHistoryLimit: 0
      failedJobsHistoryLimit: 1

Event Timeline

bd808 created this task.Feb 4 2020, 6:42 PM
Restricted Application added subscribers: Liuxinyu970226, Aklapper. · View Herald TranscriptFeb 4 2020, 6:42 PM
bd808 added a comment.Feb 4 2020, 6:58 PM

This error message seems to be the result of using /usr/local/bin/kubectl to talk to the 2020 cluster. Explicit use of /usr/bin/kubectl shows that the yaml I wrote is not quite right:

$ /usr/bin/kubectl create --validate=true -f cronjobs.yaml
error: error validating "cronjobs.yaml": error validating data: [ValidationError(CronJob.spec.jobTemplate.spec): unknown field "concurrencyPolicy" in io.k8s.api.batch.v1.JobSpec, ValidationError(CronJob.spec.jobTemplate.spec): unknown field "failedJobsHistoryLimit" in io.k8s.api.batch.v1.JobSpec, ValidationError(CronJob.spec.jobTemplate.spec): unknown field "successfulJobsHistoryLimit" in io.k8s.api.batch.v1.JobSpec]; if you choose to ignore these errors, turn validation off with --validate=false
bd808 closed this task as Resolved.Feb 4 2020, 7:02 PM
bd808 claimed this task.
$ /usr/bin/kubectl create --validate=true -f cronjobs.yaml
cronjob.batch/archivebot created

The fixes:

  • Use /usr/bin/kubectl, the shell alias in $HOME/.profile for this tool did not work as hoped
  • Actual write valid YAML for the CronJob object
cronjobs.yaml
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: archivebot
  labels:
    name: archivebot
    toolforge: tool
spec:
  schedule: "34 2 2 * *"  # 02:34 on the 2nd of each month
  concurrencyPolicy: Forbid
  successfulJobsHistoryLimit: 0
  failedJobsHistoryLimit: 1
  jobTemplate:
    spec:
      template:
        metadata:
          labels:
            toolforge: tool
        spec:
          containers:
          - name: archivebot
            workingDir: /data/project/bd808-pywikibot
            image: docker-registry.tools.wmflabs.org/toolforge-python37-sssd-base:latest
            args:
            - /usr/bin/python3
            - /data/project/shared/pywikipedia/core/scripts/archivebot.py
            - User:BryanDavis/archivebot
            env:
            - name: PYWIKIBOT_DIR
              value: /data/project/bd808-pywikibot
            - name: HOME
              value: /data/project/bd808-pywikibot
          restartPolicy: Never