diff --git a/config/samples/deployment-duplicator.yaml b/config/samples/deployment-duplicator.yaml new file mode 100644 index 0000000..be3c1e1 --- /dev/null +++ b/config/samples/deployment-duplicator.yaml @@ -0,0 +1,716 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.8.0 + creationTimestamp: null + name: deploymentcopies.duplication.k8s.wantedly.com +spec: + group: duplication.k8s.wantedly.com + names: + kind: DeploymentCopy + listKind: DeploymentCopyList + plural: deploymentcopies + singular: deploymentcopy + scope: Namespaced + versions: + - name: v1beta1 + schema: + openAPIV3Schema: + description: DeploymentCopy is the Schema for the deploymentcopies 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: DeploymentCopySpec defines the desired state of DeploymentCopy + properties: + customAnnotations: + additionalProperties: + type: string + description: annotations in `CustomAnnotations` and those of `TargetDeploymentName` + will be merged. When both have same keys, values in `Labels` will + be applied + type: object + customLabels: + additionalProperties: + type: string + description: labels in `CustomLabels` and those of `TargetDeploymentName` + will be merged. When both have same keys, values in `Labels` will + be applied This will also used for `Spec.Template.Labels` and `Spec.Selector.MatchLabels` + of copied Deployment + type: object + hostname: + description: (optional) if defined, the copied deployment will have + the specified Hostname + type: string + nameSuffix: + description: (optional) if defined, the copied deployment will have + suffix with this value. When not defined, `.Matadata.Name` will + be used + type: string + replicas: + description: If non-zero, Replicas will be used for replicas for the + copied deployment + format: int32 + type: integer + targetContainers: + description: name defined in `TargetDeploymentName` will be copied + items: + description: Container should be compatible with "k8s.io/api/apps/v1".Container, + so that we can support more fields later on + properties: + env: + items: + description: EnvVar represents an environment variable present + in a Container. + properties: + name: + description: Name of the environment variable. Must be + a C_IDENTIFIER. + type: string + value: + description: 'Variable references $(VAR_NAME) are expanded + using the previously defined environment variables in + the container and any service environment variables. + If a variable cannot be resolved, the reference in the + input string will be unchanged. Double $$ are reduced + to a single $, which allows for escaping the $(VAR_NAME) + syntax: i.e. "$$(VAR_NAME)" will produce the string + literal "$(VAR_NAME)". Escaped references will never + be expanded, regardless of whether the variable exists + or not. Defaults to "".' + type: string + valueFrom: + description: Source for the environment variable's value. + Cannot be used if value is not empty. + properties: + configMapKeyRef: + description: Selects a key of a ConfigMap. + properties: + key: + description: The key to select. + type: string + name: + description: 'Name of the referent. More info: + https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the ConfigMap or + its key must be defined + type: boolean + required: + - key + type: object + fieldRef: + description: 'Selects a field of the pod: supports + metadata.name, metadata.namespace, `metadata.labels[''<KEY>'']`, + `metadata.annotations[''<KEY>'']`, spec.nodeName, + spec.serviceAccountName, status.hostIP, status.podIP, + status.podIPs.' + properties: + apiVersion: + description: Version of the schema the FieldPath + is written in terms of, defaults to "v1". + type: string + fieldPath: + description: Path of the field to select in the + specified API version. + type: string + required: + - fieldPath + type: object + resourceFieldRef: + description: 'Selects a resource of the container: + only resources limits and requests (limits.cpu, + limits.memory, limits.ephemeral-storage, requests.cpu, + requests.memory and requests.ephemeral-storage) + are currently supported.' + properties: + containerName: + description: 'Container name: required for volumes, + optional for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output format of the + exposed resources, defaults to "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource to select' + type: string + required: + - resource + type: object + secretKeyRef: + description: Selects a key of a secret in the pod's + namespace + properties: + key: + description: The key of the secret to select from. Must + be a valid secret key. + type: string + name: + description: 'Name of the referent. More info: + https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the Secret or its + key must be defined + type: boolean + required: + - key + type: object + type: object + required: + - name + type: object + type: array + image: + type: string + name: + type: string + required: + - env + - image + - name + type: object + type: array + targetDeploymentName: + description: name defined in `TargetDeploymentName` will be copied + type: string + required: + - hostname + - nameSuffix + - replicas + - targetContainers + - targetDeploymentName + type: object + status: + description: DeploymentCopyStatus defines the observed state of DeploymentCopy + type: object + type: object + served: true + storage: true + subresources: + status: {} +status: + acceptedNames: + kind: "" + plural: "" + conditions: [] + storedVersions: [] +--- +apiVersion: v1 +kind: Namespace +metadata: + labels: + control-plane: controller-manager + name: deployment-duplicator-system +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.8.0 + creationTimestamp: null + name: deploymentcopies.duplication.k8s.wantedly.com +spec: + group: duplication.k8s.wantedly.com + names: + kind: DeploymentCopy + listKind: DeploymentCopyList + plural: deploymentcopies + singular: deploymentcopy + scope: Namespaced + versions: + - name: v1beta1 + schema: + openAPIV3Schema: + description: DeploymentCopy is the Schema for the deploymentcopies 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: DeploymentCopySpec defines the desired state of DeploymentCopy + properties: + customAnnotations: + additionalProperties: + type: string + description: annotations in `CustomAnnotations` and those of `TargetDeploymentName` + will be merged. When both have same keys, values in `Labels` will + be applied + type: object + customLabels: + additionalProperties: + type: string + description: labels in `CustomLabels` and those of `TargetDeploymentName` + will be merged. When both have same keys, values in `Labels` will + be applied This will also used for `Spec.Template.Labels` and `Spec.Selector.MatchLabels` + of copied Deployment + type: object + hostname: + description: (optional) if defined, the copied deployment will have + the specified Hostname + type: string + nameSuffix: + description: (optional) if defined, the copied deployment will have + suffix with this value. When not defined, `.Matadata.Name` will + be used + type: string + replicas: + description: If non-zero, Replicas will be used for replicas for the + copied deployment + format: int32 + type: integer + targetContainers: + description: name defined in `TargetDeploymentName` will be copied + items: + description: Container should be compatible with "k8s.io/api/apps/v1".Container, + so that we can support more fields later on + properties: + env: + items: + description: EnvVar represents an environment variable present + in a Container. + properties: + name: + description: Name of the environment variable. Must be + a C_IDENTIFIER. + type: string + value: + description: 'Variable references $(VAR_NAME) are expanded + using the previously defined environment variables in + the container and any service environment variables. + If a variable cannot be resolved, the reference in the + input string will be unchanged. Double $$ are reduced + to a single $, which allows for escaping the $(VAR_NAME) + syntax: i.e. "$$(VAR_NAME)" will produce the string + literal "$(VAR_NAME)". Escaped references will never + be expanded, regardless of whether the variable exists + or not. Defaults to "".' + type: string + valueFrom: + description: Source for the environment variable's value. + Cannot be used if value is not empty. + properties: + configMapKeyRef: + description: Selects a key of a ConfigMap. + properties: + key: + description: The key to select. + type: string + name: + description: 'Name of the referent. More info: + https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the ConfigMap or + its key must be defined + type: boolean + required: + - key + type: object + fieldRef: + description: 'Selects a field of the pod: supports + metadata.name, metadata.namespace, `metadata.labels[''<KEY>'']`, + `metadata.annotations[''<KEY>'']`, spec.nodeName, + spec.serviceAccountName, status.hostIP, status.podIP, + status.podIPs.' + properties: + apiVersion: + description: Version of the schema the FieldPath + is written in terms of, defaults to "v1". + type: string + fieldPath: + description: Path of the field to select in the + specified API version. + type: string + required: + - fieldPath + type: object + resourceFieldRef: + description: 'Selects a resource of the container: + only resources limits and requests (limits.cpu, + limits.memory, limits.ephemeral-storage, requests.cpu, + requests.memory and requests.ephemeral-storage) + are currently supported.' + properties: + containerName: + description: 'Container name: required for volumes, + optional for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output format of the + exposed resources, defaults to "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource to select' + type: string + required: + - resource + type: object + secretKeyRef: + description: Selects a key of a secret in the pod's + namespace + properties: + key: + description: The key of the secret to select from. Must + be a valid secret key. + type: string + name: + description: 'Name of the referent. More info: + https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the Secret or its + key must be defined + type: boolean + required: + - key + type: object + type: object + required: + - name + type: object + type: array + image: + type: string + name: + type: string + required: + - env + - image + - name + type: object + type: array + targetDeploymentName: + description: name defined in `TargetDeploymentName` will be copied + type: string + required: + - hostname + - nameSuffix + - replicas + - targetContainers + - targetDeploymentName + type: object + status: + description: DeploymentCopyStatus defines the observed state of DeploymentCopy + type: object + type: object + served: true + storage: true + subresources: + status: {} +status: + acceptedNames: + kind: "" + plural: "" + conditions: [] + storedVersions: [] +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: deployment-duplicator-controller-manager + namespace: deployment-duplicator-system +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: deployment-duplicator-leader-election-role + namespace: deployment-duplicator-system +rules: +- apiGroups: + - "" + resources: + - configmaps + verbs: + - get + - list + - watch + - create + - update + - patch + - delete +- apiGroups: + - coordination.k8s.io + resources: + - leases + verbs: + - get + - list + - watch + - create + - update + - patch + - delete +- apiGroups: + - "" + resources: + - events + verbs: + - create + - patch +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + creationTimestamp: null + name: deployment-duplicator-manager-role +rules: +- apiGroups: + - apps + resources: + - deployments + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - apps + resources: + - deployments/status + verbs: + - get + - patch + - update +- apiGroups: + - duplication.k8s.wantedly.com + resources: + - deploymentcopies + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - duplication.k8s.wantedly.com + resources: + - deploymentcopies/finalizers + verbs: + - update +- apiGroups: + - duplication.k8s.wantedly.com + resources: + - deploymentcopies/status + verbs: + - get + - patch + - update +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: deployment-duplicator-metrics-reader +rules: +- nonResourceURLs: + - /metrics + verbs: + - get +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: deployment-duplicator-proxy-role +rules: +- apiGroups: + - authentication.k8s.io + resources: + - tokenreviews + verbs: + - create +- apiGroups: + - authorization.k8s.io + resources: + - subjectaccessreviews + verbs: + - create +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: deployment-duplicator-leader-election-rolebinding + namespace: deployment-duplicator-system +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: deployment-duplicator-leader-election-role +subjects: +- kind: ServiceAccount + name: deployment-duplicator-controller-manager + namespace: deployment-duplicator-system +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: deployment-duplicator-manager-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: deployment-duplicator-manager-role +subjects: +- kind: ServiceAccount + name: deployment-duplicator-controller-manager + namespace: deployment-duplicator-system +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: deployment-duplicator-proxy-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: deployment-duplicator-proxy-role +subjects: +- kind: ServiceAccount + name: deployment-duplicator-controller-manager + namespace: deployment-duplicator-system +--- +apiVersion: v1 +data: + controller_manager_config.yaml: | + apiVersion: controller-runtime.sigs.k8s.io/v1alpha1 + kind: ControllerManagerConfig + health: + healthProbeBindAddress: :8081 + metrics: + bindAddress: 127.0.0.1:8080 + webhook: + port: 9443 + leaderElection: + leaderElect: true + resourceName: 3025a49c.k8s.wantedly.com +kind: ConfigMap +metadata: + name: deployment-duplicator-manager-config + namespace: deployment-duplicator-system +--- +apiVersion: v1 +kind: Service +metadata: + labels: + control-plane: controller-manager + name: deployment-duplicator-controller-manager-metrics-service + namespace: deployment-duplicator-system +spec: + ports: + - name: https + port: 8443 + protocol: TCP + targetPort: https + selector: + control-plane: controller-manager +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + control-plane: controller-manager + name: deployment-duplicator-controller-manager + namespace: deployment-duplicator-system +spec: + replicas: 1 + selector: + matchLabels: + control-plane: controller-manager + template: + metadata: + annotations: + kubectl.kubernetes.io/default-container: manager + 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=0 + image: gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0 + name: kube-rbac-proxy + ports: + - containerPort: 8443 + name: https + protocol: TCP + resources: + limits: + cpu: 500m + memory: 128Mi + requests: + cpu: 5m + memory: 64Mi + - args: + - --health-probe-bind-address=:8081 + - --metrics-bind-address=127.0.0.1:8080 + - --leader-elect + command: + - /manager + image: quay.io/wantedly/deployment-duplicator:latest + livenessProbe: + httpGet: + path: /healthz + port: 8081 + initialDelaySeconds: 15 + periodSeconds: 20 + name: manager + readinessProbe: + httpGet: + path: /readyz + port: 8081 + initialDelaySeconds: 5 + periodSeconds: 10 + resources: + limits: + cpu: 500m + memory: 128Mi + requests: + cpu: 10m + memory: 64Mi + securityContext: + allowPrivilegeEscalation: false + securityContext: + runAsNonRoot: true + serviceAccountName: deployment-duplicator-controller-manager + terminationGracePeriodSeconds: 10