Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

agent mode support #227

Merged
merged 10 commits into from
Aug 10, 2023
4 changes: 2 additions & 2 deletions charts/zora/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ name: zora
description: Zora scans multiple Kubernetes clusters and reports potential issues.
icon: https://zora-docs.undistro.io/assets/logo.png
type: application
version: 0.6.2
appVersion: "v0.6.2"
version: 0.7.0-rc2
appVersion: "v0.7.0-rc2"
sources:
- https://github.com/undistro/zora
6 changes: 4 additions & 2 deletions charts/zora/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Zora Helm Chart

![Version: 0.6.2](https://img.shields.io/badge/Version-0.6.2-informational?style=flat-square&color=3CA9DD) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square&color=3CA9DD) ![AppVersion: v0.6.2](https://img.shields.io/badge/AppVersion-v0.6.2-informational?style=flat-square&color=3CA9DD)
![Version: 0.7.0-rc2](https://img.shields.io/badge/Version-0.7.0--rc2-informational?style=flat-square&color=3CA9DD) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square&color=3CA9DD) ![AppVersion: v0.7.0-rc2](https://img.shields.io/badge/AppVersion-v0.7.0--rc2-informational?style=flat-square&color=3CA9DD)

Zora scans multiple Kubernetes clusters and reports potential issues.

Expand All @@ -12,7 +12,7 @@ To install the chart with the release name `zora`:
helm repo add undistro https://charts.undistro.io --force-update
helm upgrade --install zora undistro/zora \
-n zora-system \
--version 0.6.2 \
--version 0.7.0-rc2 \
--create-namespace --wait
```

Expand Down Expand Up @@ -54,6 +54,8 @@ The following table lists the configurable parameters of the Zora chart and thei
|-----|------|---------|-------------|
| nameOverride | string | `""` | String to partially override fullname template with a string (will prepend the release name) |
| fullnameOverride | string | `""` | String to fully override fullname template with a string |
| clusterName | string | `""` | Cluster name. Should be set by `kubectl config current-context`. |
| scanSchedule | string | Cron expression for every hour at the current minute + 5 minutes | Cluster scan schedule in Cron format |
| saas.workspaceID | string | `""` | Your SaaS workspace ID |
| saas.server | string | `"https://zora-dashboard.undistro.io"` | SaaS server URL |
| saas.hooks.image.repository | string | `"curlimages/curl"` | SaaS hooks image repository |
Expand Down
19 changes: 13 additions & 6 deletions charts/zora/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
1. Connect clusters with `kubectl`:
Thank you for installing {{ .Chart.Name | title }} version {{ .Chart.Version }}.

For in-depth information about how to connect a cluster, visit
https://zora-docs.undistro.io/
{{ if .Values.clusterName -}}
Cluster `{{ .Values.clusterName }}` is scheduled to be scanned. Check it by running:
kubectl get cluster,clusterscan -o wide -n {{ .Release.Namespace }}

{{- if .Values.saas.workspaceID }}
2. Now you can see your clusters and issues in the SaaS:
{{ .Values.saas.server }}
Once a cluster is successfully scanned, you can check issues by running:
kubectl get clusterissues -n {{ .Release.Namespace }}

{{ end -}}

Visit our documentation for in-depth information: https://zora-docs.undistro.io

{{ if .Values.saas.workspaceID -}}
You can see your clusters and issues in SaaS: {{ .Values.saas.server }}
{{- end }}
8 changes: 8 additions & 0 deletions charts/zora/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,11 @@ Create the name of the service account to use in Operator
{{- printf "{\"auths\":{\"%s\":{\"auth\":\"%s\"}}}" .registry (printf "%s:%s" .username .password | b64enc) | b64enc }}
{{- end }}
{{- end }}

{{- define "clusterName" }}
{{- regexReplaceAll "\\W+" (required "clusterName is required" .Values.clusterName) "-" }}
{{- end }}

{{- define "scanSchedule"}}
{{- default (printf "%d * * * *" (add 5 (now | date "04"))) .Values.scanSchedule }}
{{- end }}
33 changes: 33 additions & 0 deletions charts/zora/templates/cluster/cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2023 Undistro Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
{{ if .Values.clusterName }}
apiVersion: zora.undistro.io/v1alpha1
kind: Cluster
metadata:
labels:
{{- include "zora.labels" . | nindent 4 }}
name: {{ include "clusterName" . }}
spec: {}
---
apiVersion: zora.undistro.io/v1alpha1
kind: ClusterScan
metadata:
labels:
{{- include "zora.labels" . | nindent 4 }}
name: {{ include "clusterName" . }}
spec:
clusterRef:
name: {{ include "clusterName" . }}
schedule: {{ include "scanSchedule" . | quote }}
{{- end }}
2 changes: 1 addition & 1 deletion charts/zora/templates/plugins/marvin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ spec:
mkdir -p $(CUSTOM_CHECKS_PATH)
ls -lh $(CUSTOM_CHECKS_PATH)
echo Scanning...
/marvin scan --disable-annotation-skip -f $(CUSTOM_CHECKS_PATH) -o json -v 2 --kubeconfig $(KUBECONFIG) > $(DONE_DIR)/results.json
/marvin scan --disable-annotation-skip -f $(CUSTOM_CHECKS_PATH) -o json -v 2 > $(DONE_DIR)/results.json
exitcode=$(echo $?)
if [ $exitcode -ne 0 ]; then
echo "ERROR" > $(DONE_DIR)/error
Expand Down
1 change: 0 additions & 1 deletion charts/zora/templates/plugins/popeye.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ spec:
POPEYE_REPORT_DIR=$(DONE_DIR) \
/bin/popeye \
-o json \
--kubeconfig $(KUBECONFIG) \
{{- if .Values.scan.plugins.popeye.skipInternalResources }}
-f /tmp/spinach.yml \
{{- end }}
Expand Down
80 changes: 57 additions & 23 deletions charts/zora/templates/plugins/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,66 @@ kind: ClusterRole
metadata:
name: zora-plugins
rules:
- apiGroups:
- zora.undistro.io
- apiGroups: [ "zora.undistro.io" ]
resources:
- clusterissues
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- zora.undistro.io
verbs: [ "create", "delete", "get", "list", "patch", "update", "watch" ]
- apiGroups: [ "zora.undistro.io" ]
resources:
- clusterissues/status
verbs:
- get
- apiGroups:
- ""
verbs: [ "get" ]
- apiGroups: [ "" ]
resources:
- configmaps
verbs:
- get
- list
- endpoints
- limitranges
- namespaces
- nodes
- persistentvolumes
- persistentvolumeclaims
- pods
- secrets
- serviceaccounts
- services
verbs: [ "get", "list" ]
- apiGroups: [ "apps" ]
resources:
- daemonsets
- deployments
- statefulsets
- replicasets
verbs: [ "get", "list" ]
- apiGroups: [ "autoscaling" ]
resources:
- horizontalpodautoscalers
verbs: [ "get", "list" ]
- apiGroups: [ "networking.k8s.io" ]
resources:
- ingresses
- networkpolicies
verbs: [ "get", "list" ]
- apiGroups: [ "policy" ]
resources:
- poddisruptionbudgets
- podsecuritypolicies
verbs: [ "get", "list" ]
- apiGroups: [ "rbac.authorization.k8s.io" ]
resources:
- clusterroles
- clusterrolebindings
- roles
- rolebindings
verbs: [ "get", "list" ]
- apiGroups: [ "metrics.k8s.io" ]
resources:
- pods
- nodes
verbs: [ "get", "list" ]
- apiGroups: [ batch ]
resources:
- jobs
- cronjobs
verbs: [ "get", "list" ]
---
{{ $crb := (lookup "rbac.authorization.k8s.io/v1" "ClusterRoleBinding" "" "zora-plugins-rolebinding") }}
apiVersion: rbac.authorization.k8s.io/v1
Expand All @@ -52,13 +87,12 @@ roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: zora-plugins
{{- if $crb }}
subjects:
- kind: ServiceAccount
name: {{ include "zora.operatorServiceAccountName" . }}
namespace: {{ .Release.Namespace }}
{{- range $s := $crb.subjects }}
- kind: {{ $s.kind }}
name: {{ $s.name }}
namespace: {{ $s.namespace }}
{{- end }}
{{- else }}
subjects: []
{{- end }}
7 changes: 7 additions & 0 deletions charts/zora/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ nameOverride: ""
# -- String to fully override fullname template with a string
fullnameOverride: ""

# -- Cluster name. Should be set by `kubectl config current-context`.
clusterName: ""

# -- Cluster scan schedule in Cron format
# @default -- Cron expression for every hour at the current minute + 5 minutes
scanSchedule: ""

saas:
# -- Your SaaS workspace ID
workspaceID: ""
Expand Down
73 changes: 54 additions & 19 deletions config/rbac/zora_plugins_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,63 @@ metadata:
app.kubernetes.io/managed-by: kustomize
name: zora-plugins
rules:
- apiGroups:
- zora.undistro.io
- apiGroups: [ "zora.undistro.io" ]
resources:
- clusterissues
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- zora.undistro.io
verbs: [ "create", "delete", "get", "list", "patch", "update", "watch" ]
- apiGroups: [ "zora.undistro.io" ]
resources:
- clusterissues/status
verbs:
- get
- apiGroups:
- ""
verbs: [ "get" ]
- apiGroups: [ "" ]
resources:
- configmaps
verbs:
- get
- list
- endpoints
- limitranges
- namespaces
- nodes
- persistentvolumes
- persistentvolumeclaims
- pods
- secrets
- serviceaccounts
- services
verbs: [ "get", "list" ]
- apiGroups: [ "apps" ]
resources:
- daemonsets
- deployments
- statefulsets
- replicasets
verbs: [ "get", "list" ]
- apiGroups: [ "autoscaling" ]
resources:
- horizontalpodautoscalers
verbs: [ "get", "list" ]
- apiGroups: [ "networking.k8s.io" ]
resources:
- ingresses
- networkpolicies
verbs: [ "get", "list" ]
- apiGroups: [ "policy" ]
resources:
- poddisruptionbudgets
- podsecuritypolicies
verbs: [ "get", "list" ]
- apiGroups: [ "rbac.authorization.k8s.io" ]
resources:
- clusterroles
- clusterrolebindings
- roles
- rolebindings
verbs: [ "get", "list" ]
- apiGroups: [ "metrics.k8s.io" ]
resources:
- pods
- nodes
verbs: [ "get", "list" ]
- apiGroups: [ batch ]
resources:
- jobs
- cronjobs
verbs: [ "get", "list" ]
4 changes: 1 addition & 3 deletions config/samples/zora_v1alpha1_cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ metadata:
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/created-by: zora
name: mycluster
spec:
kubeconfigRef:
name: mycluster-kubeconfig
spec: {}
2 changes: 1 addition & 1 deletion config/samples/zora_v1alpha1_plugin_marvin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
mkdir -p $(CUSTOM_CHECKS_PATH)
ls -lh $(CUSTOM_CHECKS_PATH)
echo Scanning...
/marvin scan --disable-annotation-skip -f $(CUSTOM_CHECKS_PATH) -o json -v 2 --kubeconfig $(KUBECONFIG) > $(DONE_DIR)/results.json
/marvin scan --disable-annotation-skip -f $(CUSTOM_CHECKS_PATH) -o json -v 2 > $(DONE_DIR)/results.json
exitcode=$(echo $?)
if [ $exitcode -ne 0 ]; then
echo "ERROR" > $(DONE_DIR)/error
Expand Down
1 change: 0 additions & 1 deletion config/samples/zora_v1alpha1_plugin_popeye.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ spec:
POPEYE_REPORT_DIR=$(DONE_DIR) \
/bin/popeye \
-o json \
--kubeconfig $(KUBECONFIG) \
--all-namespaces \
--force-exit-zero \
-f /tmp/spinach.yml \
Expand Down
1 change: 0 additions & 1 deletion config/samples/zora_v1alpha1_plugin_popeye_all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ spec:
POPEYE_REPORT_DIR=$(DONE_DIR) \
/bin/popeye \
-o json \
--kubeconfig $(KUBECONFIG) \
--all-namespaces \
--force-exit-zero \
--save \
Expand Down
20 changes: 12 additions & 8 deletions internal/controller/zora/clusterscan_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,16 @@ func (r *ClusterScanReconciler) reconcile(ctx context.Context, clusterscan *v1al
log.Error(notReadyErr, "Cluster is not ready")
clusterscan.SetReadyStatus(false, "ClusterNotReady", notReadyErr.Error())
}
kubeconfigKey := cluster.KubeconfigRefKey()
kubeconfigSecret, err := kubeconfig.SecretFromRef(ctx, r.Client, *kubeconfigKey)
if err != nil {
log.Error(err, fmt.Sprintf("failed to get kubeconfig secret %s", kubeconfigKey.String()))
clusterscan.SetReadyStatus(false, "ClusterKubeconfigError", err.Error())
return err
var kubeconfigSecret *corev1.Secret
if cluster.Spec.KubeconfigRef != nil {
key := cluster.KubeconfigRefKey()
sec, err := kubeconfig.SecretFromRef(ctx, r.Client, *key)
if err != nil {
log.Error(err, fmt.Sprintf("failed to get kubeconfig secret %s", key.String()))
clusterscan.SetReadyStatus(false, "ClusterKubeconfigError", err.Error())
return err
}
kubeconfigSecret = sec
}

if err := r.setControllerReference(ctx, clusterscan, cluster); err != nil {
Expand All @@ -193,7 +197,7 @@ func (r *ClusterScanReconciler) reconcile(ctx context.Context, clusterscan *v1al
clusterscan.SetReadyStatus(false, "PluginFetchError", err.Error())
return err
}
cronJob := plugins.NewCronJob(fmt.Sprintf("%s-%s", clusterscan.Name, plugin.Name), kubeconfigSecret.Namespace)
cronJob := plugins.NewCronJob(fmt.Sprintf("%s-%s", clusterscan.Name, plugin.Name), clusterscan.Namespace)
cronJobMutator := &plugins.CronJobMutator{
Scheme: r.Scheme,
Existing: cronJob,
Expand Down Expand Up @@ -441,7 +445,7 @@ func (r *ClusterScanReconciler) defaultPlugins() []v1alpha1.PluginReference {
return p
}

// applyRBAC Create or Update a ServiceAccount (with ClusterScan as Owner) and append it to ClusterRoleBinding
// applyRBAC Create or Update a ServiceAccount in the ClusterScan namespace (with ClusterScan as Owner) and append it to ClusterRoleBinding
func (r *ClusterScanReconciler) applyRBAC(ctx context.Context, clusterscan *v1alpha1.ClusterScan) error {
log := ctrllog.FromContext(ctx)

Expand Down
Loading