Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRD support in k8s resource mapping #50042

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

creack
Copy link
Member

@creack creack commented Dec 10, 2024

Support CRD in kubernetes resources for roles.

Removes the validation on the kind field to allow for arbitrary resources.
To avoid changing the model, the api group/version are added to the kind field.
Enable support for cluster-wide resources.
Update role editor to support CRDs

changelog: Add support for CRDs in kubernetes_resources for roles.

Example

kube-access teleport role:

---
kind: role
metadata:
  name: kube-access
version: v7
spec:
  allow:
    kubernetes_labels:
      'region': '*'
      'platform': 'kind'
    kubernetes_resources:
      - kind: pod
        namespace: "production"
        name: "^webapp-[a-z0-9-]+$"
        verbs: ["get", "watch", "list"]
      - kind: stable.example.com/v1/crontabs
        namespace: "production"
        name: "*"
        verbs: ["*"]
      - kind: '*'
        namespace: "development"
        name: "*"
        verbs: ["*"]
    kubernetes_groups:
    - developers
    kubernetes_users:
    - minikube
  deny: {}

clusterrolebinding:

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: pod-viewer
rules:
- apiGroups: ["*"]
  resources: ["*"]
  verbs: ["*"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: pod-viewer
subjects:
- kind: Group
  name: developers
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: ClusterRole
  name: pod-viewer
  apiGroup: rbac.authorization.k8s.io

NS:

---
apiVersion: v1
kind: Namespace
metadata:
  name: development
  labels:
    name: development
---
apiVersion: v1
kind: Namespace
metadata:
  name: production
  labels:
    name: production

CRD:

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  # Name must match the spec fields below, and be in the form: <plural>.<group>
  name: crontabs.stable.example.com
spec:
  # group name to use for REST API: /apis/<group>/<version>
  group: stable.example.com
  # list of versions supported by this CustomResourceDefinition
  versions:
    - name: v1
      # Each version can be enabled/disabled by Served flag.
      served: true
      # One and only one version must be marked as the storage version.
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                cronSpec:
                  type: string
                image:
                  type: string
                replicas:
                  type: integer
  # either Namespaced or Cluster
  scope: Namespaced
  names:
    # plural name to be used in the URL: /apis/<group>/<version>/<plural>
    plural: crontabs
    # singular name to be used as an alias on the CLI and for display
    singular: crontab
    # kind is normally the CamelCased singular type. Your resource manifests use this.
    kind: CronTab
    # shortNames allow shorter string to match your resource on the CLI
    shortNames:
    - ct
---
apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object-dev
  namespace: development
spec:
  cronSpec: "* * * * */5"
  image: my-awesome-cron-image
---
apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object-prod
  namespace: production
spec:
  cronSpec: "* * * * */5"
  image: my-awesome-cron-image

CronTab

---
apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object-prod-2
  namespace: production
spec:
  cronSpec: "* * * * */5"
  image: my-awesome-cron-image

@shia-raiffeisen
Copy link

As far as I've investigated into this topic myself, I've discovered usage of the Kubenetes runtime with basic Scheme. Meaning, if we want to support CRDs we need to use client with extended scheme and api group

@creack creack force-pushed the creack/k8s-crds-mapping branch 3 times, most recently from 7e49015 to c2596cf Compare January 31, 2025 15:53
@creack creack force-pushed the creack/k8s-crds-mapping branch 7 times, most recently from 082698f to d03b0c1 Compare February 9, 2025 18:03
Copy link

github-actions bot commented Feb 9, 2025

Amplify deployment status

Branch Commit Job ID Status Preview Updated (UTC)
creack/k8s-crds-mapping 427df91 3 ✅SUCCEED creack-k8s-crds-mapping 2025-02-09 18:40:44

@creack creack force-pushed the creack/k8s-crds-mapping branch from d03b0c1 to b5bf668 Compare February 9, 2025 18:15
Update role editor to support CRDs.
Update docs.
@creack creack changed the title Experiment with CRD support in k8s resource mapping CRD support in k8s resource mapping Feb 9, 2025
@creack creack force-pushed the creack/k8s-crds-mapping branch from b5bf668 to 427df91 Compare February 9, 2025 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants