diff --git a/VERSION b/VERSION index 79a2734..09a3acf 100755 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.5.0 \ No newline at end of file +0.6.0 \ No newline at end of file diff --git a/charts/interpolator/Chart.yaml b/charts/interpolator/Chart.yaml index bdd10d4..bf51e1d 100644 --- a/charts/interpolator/Chart.yaml +++ b/charts/interpolator/Chart.yaml @@ -13,10 +13,9 @@ 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.5.0 +version: 0.6.0 # 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.5.0" - +appVersion: "0.6.0" diff --git a/charts/interpolator/README.md b/charts/interpolator/README.md index a8fc243..14520df 100644 --- a/charts/interpolator/README.md +++ b/charts/interpolator/README.md @@ -2,7 +2,7 @@ -![Version: 0.5.0](https://img.shields.io/badge/Version-0.5.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.5.0](https://img.shields.io/badge/AppVersion-0.5.0-informational?style=flat-square) +![Version: 0.6.0](https://img.shields.io/badge/Version-0.6.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.6.0](https://img.shields.io/badge/AppVersion-0.6.0-informational?style=flat-square) Interpolator Helm Chart @@ -18,12 +18,13 @@ Interpolator Helm Chart | Key | Type | Default | Description | |-----|------|---------|-------------| -| controllerManager.manager.args[0] | string | `"--leader-elect"` | | -| controllerManager.manager.args[1] | string | `"--health-probe-bind-address=:8081"` | | +| controllerManager.manager.args[0] | string | `"--metrics-bind-address=:8080"` | | +| controllerManager.manager.args[1] | string | `"--leader-elect"` | | +| controllerManager.manager.args[2] | string | `"--health-probe-bind-address=:8081"` | | | controllerManager.manager.containerSecurityContext.allowPrivilegeEscalation | bool | `false` | | | controllerManager.manager.containerSecurityContext.capabilities.drop[0] | string | `"ALL"` | | | controllerManager.manager.image.repository | string | `"ghcr.io/grzegorzgniadek/interpolator-operator"` | | -| controllerManager.manager.image.tag | string | `"0.5.0"` | | +| controllerManager.manager.image.tag | string | `"0.6.0"` | | | controllerManager.manager.imagePullPolicy | string | `"Always"` | | | controllerManager.manager.resources.limits.cpu | string | `"200m"` | | | controllerManager.manager.resources.limits.memory | string | `"128Mi"` | | @@ -31,4 +32,12 @@ Interpolator Helm Chart | controllerManager.manager.resources.requests.memory | string | `"64Mi"` | | | controllerManager.replicas | int | `1` | | | controllerManager.serviceAccount.annotations | object | `{}` | | -| kubernetesClusterDomain | string | `"cluster.local"` | | \ No newline at end of file +| kubernetesClusterDomain | string | `"cluster.local"` | | +| metricsService.enabled | bool | `true` | | +| metricsService.ports[0].name | string | `"metrics"` | | +| metricsService.ports[0].port | int | `8080` | | +| metricsService.ports[0].protocol | string | `"TCP"` | | +| metricsService.ports[0].targetPort | int | `8080` | | +| metricsService.type | string | `"ClusterIP"` | | +| prometheusMonitor.enabled | bool | `false` | | +| prometheusMonitor.interval | string | `"15s"` | | \ No newline at end of file diff --git a/charts/interpolator/templates/metrics-monitor.yaml b/charts/interpolator/templates/metrics-monitor.yaml new file mode 100644 index 0000000..b828fa4 --- /dev/null +++ b/charts/interpolator/templates/metrics-monitor.yaml @@ -0,0 +1,15 @@ +{{- if .Values.prometheusMonitor.enabled -}} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ include "interpolator.fullname" . }}-metrics-monitor + labels: + {{- include "interpolator.labels" . | nindent 4 }} +spec: + endpoints: + - interval: {{ .Values.prometheusMonitor.interval }} + port: metrics + selector: + matchLabels: + control-plane: controller-manager +{{- end -}} \ No newline at end of file diff --git a/charts/interpolator/templates/metrics-service.yaml b/charts/interpolator/templates/metrics-service.yaml new file mode 100644 index 0000000..fe5e715 --- /dev/null +++ b/charts/interpolator/templates/metrics-service.yaml @@ -0,0 +1,16 @@ +{{- if .Values.metricsService.enabled -}} +apiVersion: v1 +kind: Service +metadata: + name: {{ include "interpolator.fullname" . }}-metrics-service + labels: + control-plane: controller-manager + {{- include "interpolator.labels" . | nindent 4 }} +spec: + type: {{ .Values.metricsService.type }} + selector: + control-plane: controller-manager + {{- include "interpolator.selectorLabels" . | nindent 4 }} + ports: + {{- .Values.metricsService.ports | toYaml | nindent 2 }} +{{- end -}} \ No newline at end of file diff --git a/charts/interpolator/values.yaml b/charts/interpolator/values.yaml index 67c216a..f94ace9 100644 --- a/charts/interpolator/values.yaml +++ b/charts/interpolator/values.yaml @@ -1,6 +1,7 @@ controllerManager: manager: args: + - --metrics-bind-address=:8080 - --leader-elect - --health-probe-bind-address=:8081 containerSecurityContext: @@ -10,7 +11,7 @@ controllerManager: - ALL image: repository: ghcr.io/grzegorzgniadek/interpolator-operator - tag: 0.5.0 + tag: 0.6.0 imagePullPolicy: Always resources: limits: @@ -23,3 +24,14 @@ controllerManager: serviceAccount: annotations: {} kubernetesClusterDomain: cluster.local +metricsService: + enabled: true + ports: + - name: metrics + port: 8080 + protocol: TCP + targetPort: 8080 + type: ClusterIP +prometheusMonitor: + enabled: false + interval: 15s diff --git a/config/default/kustomization.yaml b/config/default/kustomization.yaml index 65aa432..32ae286 100644 --- a/config/default/kustomization.yaml +++ b/config/default/kustomization.yaml @@ -1,5 +1,6 @@ # Adds namespace to all resources. namespace: interpolator-system +namePrefix: interpolator- # Value of this field is prepended to the # names of all resources, e.g. a deployment named # "wordpress" becomes "alices-wordpress". @@ -22,18 +23,16 @@ resources: # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required. #- ../certmanager # [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'. -#- ../prometheus -# [METRICS] To enable the controller manager metrics service, uncomment the following line. -#- metrics_service.yaml +- ../prometheus # Uncomment the patches line if you enable Metrics, and/or are using webhooks and cert-manager -#patches: +patches: # [METRICS] The following patch will enable the metrics endpoint. Ensure that you also protect this endpoint. # More info: https://book.kubebuilder.io/reference/metrics # If you want to expose the metric endpoint of your controller-manager uncomment the following line. -#- path: manager_metrics_patch.yaml -# target: -# kind: Deployment +- path: manager_metrics_patch.yaml + target: + kind: Deployment # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in # crd/kustomization.yaml @@ -46,7 +45,6 @@ resources: # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix. # Uncomment the following replacements to add the cert-manager CA injection annotations -#replacements: # - source: # Add cert-manager annotation to ValidatingWebhookConfiguration, MutatingWebhookConfiguration and CRDs # kind: Certificate # group: cert-manager.io @@ -143,3 +141,19 @@ resources: # delimiter: '.' # index: 1 # create: true +replacements: + - source: + kind: Deployment + name: controller-manager + fieldPath: .metadata.namespace + targets: + - select: + kind: ClusterRoleBinding + name: manager-rolebinding + fieldPaths: + - .subjects.0.namespace + - select: + kind: RoleBinding + name: leader-election-rolebinding + fieldPaths: + - .subjects.0.namespace \ No newline at end of file diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 0cec405..0a65c7a 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,8 +1,10 @@ resources: - manager.yaml + # [METRICS] To enable the controller manager metrics service, uncomment the following line. + - metrics_service.yaml apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization images: - name: controller newName: ghcr.io/grzegorzgniadek/interpolator-operator - newTag: "0.5.0" + newTag: "0.6.0" diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 92f5b37..dc03282 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -5,7 +5,7 @@ metadata: control-plane: controller-manager app.kubernetes.io/name: interpolator-operator app.kubernetes.io/managed-by: kustomize - name: interpolator-operator-system + name: system --- apiVersion: apps/v1 kind: Deployment diff --git a/config/default/metrics_service.yaml b/config/manager/metrics_service.yaml similarity index 87% rename from config/default/metrics_service.yaml rename to config/manager/metrics_service.yaml index e0f20c4..d028669 100644 --- a/config/default/metrics_service.yaml +++ b/config/manager/metrics_service.yaml @@ -5,7 +5,7 @@ metadata: control-plane: controller-manager app.kubernetes.io/name: interpolator-operator app.kubernetes.io/managed-by: kustomize - name: controller-manager-metrics-service + name: metrics-service spec: ports: - name: http diff --git a/config/prometheus/monitor.yaml b/config/prometheus/monitor.yaml index c9209ad..c1a2691 100644 --- a/config/prometheus/monitor.yaml +++ b/config/prometheus/monitor.yaml @@ -6,7 +6,7 @@ metadata: control-plane: controller-manager app.kubernetes.io/name: interpolator-operator app.kubernetes.io/managed-by: kustomize - name: controller-manager-metrics-monitor + name: metrics-monitor spec: endpoints: - path: /metrics diff --git a/config/rbac/interpolator_editor_role.yaml b/config/rbac/editor_role.yaml similarity index 100% rename from config/rbac/interpolator_editor_role.yaml rename to config/rbac/editor_role.yaml diff --git a/config/rbac/kustomization.yaml b/config/rbac/kustomization.yaml index b8dcf41..ec7dd0b 100644 --- a/config/rbac/kustomization.yaml +++ b/config/rbac/kustomization.yaml @@ -14,6 +14,5 @@ resources: # default, aiding admins in cluster management. Those roles are # not used by the Project itself. You can comment the following lines # if you do not want those helpers be installed with your Project. -- interpolator_editor_role.yaml -- interpolator_viewer_role.yaml - +- editor_role.yaml +- viewer_role.yaml diff --git a/config/rbac/interpolator_viewer_role.yaml b/config/rbac/viewer_role.yaml similarity index 100% rename from config/rbac/interpolator_viewer_role.yaml rename to config/rbac/viewer_role.yaml diff --git a/internal/controller/interpolator_controller.go b/internal/controller/interpolator_controller.go index 26097cd..a602ad9 100644 --- a/internal/controller/interpolator_controller.go +++ b/internal/controller/interpolator_controller.go @@ -74,6 +74,16 @@ func (r *InterpolatorReconciler) Reconcile(ctx context.Context, req ctrl.Request // Fetch the Interpolator instance interpolator := &interpolatorv1.Interpolator{} + interpolatorList := &interpolatorv1.InterpolatorList{} + + if err := r.List(ctx, interpolatorList); err != nil { + log.Error(err, "failed to list custom resources") + + return ctrl.Result{}, nil + } + count := len(interpolatorList.Items) + interCount.Set(float64(count)) + err := r.Get(ctx, req.NamespacedName, interpolator) if err != nil { if apierrors.IsNotFound(err) { diff --git a/internal/controller/metrics.go b/internal/controller/metrics.go new file mode 100755 index 0000000..49aad76 --- /dev/null +++ b/internal/controller/metrics.go @@ -0,0 +1,20 @@ +package controller + +import ( + "github.com/prometheus/client_golang/prometheus" + "sigs.k8s.io/controller-runtime/pkg/metrics" +) + +var ( + interCount = prometheus.NewGauge( + prometheus.GaugeOpts{ + Name: "inter_count", + Help: "Count of inter resources", + }, + ) +) + +func init() { + // Register custom metrics with the global prometheus registry + metrics.Registry.MustRegister(interCount) +}