kubernetes-sigs / kubebuilder

Kubebuilder - SDK for building Kubernetes APIs using CRDs
http://book.kubebuilder.io
Apache License 2.0
7.85k stars 1.44k forks source link

How to define spec variable which is injectable by MutatingWebhookConfiguration #1376

Closed TrsNium closed 4 years ago

TrsNium commented 4 years ago

Hello.

I recently make crd (https://github.com/TrsNium/digdag-worker-crd). But I have a question, so let me ask you a question.

I try to overwrote the spec variable with MutatingWebhookConfiguration but it didn't work. At that time, CRD and MutatingWebhookConfiguration are defined as following.

MutatingWebhookConfiguration

apiVersion: admissionregistration.k8s.io/v1beta1
kind: MutatingWebhookConfiguration
metadata:
  name: berglas-webhook
  labels:
    app: berglas-webhook
    kind: mutator

webhooks:
- name: berglas-webhook.cloud.google.com
  clientConfig:
    url: REPLACE_WITH_YOUR_URL
    caBundle: ""
  rules:
  - operations: ["CREATE", "UPDATE"]
    apiGroups: ["horizontalpodautoscalers.autoscaling.digdag-worker-crd"]
    apiVersions: ["v1"]
    resources: ["*"]

CRD

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  annotations:
    controller-gen.kubebuilder.io/version: v0.2.4
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"apiextensions.k8s.io/v1beta1","kind":"CustomResourceDefinition","metadata":{"annotations":{"controller-gen.kubebuilder.io/version":"v0.2.4"},"creationTimestamp":null,"name":"horizontaldigdagworkerautoscalers.horizontalpodautoscalers.autoscaling.digdag-worker-crd"},"spec":{"group":"horizontalpodautoscalers.autoscaling.digdag-worker-crd","names":{"kind":"HorizontalDigdagWorkerAutoscaler","listKind":"HorizontalDigdagWorkerAutoscalerList","plural":"horizontaldigdagworkerautoscalers","singular":"horizontaldigdagworkerautoscaler"},"scope":"Namespaced","validation":{"openAPIV3Schema":{"description":"HorizontalDigdagWorkerAutoscaler is the Schema for the horizontaldigdagworkerautoscalers API","properties":{"apiVersion":{"description":"APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources","type":"string"},"kind":{"description":"Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds","type":"string"},"metadata":{"type":"object"},"spec":{"description":"NOTE: json tags are required.  Any new fields you add must have json tags for the fields to be serialized. HorizontalDigdagWorkerAutoscalerSpec defines the desired state of HorizontalDigdagWorkerAutoscaler","properties":{"digdagMaxTaskThreads":{"format":"int32","minimum":1,"type":"integer"},"postgresqlDatabase":{"type":"string"},"postgresqlHost":{"type":"string"},"postgresqlPassword":{"type":"string"},"postgresqlPort":{"format":"int32","type":"integer"},"postgresqlUser":{"type":"string"},"scaleTargetDeployment":{"description":"INSERT ADDITIONAL SPEC FIELDS - desired state of cluster Important: Run \"make\" to regenerate code after modifying this file","type":"string"},"scaleTargetDeploymentNamespace":{"type":"string"}},"required":["digdagMaxTaskThreads","postgresqlDatabase","postgresqlHost","postgresqlPassword","postgresqlPort","postgresqlUser","scaleTargetDeployment","scaleTargetDeploymentNamespace"],"type":"object"},"status":{"description":"HorizontalDigdagWorkerAutoscalerStatus defines the observed state of HorizontalDigdagWorkerAutoscaler","type":"object"}},"type":"object"}},"version":"v1","versions":[{"name":"v1","served":true,"storage":true}]},"status":{"acceptedNames":{"kind":"","plural":""},"conditions":[],"storedVersions":[]}}
  creationTimestamp: "2020-02-18T07:02:39Z"
  generation: 1
  name: horizontaldigdagworkerautoscalers.horizontalpodautoscalers.autoscaling.digdag-worker-crd
  resourceVersion: "1961146"
  selfLink: /apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/horizontaldigdagworkerautoscalers.horizontalpodautoscalers.autoscaling.digdag-worker-crd
  uid: a6a533a9-521c-11ea-bbc4-4201ac130806
spec:
  conversion:
    strategy: None
  group: horizontalpodautoscalers.autoscaling.digdag-worker-crd
  names:
    kind: HorizontalDigdagWorkerAutoscaler
    listKind: HorizontalDigdagWorkerAutoscalerList
    plural: horizontaldigdagworkerautoscalers
    singular: horizontaldigdagworkerautoscaler
  scope: Namespaced
  validation:
    openAPIV3Schema:
      description: HorizontalDigdagWorkerAutoscaler is the Schema for the horizontaldigdagworkerautoscalers
        API
      properties:
        apiVersion:
          description: 'APIVersion defines the versioned schema of this representation
            of an object. Servers should convert recognized schemas to the latest
            internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
          type: string
        kind:
          description: 'Kind is a string value representing the REST resource this
            object represents. Servers may infer this from the endpoint the client
            submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
          type: string
        metadata:
          type: object
        spec:
          description: 'NOTE: json tags are required.  Any new fields you add must
            have json tags for the fields to be serialized. HorizontalDigdagWorkerAutoscalerSpec
            defines the desired state of HorizontalDigdagWorkerAutoscaler'
          properties:
            digdagMaxTaskThreads:
              format: int32
              minimum: 1
              type: integer
            postgresqlDatabase:
              type: string
            postgresqlHost:
              type: string
            postgresqlPassword:
              type: string
            postgresqlPort:
              format: int32
              type: integer
            postgresqlUser:
              type: string
            scaleTargetDeployment:
              description: 'INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
                Important: Run "make" to regenerate code after modifying this file'
              type: string
            scaleTargetDeploymentNamespace:
              type: string
          required:
          - digdagMaxTaskThreads
          - postgresqlDatabase
          - postgresqlHost
          - postgresqlPassword
          - postgresqlPort
          - postgresqlUser
          - scaleTargetDeployment
          - scaleTargetDeploymentNamespace
          type: object
        status:
          description: HorizontalDigdagWorkerAutoscalerStatus defines the observed
            state of HorizontalDigdagWorkerAutoscaler
          type: object
      type: object
  version: v1
  versions:
  - name: v1
    served: true
    storage: true
status:
  acceptedNames:
    kind: HorizontalDigdagWorkerAutoscaler
    listKind: HorizontalDigdagWorkerAutoscalerList
    plural: horizontaldigdagworkerautoscalers
    singular: horizontaldigdagworkerautoscaler
  conditions:
  - lastTransitionTime: "2020-02-18T07:02:39Z"
    message: no conflicts found
    reason: NoConflicts
    status: "True"
    type: NamesAccepted
  - lastTransitionTime: null
    message: the initial names have been accepted
    reason: InitialNamesAccepted
    status: "True"
    type: Established
  storedVersions:
  - v1

Please let me know if there is a reason why the above definition does not work.

TrsNium commented 4 years ago

I'm sorry if the project that I should ask is different.