website logo
HomeGithubSlack
⌘K
Overview
Quick Start
Supported Services
Running CloudGraph in EKS
Compliance
Rules Engine
AWS
Querying AWS Data
AWS Policy Packs
Billing Data
Services
Azure
Querying Azure Data
Azure Policy Packs
Services
GCP
Querying GCP Data
GCP Policy Packs
Services
K8s
Querying Kubernetes Data
Services
Docs powered by archbee 
15min

CronJob

Note: if you are running CloudGraph locally you can view the interactive, automatically generated documentation in either GraphQL Playground or Altair by clicking the docs button on the right-hand side of the screen. After reading the below information we highly suggest you use one of these tools to test your queries as they will autocomplete fields for you and let you know if your queries are valid before you even submit them.

Overview

You can currently query the following attributes and connections on a k8s CronJob:

GraphQL
|
type k8sCronJob {
  id: String
  context: String
  apiVersion: String
  kind: String
  metadata {
    id: String
    annotations: {
      id: String!
      key: String
      value: String
    }
    clusterName: String
    creationTimestamp: String
    deletionGracePeriodSeconds: Int
    deletionTimestamp: String
    finalizers: [String]
    generateName: String
    generation: Int
    labels: {
      id: String!
      key: String
      value: String
    }
    ownerReferences: {
      id: String!
      apiVersion: String
      blockOwnerDeletion: Boolean
      controller: Boolean
      kind: String
      name: String
    }
    name: String
    namespace: String
    resourceVersion: String
    selfLink: String
  }
  spec {
    concurrencyPolicy: String
    failedJobsHistoryLimit: Int
    jobTemplate {
      metadata {
        id: String
        annotations {
          id: String!
          key: String
          value: String
        }
        clusterName: String
        creationTimestamp: String
        deletionGracePeriodSeconds: Int
        deletionTimestamp: String
        finalizers: [String]
        generateName: String
        generation: Int
        labels{
          id: String!
          key: String
          value: String
        }
        ownerReferences {
          id: String!
          apiVersion: String
          blockOwnerDeletion: Boolean
          controller: Boolean
          kind: String
          name: String
        }
        name: String
        namespace: String
        resourceVersion: String
        selfLink: String
      }
      spec {
        activeDeadlineSeconds: Int
        backoffLimit: Int
        completionMode: String
        completions: Int
        manualSelector: Boolean
        parallelism: Int
        selector {
          matchExpressions {
            id: String!
            key: String
            operator: String
            values: [String]
          }
          matchLabels {
            id: String!
            key: String
            value: String
          }
        }
        suspend: Boolean
        template {
          metadata {
            id: String
            annotations {
              id: String!
              key: String
              value: String
            }
            clusterName: String
            creationTimestamp: String
            deletionGracePeriodSeconds: Int
            deletionTimestamp: String
            finalizers: [String]
            generateName: String
            generation: Int
            labels{
              id: String!
              key: String
              value: String
            }
            ownerReferences {
              id: String!
              apiVersion: String
              blockOwnerDeletion: Boolean
              controller: Boolean
              kind: String
              name: String
            }
            name: String
            namespace: String
            resourceVersion: String
            selfLink: String
          }
          spec {
            activeDeadlineSeconds: Int
            affinity {
              nodeAffinity {
                requiredDuringSchedulingIgnoredDuringExecution {
                  nodeSelectorTerms {
                    id: String!
                    matchExpressions {
                      id: String!
                      key: String
                      operator: String
                      values: [String]
                    }
                    matchFields {
                      id: String!
                      key: String
                      operator: String
                      values: [String]
                    }
                  }
                }
                preferredDuringSchedulingIgnoredDuringExecution {
                  id: String!
                  weight: Int
                  preference {
                    id: String!
                    labelSelector {
                      matchExpressions {
                        id: String!
                        key: String
                        operator: String
                        values: [String]
                      }
                      matchLabels {
                        id: String!
                        key: String
                        value: String
                      }
                    }
                    namespaceSelector {
                      matchExpressions {
                        id: String!
                        key: String
                        operator: String
                        values: [String]
                      }
                      matchLabels {
                        id: String!
                        key: String
                        value: String
                      }
                    }
                    namespaces: [String]
                    topologyKey: String
                  }
                  podAffinityTerm {
                    id: String!
                    labelSelector {
                      matchExpressions {
                        id: String!
                        key: String
                        operator: String
                        values: [String]
                      }
                      matchLabels {
                        id: String!
                        key: String
                        value: String
                      }
                    }
                    namespaceSelector {
                      matchExpressions {
                        id: String!
                        key: String
                        operator: String
                        values: [String]
                      }
                      matchLabels {
                        id: String!
                        key: String
                        value: String
                      }
                    }
                    namespaces: [String]
                    topologyKey: String
                  }
                }
              }
              podAffinity {
                requiredDuringSchedulingIgnoredDuringExecution {
                  id: String!
                  labelSelector {
                    matchExpressions {
                      id: String!
                      key: String
                      operator: String
                      values: [String]
                    }
                    matchLabels {
                      id: String!
                      key: String
                      value: String
                    }
                  }
                  namespaceSelector {
                    matchExpressions {
                      id: String!
                      key: String
                      operator: String
                      values: [String]
                    }
                    matchLabels {
                      id: String
                      key: String
                      value: String
                    }
                  }
                  namespaces: [String]
                  topologyKey: String
                }
                preferredDuringSchedulingIgnoredDuringExecution {
                  id: String!
                  weight: Int
                  preference {
                    id: String!
                    labelSelector {
                      matchExpressions {
                        id: String!
                        key: String
                        operator: String
                        values: [String]
                      }
                      matchLabels {
                        id: String
                        key: String
                        value: String
                      }
                    }
                    namespaceSelector {
                      matchExpressions {
                        id: String!
                        key: String
                        operator: String
                        values: [String]
                      }
                      matchLabels {
                        id: String
                        key: String
                        value: String
                      }
                    }
                    namespaces: [String]
                    topologyKey: String
                  }
                  podAffinityTerm {
                    id: String!
                    labelSelector {
                      matchExpressions {
                        id: String!
                        key: String
                        operator: String
                        values: [String]
                      }
                      matchLabels {
                        id: String
                        key: String
                        value: String
                      }
                    }
                    namespaceSelector {
                      matchExpressions {
                        id: String!
                        key: String
                        operator: String
                        values: [String]
                      }
                      matchLabels {
                        id: String
                        key: String
                        value: String
                      }
                    }
                    namespaces: [String]
                    topologyKey: String
                  }
                }
              }
              podAntiAffinity {
                requiredDuringSchedulingIgnoredDuringExecution {
                  id: String!
                  labelSelector {
                    matchExpressions {
                      id: String!
                      key: String
                      operator: String
                      values: [String]
                    }
                    matchLabels {
                      id: String!
                      key: String
                      value: String
                    }
                  }
                  namespaceSelector {
                    matchExpressions {
                      id: String!
                      key: String
                      operator: String
                      values: [String]
                    }
                    matchLabels {
                      id: String
                      key: String
                      value: String
                    }
                  }
                  namespaces: [String]
                  topologyKey: String
                }
                preferredDuringSchedulingIgnoredDuringExecution {
                  id: String!
                  weight: Int
                  preference {
                    id: String!
                    labelSelector {
                      matchExpressions {
                        id: String!
                        key: String
                        operator: String
                        values: [String]
                      }
                      matchLabels {
                        id: String
                        key: String
                        value: String
                      }
                    }
                    namespaceSelector {
                      matchExpressions {
                        id: String!
                        key: String
                        operator: String
                        values: [String]
                      }
                      matchLabels {
                        id: String
                        key: String
                        value: String
                      }
                    }
                    namespaces: [String]
                    topologyKey: String
                  }
                  podAffinityTerm {
                    id: String!
                    labelSelector {
                      matchExpressions {
                        id: String!
                        key: String
                        operator: String
                        values: [String]
                      }
                      matchLabels {
                        id: String
                        key: String
                        value: String
                      }
                    }
                    namespaceSelector {
                      matchExpressions {
                        id: String!
                        key: String
                        operator: String
                        values: [String]
                      }
                      matchLabels {
                        id: String
                        key: String
                        value: String
                      }
                    }
                    namespaces: [String]
                    topologyKey: String
                  }
                }     
              }
            }
            automountServiceAccountToken: Boolean
            dnsPolicy: String
            enableServiceLinks: Boolean
            hostIpc: Boolean
            hostNetwork: Boolean
            hostPid: Boolean
            hostname: String
            nodeName: String
            preemptionPolicy: String
            priority: Int
            priorityClassName: String
            restartPolicy: String
            runtimeClassName: String
            schedulerName: String
            serviceAccount: String
            serviceAccountName: String
            setHostnameAsFqdn: Boolean
            shareProcessNamespace: Boolean
            subdomain: String
            terminationGracePeriodSeconds: Int
          }
        }
        ttlSecondsAfterFinished: Int
      }
    }
    schedule: String
    startingDeadlineSeconds: Int
    successfulJobsHistoryLimit: Int
    suspend: Boolean
  }
  status {
    lastScheduleTime: String
    lastSuccessfulTime: String
    active {
      id: String!
      apiVersion: String
      fieldPath: String
      kind: String
      name: String
      namespace: String
      resourceVersion: String
    }
  }
  namespace {
    id: String!
    # other namespace fields
  }
}


