diff --git a/.DS_Store b/.DS_Store index 466cc24a..1d30c936 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Makefile b/Makefile index e39df626..d741aa11 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ IMG ?= ghcr.io/k8sgpt-ai/k8sgpt-operator:latest # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. ENVTEST_K8S_VERSION = 1.26.0 -CHART_VERSION=v0.0.2# x-release-please-version +CHART_VERSION=v0.0.3# x-release-please-version # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) GOBIN=$(shell go env GOPATH)/bin @@ -116,26 +116,38 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. $(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f - +.PHONY: helmify +helmify: $(HELMIFY) ## Download helmify locally if necessary. +$(HELMIFY): $(LOCALBIN) + test -s $(LOCALBIN)/helmify || GOBIN=$(LOCALBIN) go install github.com/arttor/helmify/cmd/helmify@latest + OSARCH=$(shell ./hack/get-os.sh) HELM = $(shell pwd)/bin/$(OSARCH)/helm HELM_INSTALLER ?= "https://get.helm.sh/helm-v3.10.1-$(OSARCH).tar.gz" +HELMIFY ?= $(LOCALBIN)/helmify .PHONY: helm helm: $(HELM) ## Download helm locally if necessary. $(HELM): $(LOCALBIN) [ -e "$(HELM)" ] && rm -rf "$(HELM)" || true cd $(LOCALBIN) && curl -s $(HELM_INSTALLER) | tar -xzf - -C $(LOCALBIN) -.PHONY: release-manifests -release-manifests: manifests kustomize +.PHONY: helmify +helmify: $(HELMIFY) ## Download helmify locally if necessary. +$(HELMIFY): $(LOCALBIN) + test -s $(LOCALBIN)/helmify || GOBIN=$(LOCALBIN) go install github.com/arttor/helmify/cmd/helmify@latest + +.PHONY: helm-build +helm-build: helm helmify manifests kustomize cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) && cd ../../ - mkdir -p chart/k8sgpt-operator/templates/ - $(KUSTOMIZE) build config/default > chart/k8sgpt-operator/templates/rendered.yaml + $(KUSTOMIZE) build config/default | $(HELMIFY) -helm-package: generate manifests release-manifests helm - $(HELM) package --version $(CHART_VERSION) chart/k8sgpt-operator +helm-package: generate manifests helm-build + $(HELM) package --version $(CHART_VERSION) chart/ mkdir -p charts && mv k8sgpt-operator-*.tgz charts $(HELM) repo index --url https://charts.k8sgpt.ai/charts charts mv charts/index.yaml index.yaml + + ##@ Build Dependencies ## Location to install dependencies to diff --git a/chart/.helmignore b/chart/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/chart/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/chart/Chart.yaml b/chart/Chart.yaml new file mode 100644 index 00000000..138331e5 --- /dev/null +++ b/chart/Chart.yaml @@ -0,0 +1,21 @@ +apiVersion: v2 +name: k8sgpt-operator +description: A Helm chart for Kubernetes +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.0.3 +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "0.1.0" diff --git a/chart/templates/_helpers.tpl b/chart/templates/_helpers.tpl new file mode 100644 index 00000000..7ba5edc2 --- /dev/null +++ b/chart/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "chart.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "chart.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "chart.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "chart.labels" -}} +helm.sh/chart: {{ include "chart.chart" . }} +{{ include "chart.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "chart.selectorLabels" -}} +app.kubernetes.io/name: {{ include "chart.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "chart.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "chart.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml new file mode 100644 index 00000000..484fdd4d --- /dev/null +++ b/chart/templates/deployment.yaml @@ -0,0 +1,102 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "chart.fullname" . }}-controller-manager + labels: + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: k8sgpt-operator + app.kubernetes.io/part-of: k8sgpt-operator + {{- include "chart.labels" . | nindent 4 }} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "chart.fullname" . }}-controller-manager + labels: + app.kubernetes.io/component: manager + app.kubernetes.io/created-by: k8sgpt-operator + app.kubernetes.io/part-of: k8sgpt-operator + control-plane: controller-manager + {{- include "chart.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.controllerManager.replicas }} + selector: + matchLabels: + control-plane: controller-manager + {{- include "chart.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + control-plane: controller-manager + {{- include "chart.selectorLabels" . | nindent 8 }} + annotations: + kubectl.kubernetes.io/default-container: manager + spec: + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/arch + operator: In + values: + - amd64 + - arm64 + - ppc64le + - s390x + - key: kubernetes.io/os + operator: In + values: + - linux + containers: + - args: + - --secure-listen-address=0.0.0.0:8443 + - --upstream=http://127.0.0.1:8080/ + - --logtostderr=true + - --v=0 + env: + - name: KUBERNETES_CLUSTER_DOMAIN + value: {{ quote .Values.kubernetesClusterDomain }} + image: {{ .Values.controllerManager.kubeRbacProxy.image.repository }}:{{ .Values.controllerManager.kubeRbacProxy.image.tag + | default .Chart.AppVersion }} + name: kube-rbac-proxy + ports: + - containerPort: 8443 + name: https + protocol: TCP + resources: {{- toYaml .Values.controllerManager.kubeRbacProxy.resources | nindent + 10 }} + securityContext: {{- toYaml .Values.controllerManager.kubeRbacProxy.containerSecurityContext + | nindent 10 }} + - args: + - --health-probe-bind-address=:8081 + - --metrics-bind-address=127.0.0.1:8080 + - --leader-elect + command: + - /manager + env: + - name: KUBERNETES_CLUSTER_DOMAIN + value: {{ quote .Values.kubernetesClusterDomain }} + image: {{ .Values.controllerManager.manager.image.repository }}:{{ .Values.controllerManager.manager.image.tag + | default .Chart.AppVersion }} + livenessProbe: + httpGet: + path: /healthz + port: 8081 + initialDelaySeconds: 15 + periodSeconds: 20 + name: manager + readinessProbe: + httpGet: + path: /readyz + port: 8081 + initialDelaySeconds: 5 + periodSeconds: 10 + resources: {{- toYaml .Values.controllerManager.manager.resources | nindent 10 + }} + securityContext: {{- toYaml .Values.controllerManager.manager.containerSecurityContext + | nindent 10 }} + securityContext: + runAsNonRoot: true + serviceAccountName: {{ include "chart.fullname" . }}-controller-manager + terminationGracePeriodSeconds: 10 \ No newline at end of file diff --git a/chart/templates/k8sgpt-crd.yaml b/chart/templates/k8sgpt-crd.yaml new file mode 100644 index 00000000..1cce08c0 --- /dev/null +++ b/chart/templates/k8sgpt-crd.yaml @@ -0,0 +1,71 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: k8sgpts.core.k8sgpt.ai + annotations: + controller-gen.kubebuilder.io/version: v0.11.1 + labels: + {{- include "chart.labels" . | nindent 4 }} +spec: + group: core.k8sgpt.ai + names: + kind: K8sGPT + listKind: K8sGPTList + plural: k8sgpts + singular: k8sgpt + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: K8sGPT is the Schema for the k8sgpts 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: K8sGPTSpec defines the desired state of K8sGPT + properties: + backend: + type: string + enableAI: + type: boolean + model: + type: string + namespace: + type: string + noCache: + type: boolean + secret: + properties: + key: + type: string + name: + type: string + type: object + version: + type: string + type: object + status: + description: K8sGPTStatus defines the observed state of K8sGPT + type: object + type: object + served: true + storage: true + subresources: + status: {} +status: + acceptedNames: + kind: "" + plural: "" + conditions: [] + storedVersions: [] \ No newline at end of file diff --git a/chart/templates/leader-election-rbac.yaml b/chart/templates/leader-election-rbac.yaml new file mode 100644 index 00000000..43ace33e --- /dev/null +++ b/chart/templates/leader-election-rbac.yaml @@ -0,0 +1,59 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: {{ include "chart.fullname" . }}-leader-election-role + labels: + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: k8sgpt-operator + app.kubernetes.io/part-of: k8sgpt-operator + {{- include "chart.labels" . | nindent 4 }} +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: RoleBinding +metadata: + name: {{ include "chart.fullname" . }}-leader-election-rolebinding + labels: + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: k8sgpt-operator + app.kubernetes.io/part-of: k8sgpt-operator + {{- include "chart.labels" . | nindent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: '{{ include "chart.fullname" . }}-leader-election-role' +subjects: +- kind: ServiceAccount + name: '{{ include "chart.fullname" . }}-controller-manager' + namespace: '{{ .Release.Namespace }}' \ No newline at end of file diff --git a/chart/templates/manager-rbac.yaml b/chart/templates/manager-rbac.yaml new file mode 100644 index 00000000..3f1b5577 --- /dev/null +++ b/chart/templates/manager-rbac.yaml @@ -0,0 +1,75 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ include "chart.fullname" . }}-manager-role + labels: + {{- include "chart.labels" . | nindent 4 }} +rules: +- apiGroups: + - '*' + resources: + - '*' + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - core.k8sgpt.ai + resources: + - k8sgpts + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - core.k8sgpt.ai + resources: + - k8sgpts/finalizers + verbs: + - update +- apiGroups: + - core.k8sgpt.ai + resources: + - k8sgpts/status + verbs: + - get + - patch + - update +- apiGroups: + - core.k8sgpt.ai + resources: + - results + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ include "chart.fullname" . }}-manager-rolebinding + labels: + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: k8sgpt-operator + app.kubernetes.io/part-of: k8sgpt-operator + {{- include "chart.labels" . | nindent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: '{{ include "chart.fullname" . }}-manager-role' +subjects: +- kind: ServiceAccount + name: '{{ include "chart.fullname" . }}-controller-manager' + namespace: '{{ .Release.Namespace }}' \ No newline at end of file diff --git a/chart/templates/metrics-reader-rbac.yaml b/chart/templates/metrics-reader-rbac.yaml new file mode 100644 index 00000000..dd2247d2 --- /dev/null +++ b/chart/templates/metrics-reader-rbac.yaml @@ -0,0 +1,14 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ include "chart.fullname" . }}-metrics-reader + labels: + app.kubernetes.io/component: kube-rbac-proxy + app.kubernetes.io/created-by: k8sgpt-operator + app.kubernetes.io/part-of: k8sgpt-operator + {{- include "chart.labels" . | nindent 4 }} +rules: +- nonResourceURLs: + - /metrics + verbs: + - get \ No newline at end of file diff --git a/chart/templates/metrics-service.yaml b/chart/templates/metrics-service.yaml new file mode 100644 index 00000000..ca352f8e --- /dev/null +++ b/chart/templates/metrics-service.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "chart.fullname" . }}-controller-manager-metrics-service + labels: + app.kubernetes.io/component: kube-rbac-proxy + app.kubernetes.io/created-by: k8sgpt-operator + app.kubernetes.io/part-of: k8sgpt-operator + control-plane: controller-manager + {{- include "chart.labels" . | nindent 4 }} +spec: + type: {{ .Values.metricsService.type }} + selector: + control-plane: controller-manager + {{- include "chart.selectorLabels" . | nindent 4 }} + ports: + {{- .Values.metricsService.ports | toYaml | nindent 2 -}} \ No newline at end of file diff --git a/chart/templates/proxy-rbac.yaml b/chart/templates/proxy-rbac.yaml new file mode 100644 index 00000000..05e73254 --- /dev/null +++ b/chart/templates/proxy-rbac.yaml @@ -0,0 +1,40 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ include "chart.fullname" . }}-proxy-role + labels: + app.kubernetes.io/component: kube-rbac-proxy + app.kubernetes.io/created-by: k8sgpt-operator + app.kubernetes.io/part-of: k8sgpt-operator + {{- include "chart.labels" . | nindent 4 }} +rules: +- apiGroups: + - authentication.k8s.io + resources: + - tokenreviews + verbs: + - create +- apiGroups: + - authorization.k8s.io + resources: + - subjectaccessreviews + verbs: + - create +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ include "chart.fullname" . }}-proxy-rolebinding + labels: + app.kubernetes.io/component: kube-rbac-proxy + app.kubernetes.io/created-by: k8sgpt-operator + app.kubernetes.io/part-of: k8sgpt-operator + {{- include "chart.labels" . | nindent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: '{{ include "chart.fullname" . }}-proxy-role' +subjects: +- kind: ServiceAccount + name: '{{ include "chart.fullname" . }}-controller-manager' + namespace: '{{ .Release.Namespace }}' \ No newline at end of file diff --git a/chart/templates/result-crd.yaml b/chart/templates/result-crd.yaml new file mode 100644 index 00000000..d331633e --- /dev/null +++ b/chart/templates/result-crd.yaml @@ -0,0 +1,84 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: results.core.k8sgpt.ai + annotations: + controller-gen.kubebuilder.io/version: v0.11.1 + labels: + {{- include "chart.labels" . | nindent 4 }} +spec: + group: core.k8sgpt.ai + names: + kind: Result + listKind: ResultList + plural: results + singular: result + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: Result is the Schema for the results 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: ResultSpec defines the desired state of Result + properties: + details: + type: string + error: + items: + properties: + sensitive: + items: + properties: + masked: + type: string + unmasked: + type: string + type: object + type: array + text: + type: string + type: object + type: array + kind: + description: 'INSERT ADDITIONAL SPEC FIELDS - desired state of cluster + Important: Run "make" to regenerate code after modifying this file' + type: string + name: + type: string + parentObject: + type: string + required: + - details + - error + - kind + - name + - parentObject + type: object + status: + description: ResultStatus defines the observed state of Result + type: object + type: object + served: true + storage: true + subresources: + status: {} +status: + acceptedNames: + kind: "" + plural: "" + conditions: [] + storedVersions: [] \ No newline at end of file diff --git a/chart/values.yaml b/chart/values.yaml new file mode 100644 index 00000000..cb17d0b2 --- /dev/null +++ b/chart/values.yaml @@ -0,0 +1,42 @@ +controllerManager: + kubeRbacProxy: + containerSecurityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + image: + repository: gcr.io/kubebuilder/kube-rbac-proxy + tag: v0.13.1 + resources: + limits: + cpu: 500m + memory: 128Mi + requests: + cpu: 5m + memory: 64Mi + manager: + containerSecurityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + image: + repository: ghcr.io/k8sgpt-ai/k8sgpt-operator + tag: latest + resources: + limits: + cpu: 500m + memory: 128Mi + requests: + cpu: 10m + memory: 64Mi + replicas: 1 +kubernetesClusterDomain: cluster.local +metricsService: + ports: + - name: https + port: 8443 + protocol: TCP + targetPort: https + type: ClusterIP diff --git a/charts/k8sgpt-operator-v0.0.3.tgz b/charts/k8sgpt-operator-v0.0.3.tgz new file mode 100644 index 00000000..06e75fc7 Binary files /dev/null and b/charts/k8sgpt-operator-v0.0.3.tgz differ diff --git a/index.yaml b/index.yaml index abb788a0..9d985c9c 100644 --- a/index.yaml +++ b/index.yaml @@ -1,9 +1,19 @@ apiVersion: v1 entries: k8sgpt-operator: + - apiVersion: v2 + appVersion: 0.1.0 + created: "2023-04-27T08:20:12.671029+02:00" + description: A Helm chart for Kubernetes + digest: 757ee19557e12b630f25db5bdcab4736e9d4ae80e92d547ef752bf725f65a43f + name: k8sgpt-operator + type: application + urls: + - https://charts.k8sgpt.ai/charts/k8sgpt-operator-v0.0.3.tgz + version: v0.0.3 - apiVersion: v2 appVersion: 0.2.4 - created: "2023-04-25T08:25:50.04319+02:00" + created: "2023-04-27T08:20:12.670806+02:00" description: A Helm chart for Kubernetes digest: e0dbf56b6e036a1eaf9f03a0c6a1b4a2a360a339c5b82b24a58fbc7df23a89c6 name: k8sgpt-operator @@ -13,7 +23,7 @@ entries: version: v0.0.2 - apiVersion: v2 appVersion: 0.2.4 - created: "2023-04-25T08:25:50.043085+02:00" + created: "2023-04-27T08:20:12.670506+02:00" description: A Helm chart for Kubernetes digest: cd4a0ca2651f617ff7c1b81de031d9ae9acc23f291e46dc940a51f6a01857154 name: k8sgpt-operator @@ -21,4 +31,4 @@ entries: urls: - https://charts.k8sgpt.ai/charts/k8sgpt-operator-v0.0.1.tgz version: v0.0.1 -generated: "2023-04-25T08:25:50.042531+02:00" +generated: "2023-04-27T08:20:12.670096+02:00"