apiVersion: v1
kind: Namespace
metadata:
  labels:
    control-plane: controller-manager
  name: music-system
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  annotations:
    cert-manager.io/inject-ca-from: music-system/music-serving-cert
    controller-gen.kubebuilder.io/version: v0.2.5
  name: rockbands.music.example.io
spec:
  conversion:
    strategy: Webhook
    webhook:
      clientConfig:
        caBundle: Cg==
        service:
          name: music-webhook-service
          namespace: music-system
          path: /convert
      conversionReviewVersions:
      - v2
      - v1
  group: music.example.io
  names:
    kind: RockBand
    listKind: RockBandList
    plural: rockbands
    singular: rockband
  scope: Namespaced
  versions:
  - name: v1
    schema:
      openAPIV3Schema:
        description: RockBand is the Schema for the rockbands 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: RockBandSpec defines the desired state of RockBand
            properties:
              genre:
                type: string
              leadSinger:
                type: string
              numberComponents:
                format: int32
                type: integer
            type: object
          status:
            description: RockBandStatus defines the observed state of RockBand
            properties:
              lastPlayed:
                type: string
            required:
            - lastPlayed
            type: object
        type: object
    served: true
    storage: false
  - name: v2
    schema:
      openAPIV3Schema:
        description: RockBand is the Schema for the rockbands 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: RockBandSpec defines the desired state of RockBand
            properties:
              bass:
                type: string
              drummer:
                type: string
              genre:
                type: string
              leadGuitar:
                type: string
              leadSinger:
                type: string
              numberComponents:
                format: int32
                type: integer
            type: object
          status:
            description: RockBandStatus defines the observed state of RockBand
            properties:
              lastPlayed:
                type: string
            type: object
        type: object
    served: true
    storage: true
    subresources:
      status: {}
status:
  acceptedNames:
    kind: ""
    plural: ""
  conditions: []
  storedVersions: []
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: music-leader-election-role
  namespace: music-system
rules:
- apiGroups:
  - ""
  resources:
  - configmaps
  verbs:
  - get
  - list
  - watch
  - create
  - update
  - patch
  - delete
- apiGroups:
  - ""
  resources:
  - configmaps/status
  verbs:
  - get
  - update
  - patch
- apiGroups:
  - ""
  resources:
  - events
  verbs:
  - create
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  creationTimestamp: null
  name: music-manager-role
rules:
- apiGroups:
  - music.example.io
  resources:
  - rockbands
  verbs:
  - create
  - delete
  - get
  - list
  - patch
  - update
  - watch
- apiGroups:
  - music.example.io
  resources:
  - rockbands/status
  verbs:
  - get
  - patch
  - update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: music-proxy-role
rules:
- apiGroups:
  - authentication.k8s.io
  resources:
  - tokenreviews
  verbs:
  - create
- apiGroups:
  - authorization.k8s.io
  resources:
  - subjectaccessreviews
  verbs:
  - create
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
  name: music-metrics-reader
rules:
- nonResourceURLs:
  - /metrics
  verbs:
  - get
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: music-leader-election-rolebinding
  namespace: music-system
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: music-leader-election-role
subjects:
- kind: ServiceAccount
  name: default
  namespace: music-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: music-manager-rolebinding
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: music-manager-role
subjects:
- kind: ServiceAccount
  name: default
  namespace: music-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: music-proxy-rolebinding
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: music-proxy-role
subjects:
- kind: ServiceAccount
  name: default
  namespace: music-system
---
apiVersion: v1
kind: Service
metadata:
  labels:
    control-plane: controller-manager
  name: music-controller-manager-metrics-service
  namespace: music-system
spec:
  ports:
  - name: https
    port: 8443
    targetPort: https
  selector:
    control-plane: controller-manager
---
apiVersion: v1
kind: Service
metadata:
  name: music-webhook-service
  namespace: music-system
spec:
  ports:
  - port: 443
    targetPort: 9443
  selector:
    control-plane: controller-manager
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    control-plane: controller-manager
  name: music-controller-manager
  namespace: music-system
spec:
  replicas: 1
  selector:
    matchLabels:
      control-plane: controller-manager
  template:
    metadata:
      labels:
        control-plane: controller-manager
    spec:
      containers:
      - args:
        - --secure-listen-address=0.0.0.0:8443
        - --upstream=http://127.0.0.1:8080/
        - --logtostderr=true
        - --v=10
        image: gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0
        name: kube-rbac-proxy
        ports:
        - containerPort: 8443
          name: https
      - args:
        - --metrics-addr=127.0.0.1:8080
        - --enable-leader-election
        command:
        - /manager
        image: quay.io/brito_rafa/music-controller:case-c-target-v0.1
        name: manager
        ports:
        - containerPort: 9443
          name: webhook-server
          protocol: TCP
        resources:
          limits:
            cpu: 100m
            memory: 30Mi
          requests:
            cpu: 100m
            memory: 20Mi
        volumeMounts:
        - mountPath: /tmp/k8s-webhook-server/serving-certs
          name: cert
          readOnly: true
      terminationGracePeriodSeconds: 10
      volumes:
      - name: cert
        secret:
          defaultMode: 420
          secretName: webhook-server-cert
---
apiVersion: cert-manager.io/v1alpha2
kind: Certificate
metadata:
  name: music-serving-cert
  namespace: music-system
spec:
  dnsNames:
  - music-webhook-service.music-system.svc
  - music-webhook-service.music-system.svc.cluster.local
  issuerRef:
    kind: Issuer
    name: music-selfsigned-issuer
  secretName: webhook-server-cert
---
apiVersion: cert-manager.io/v1alpha2
kind: Issuer
metadata:
  name: music-selfsigned-issuer
  namespace: music-system
spec:
  selfSigned: {}
---
apiVersion: admissionregistration.k8s.io/v1beta1
kind: MutatingWebhookConfiguration
metadata:
  annotations:
    cert-manager.io/inject-ca-from: music-system/music-serving-cert
  name: music-mutating-webhook-configuration
webhooks:
- clientConfig:
    caBundle: Cg==
    service:
      name: music-webhook-service
      namespace: music-system
      path: /mutate-music-example-io-v1-rockband
  failurePolicy: Fail
  name: mrockband.kb.io
  rules:
  - apiGroups:
    - music.example.io
    apiVersions:
    - v1
    operations:
    - CREATE
    - UPDATE
    resources:
    - rockbands
- clientConfig:
    caBundle: Cg==
    service:
      name: music-webhook-service
      namespace: music-system
      path: /mutate-music-example-io-v2-rockband
  failurePolicy: Fail
  name: mrockband.kb.io
  rules:
  - apiGroups:
    - music.example.io
    apiVersions:
    - v2
    operations:
    - CREATE
    - UPDATE
    resources:
    - rockbands
---
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingWebhookConfiguration
metadata:
  annotations:
    cert-manager.io/inject-ca-from: music-system/music-serving-cert
  name: music-validating-webhook-configuration
webhooks:
- clientConfig:
    caBundle: Cg==
    service:
      name: music-webhook-service
      namespace: music-system
      path: /validate-music-example-io-v1-rockband
  failurePolicy: Fail
  name: vrockband.kb.io
  rules:
  - apiGroups:
    - music.example.io
    apiVersions:
    - v1
    operations:
    - CREATE
    - UPDATE
    resources:
    - rockbands
