Linkerd2: "linkerd inject" does not work on cronjobs?

Created on 23 Oct 2019  ยท  4Comments  ยท  Source: linkerd/linkerd2

Bug Report

What is the issue?

Trying to use linkerd inject to annotate a cronjob yaml and it returns "!! no supported object found"

How can it be reproduced?

Create a cronjob yaml, apply it, then:

kubectl get cronjobs.batch mssql-backup -o yaml | linkerd inject -

Logs, error output, etc

(apologies for the debugging code in the sample)

$ kubectl get cronjobs.batch mssql-backup -o yaml | linkerd inject  -
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"batch/v1beta1","kind":"CronJob","metadata":{"annotations":{},"name":"mssql-backup","namespace":"se"},"spec":{"concurrencyPolicy":"Forbid","failedJobsHistoryLimit":1,"jobTemplate":{"spec":{"template":{"spec":{"containers":[{"args":["echo \"hello world\"; /opt/mssql-tools/bin/sqlcmd -S server -U sa -P password -I -Q \"EXEC sp_msForEachDB 'PRINT ''?'' ';\" | while read dbname; do echo \"*** Backing up $dbname ***\"; /opt/mssql-tools/bin/sqlcmd -S server -U sa -P password -I -Q \"BACKUP DATABASE master TO DISK='/mssql-backup/backup/$dbname/$dbname-$(date +%Y-%m-%d.%s).bak' WITH STATS, COMPRESSION;\" ; done; echo \"*** End of $dbname backup ***\"; echo \"\"; sleep 60; echo \" *** NORMAL TERMINATION *** \";"],"command":["bash","-c"],"image":"microsoft/mssql-tools","name":"mssql-backup"}],"nodeSelector":{"kubernetes.io/os":"linux"},"restartPolicy":"Never","securityContext":{"fsGroup":0,"runAsUser":0}}}}},"schedule":"*/5 * * * *","successfulJobsHistoryLimit":3}}
  creationTimestamp: "2019-10-23T20:03:48Z"
  name: mssql-backup
  namespace: se
  resourceVersion: "2061027"
  selfLink: /apis/batch/v1beta1/namespaces/se/cronjobs/mssql-backup
  uid: 399f4b60-f5d0-11e9-a92d-72a7270cd27e
spec:
  concurrencyPolicy: Forbid
  failedJobsHistoryLimit: 1
  jobTemplate:
    metadata:
      creationTimestamp: null
    spec:
      template:
        metadata:
          creationTimestamp: null
        spec:
          containers:
          - args:
            - echo "hello world"; /opt/mssql-tools/bin/sqlcmd -S server
              -U sa -P password -I -Q "EXEC sp_msForEachDB
              'PRINT ''?'' ';" | while read dbname; do echo "*** Backing up $dbname
              ***"; /opt/mssql-tools/bin/sqlcmd -S server -U sa -P password
              -I -Q "BACKUP DATABASE master TO DISK='/mssql-backup/backup/$dbname/$dbname-$(date
              +%Y-%m-%d.%s).bak' WITH STATS, COMPRESSION;" ; done; echo "*** End of
              $dbname backup ***"; echo ""; sleep 60; echo " *** NORMAL TERMINATION
              *** ";
            command:
            - bash
            - -c
            image: microsoft/mssql-tools
            imagePullPolicy: Always
            name: mssql-backup
            resources: {}
            terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
          dnsPolicy: ClusterFirst
          nodeSelector:
            kubernetes.io/os: linux
          restartPolicy: Never
          schedulerName: default-scheduler
          securityContext:
            fsGroup: 0
            runAsUser: 0
          terminationGracePeriodSeconds: 30
  schedule: '*/5 * * * *'
  successfulJobsHistoryLimit: 3
  suspend: false
status:
  active:
  - apiVersion: batch/v1
    kind: Job
    name: mssql-backup-1571861700
    namespace: se
    resourceVersion: "2061025"
    uid: f8bae702-f5d1-11e9-a92d-72a7270cd27e
  lastScheduleTime: "2019-10-23T20:15:00Z"
---

โ€ผ no supported objects found

cronjob "mssql-backup" skipped

linkerd check output

```$ linkerd check

kubernetes-api

โˆš can initialize the client
โˆš can query the Kubernetes API

kubernetes-version

โˆš is running the minimum Kubernetes API version
โˆš is running the minimum kubectl version

linkerd-config

โˆš control plane Namespace exists
โˆš control plane ClusterRoles exist
โˆš control plane ClusterRoleBindings exist
โˆš control plane ServiceAccounts exist
โˆš control plane CustomResourceDefinitions exist
โˆš control plane MutatingWebhookConfigurations exist
โˆš control plane ValidatingWebhookConfigurations exist
โˆš control plane PodSecurityPolicies exist

linkerd-existence

โˆš 'linkerd-config' config map exists
โˆš heartbeat ServiceAccount exist
โˆš control plane replica sets are ready
โˆš no unschedulable pods
โˆš controller pod is running
โˆš can initialize the client
โˆš can query the control plane API

linkerd-api

โˆš control plane pods are ready
โˆš control plane self-check
โˆš [kubernetes] control plane can talk to Kubernetes
โˆš [prometheus] control plane can talk to Prometheus
โˆš no invalid service profiles

linkerd-version

โˆš can determine the latest version
โˆš cli is up-to-date

control-plane-version

โˆš control plane is up-to-date
โˆš control plane and cli versions match

Status check results are โˆš

$ linkerd version
Client version: stable-2.6.0
Server version: stable-2.6.0
```

Environment

  • Kubernetes Version: 1.14.6
  • Cluster Environment: AKS
  • Host OS: AKS Linux (Ubuntu?)
  • Linkerd version: 2.6-stable

Possible solution

Additional context

This is actually to add the annotation to end up "disable"ing the auto-proxy-inject until we figure out how to ask the sidecar to exit when the main container is done.

arecli good first issue help wanted

All 4 comments

As of now, linkerd inject does not support configs of Kind Cronjob.

As per the cases listed under method conf.getFreshWorkloadObj() (at pkg/inject/inject.go), nil is returned while trying to parse a config of type Cronjob.
Neither is method conf.parse() setup to process a config of this kind.

Once we have that, such a config can be unmarshalled to *ResourceConfig, have the annotations appended and marshalled back to yaml.

This would however be a cool feature to have.
@grampelberg @ihcsim WDYT?

This feature is very similar to https://github.com/linkerd/linkerd2/pull/3607

@mayankshah1607 go for it!

Hi guys,

Do you mind if I take care of this one? I was doing it as part of #3614

cc @scottcarol

@tegioz Sure, go ahead! :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ihcsim picture ihcsim  ยท  4Comments

steve-fraser picture steve-fraser  ยท  4Comments

tustvold picture tustvold  ยท  4Comments

briansmith picture briansmith  ยท  4Comments

alpeb picture alpeb  ยท  3Comments