Filtering

Get data for a single cronJob that you know the id for:

GraphQL
|
query {
  getk8sCronJob(id: "12345") {
    id
    # Other fields and connections here...
  }
}


Get data for all of the cronJobs in a certain k8s Context:

GraphQL
|
query {
  queryk8sCronJob(filter: { context: { eq: "my-context-name" } }) {
    id
    # Other fields and connections here...
  }
}


Get data for all of the cronJobs NOT in a certain k8s Context:

GraphQL
|
query {
  queryk8sCronJob(filter: { not: { context: { eq: "my-context-name" } } }) {
    id
    # Other fields and connections here...
  }
}




Advanced Filtering

Get data for all of the cronJobs that have a namespace:

GraphQL
|
query {
  queryk8sCronJob(filter: { has: namespace }) {
    id
    # Other fields and connections here...
  }
}

# Note that in addition to "namespace" you can filter
# Using "has" based on any of the following attributes:

# context
# apiVersion
# kind
# metadata
# spec
# status


Use multiple filter selectors, (i.e. has, and, not, or) to get data for all of the cronJobs that have a namespace AND status OR that do not have a spec. Note that you can use has, and, not, or completely independently of each other:

GraphQL
|
query {
  queryk8sCronJob(
    filter: {
      has: namespace
      and: { has: status }
      or: { not: { has: spec } }
    }
  ) {
    id
    # Other fields and connections here...
  }
}


You may also filter using a regex when filtering on a string field like, context if you want to look for a value that matches say, some-value (case insensitive):

GraphQL
|
query {
  queryk8sCronJob(
    filter: { context: { regexp: "/.*some-value*./i" } }
  ) {
    id
    # Other fields and connections here...
  }
}


Ordering

You can order the results you get back either asc or desc depending on your preference:

GraphQL
|
query {
  queryk8sCronJob(order: { desc: apiVersion }) {
    apiVersion
    # Other fields and connections here...
  }
}

# Note that in addition to "apiVersion" you can filter
# Using "asc" or "desc" based on any of the following attributes:

# id
# kind
# context


Only select and return the first two cronJobs that are found:

GraphQL
|
query {
  queryk8sCronJob(first: 2, order: { desc: apiVersion }) {
    apiVersion
    # Other fields and connections here...
  }
}


Only select and return the first two cronJobs that are found, but offset by one so cronJobs two & three are returned:

GraphQL
|
query {
  queryk8sCronJob(first: 2, order: { desc: apiVersion }, offset: 1) {
    apiVersion
    # Other fields and connections here...
  }
}


Aggregation

Count the number of cronJobs across all scanned K8s contexts:

GraphQL
|
query {
  aggregatek8sCronJob {
    count
    # Other fields and connections here...
  }
}

# Note that in addition to "count" you can request the
# Following min and max values based on attributes of your Namespaces:

# idMin
# idMax
# contextMin
# contextMax
# kindMin
# kindMax
# apiVersionMin
# apiVersionMax


Count the number of cronJobs in a single context. Note that you can apply all of the same filters that are listed above to aggregate queries:

GraphQL
|
query {
  aggregatek8sCronJob(filter: { context: { eq: "my-context-name" } }) {
    count
    # Other fields and connections here...
  }
}


Kitchen Sink

Putting it all together; get all data for all cronJobs across all k8s contexts in a single query. For the purposes of this example we will only get direct children of the service but if you want to it's easy to go from say, cronJob -> namespace -> service ...etc:

GraphQL
|
query {
  queryk8sCronJob {
    id
    context
    apiVersion
    kind
    metadata {
      id
      annotations {
        id
        key
        value
      }
      clusterName
      creationTimestamp
      deletionGracePeriodSeconds
      deletionTimestamp
      finalizers
      generateName
      generation
      labels{
        id
        key
        value
      }
      ownerReferences {
        id
        apiVersion
        blockOwnerDeletion
        controller
        kind
        name
      }
      name
      namespace
      resourceVersion
      selfLink
    }
    spec {
      concurrencyPolicy
      failedJobsHistoryLimit
      jobTemplate {
        metadata {
          id
          annotations {
            id
            key
            value
          }
          clusterName
          creationTimestamp
          deletionGracePeriodSeconds
          deletionTimestamp
          finalizers
          generateName
          generation
          labels{
            id
            key
            value
          }
          ownerReferences {
            id
            apiVersion
            blockOwnerDeletion
            controller
            kind
            name
          }
          name
          namespace
          resourceVersion
          selfLink
        } 
        spec {
          activeDeadlineSeconds
          backoffLimit
          completionMode
          completions
          manualSelector
          parallelism
          selector {
            matchExpressions {
              id
              key
              operator
              values
            }
            matchLabels {
              id
              key
              value
            }
          }
          suspend
          template {
            metadata {
              id
              annotations {
                id
                key
                value
              }
              clusterName
              creationTimestamp
              deletionGracePeriodSeconds
              deletionTimestamp
              finalizers
              generateName
              generation
              labels{
                id
                key
                value
              }
              ownerReferences {
                id
                apiVersion
                blockOwnerDeletion
                controller
                kind
                name
              }
              name
              namespace
              resourceVersion
              selfLink
            }
            spec {
              activeDeadlineSeconds
              affinity {
                nodeAffinity {
                  requiredDuringSchedulingIgnoredDuringExecution {
                    nodeSelectorTerms {
                      id
                      matchExpressions {
                        id
                        key
                        operator
                        values
                      }
                      matchFields {
                        id
                        key
                        operator
                        values
                      }
                    }
                  }
                  preferredDuringSchedulingIgnoredDuringExecution {
                    id
                    weight
                    preference {
                      id
                      labelSelector {
                        matchExpressions {
                          id
                          key
                          operator
                          values
                        }
                        matchLabels {
                          id
                          key
                          value
                        }
                      }
                      namespaceSelector {
                        matchExpressions {
                          id
                          key
                          operator
                          values
                        }
                        matchLabels {
                          id
                          key
                          value
                        }
                      }
                      namespaces
                      topologyKey
                    }
                    podAffinityTerm {
                      id
                      labelSelector {
                        matchExpressions {
                          id
                          key
                          operator
                          values
                        }
                        matchLabels {
                          id
                          key
                          value
                        }
                      }
                      namespaceSelector {
                        matchExpressions {
                          id
                          key
                          operator
                          values
                        }
                        matchLabels {
                          id
                          key
                          value
                        }
                      }
                      namespaces
                      topologyKey
                    }
                  }
                }
                podAffinity {
                  requiredDuringSchedulingIgnoredDuringExecution {
                    id
                    labelSelector {
                        matchExpressions {
                          id
                          key
                          operator
                          values
                        }
                        matchLabels {
                          id
                          key
                          value
                        }
                      }
                      namespaceSelector {
                        matchExpressions {
                          id
                          key
                          operator
                          values
                        }
                        matchLabels {
                          id
                          key
                          value
                        }
                      }
                    namespaces
                    topologyKey
                  }
                  preferredDuringSchedulingIgnoredDuringExecution {
                    id
                    weight
                    preference {
                      id
                      labelSelector {
                        matchExpressions {
                          id
                          key
                          operator
                          values
                        }
                        matchLabels {
                          id
                          key
                          value
                        }
                      }
                      namespaceSelector {
                        matchExpressions {
                          id
                          key
                          operator
                          values
                        }
                        matchLabels {
                          id
                          key
                          value
                        }
                      }
                      namespaces
                      topologyKey
                    }
                    podAffinityTerm {
                      id
                      labelSelector {
                        matchExpressions {
                          id
                          key
                          operator
                          values
                        }
                        matchLabels {
                          id
                          key
                          value
                        }
                      }
                      namespaceSelector {
                        matchExpressions {
                          id
                          key
                          operator
                          values
                        }
                        matchLabels {
                          id
                          key
                          value
                        }
                      }
                      namespaces
                      topologyKey
                    }
                  }
                }
                podAntiAffinity {
                  requiredDuringSchedulingIgnoredDuringExecution {
                    id
                    labelSelector {
                        matchExpressions {
                          id
                          key
                          operator
                          values
                        }
                        matchLabels {
                          id
                          key
                          value
                        }
                      }
                      namespaceSelector {
                        matchExpressions {
                          id
                          key
                          operator
                          values
                        }
                        matchLabels {
                          id
                          key
                          value
                        }
                      }
                    namespaces
                    topologyKey
                  }
                  preferredDuringSchedulingIgnoredDuringExecution {
                    id
                    weight
                    preference {
                      id
                      labelSelector {
                        matchExpressions {
                          id
                          key
                          operator
                          values
                        }
                        matchLabels {
                          id
                          key
                          value
                        }
                      }
                      namespaceSelector {
                        matchExpressions {
                          id
                          key
                          operator
                          values
                        }
                        matchLabels {
                          id
                          key
                          value
                        }
                      }
                      namespaces
                      topologyKey
                    }
                    podAffinityTerm {
                      id
                      labelSelector {
                        matchExpressions {
                          id
                          key
                          operator
                          values
                        }
                        matchLabels {
                          id
                          key
                          value
                        }
                      }
                      namespaceSelector {
                        matchExpressions {
                          id
                          key
                          operator
                          values
                        }
                        matchLabels {
                          id
                          key
                          value
                        }
                      }
                      namespaces
                      topologyKey
                    }
                  }
                }
              }
              automountServiceAccountToken
              dnsPolicy
              enableServiceLinks
              hostIpc
              hostNetwork
              hostPid
              hostname
              nodeName
              preemptionPolicy
              priority
              priorityClassName
              restartPolicy
              runtimeClassName
              schedulerName
              serviceAccount
              serviceAccountName
              setHostnameAsFqdn
              shareProcessNamespace
              subdomain
              terminationGracePeriodSeconds
            }
          }
          ttlSecondsAfterFinished
        }
      }
      schedule
      startingDeadlineSeconds
      successfulJobsHistoryLimit
      suspend
    }
    status {
      lastScheduleTime
      lastSuccessfulTime
      active {
        id
    		apiVersion
        fieldPath
        kind
        name
        namespace
        resourceVersion
      }
    }
    namespace {
      id
      # other namespace fields
    }
  }
}


References

Dgraph documentation on querying

K8s CronJob Documentation

Updated 03 Mar 2023
Did this page help you?
Yes
No
UP NEXT
Deployment
Docs powered by archbee 
TABLE OF CONTENTS
Overview
Filtering
Advanced Filtering
Ordering
Aggregation
Kitchen Sink
References