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

feat: Add Kustomize files for unit testing #30

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/kustomize/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Structure

The `kustomize` folder contains the Kustomize resources that are used to assemble the operator's deployment units for testing

```
.
├── certmanager # Kustomize options dealing with cert-manager
├── crd # Kustomize options for our CRDs
│   ├── bases # auto generated based on the code annotations (`make manifests`)
│   └── patches # patches to apply to the generated CRD
├── default # Kustomize's "entry point", generating the distribution YAML file
├── manager # the operator's Deployment
├── manifests # the resulting CSV
│   └── bases
├── prometheus # ServiceMonitor that exposes our operator's metrics
├── rbac # RBAC rules
├── samples # Set of examples of how to accomplish specific scenarios. Those are bundled in the final CSV
└── webhook # Webhook configuration and service
```
29 changes: 29 additions & 0 deletions tests/kustomize/certmanager/certificate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# The following manifests contain a self-signed issuer CR and a certificate CR.
# More document can be found at https://docs.cert-manager.io
# WARNING: Targets CertManager 0.11 check https://docs.cert-manager.io/en/latest/tasks/upgrading/index.html for
# breaking changes
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: selfsigned-issuer
namespace: system
spec:
selfSigned: {}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: serving-cert # this name should match the one appeared in kustomizeconfig.yaml
namespace: system
spec:
# $(SERVICE_NAME) and $(SERVICE_NAMESPACE) will be substituted by kustomize
dnsNames:
- $(SERVICE_NAME).$(SERVICE_NAMESPACE).svc
- $(SERVICE_NAME).$(SERVICE_NAMESPACE).svc.cluster.local
issuerRef:
kind: Issuer
name: selfsigned-issuer
secretName: k8s-agents-operator-controller-manager-service-cert # this secret will not be prefixed, since it's not managed by kustomize
subject:
organizationalUnits:
- "k8s-agents-operator"
5 changes: 5 additions & 0 deletions tests/kustomize/certmanager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resources:
- certificate.yaml

configurations:
- kustomizeconfig.yaml
16 changes: 16 additions & 0 deletions tests/kustomize/certmanager/kustomizeconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This configuration is for teaching kustomize how to update name ref and var substitution
nameReference:
- kind: Issuer
group: cert-manager.io
fieldSpecs:
- kind: Certificate
group: cert-manager.io
path: spec/issuerRef/name

varReference:
- kind: Certificate
group: cert-manager.io
path: spec/commonName
- kind: Certificate
group: cert-manager.io
path: spec/dnsNames
1,021 changes: 1,021 additions & 0 deletions tests/kustomize/crd/bases/newrelic.com_instrumentations.yaml

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions tests/kustomize/crd/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This kustomization.yaml is not intended to be run by itself,
# since it depends on service name and namespace that are out of this kustomize package.
# It should be run by config/default
resources:
- bases/newrelic.com_instrumentations.yaml
# +kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
# patches here are for enabling the conversion webhook for each CRD
# +kubebuilder:scaffold:crdkustomizewebhookpatch

# patches here are for enabling the CA injection for each CRD
# +kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
configurations:
- kustomizeconfig.yaml
17 changes: 17 additions & 0 deletions tests/kustomize/crd/kustomizeconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file is for teaching kustomize how to substitute name and namespace reference in CRD
nameReference:
- kind: Service
version: v1
fieldSpecs:
- kind: CustomResourceDefinition
group: apiextensions.k8s.io
path: spec/conversion/webhookClientConfig/service/name

namespace:
- kind: CustomResourceDefinition
group: apiextensions.k8s.io
path: spec/conversion/webhookClientConfig/service/namespace
create: false

varReference:
- path: metadata/annotations
60 changes: 60 additions & 0 deletions tests/kustomize/default/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Adds namespace to all resources.
namespace: k8s-agents-operator-system

# Value of this field is prepended to the
# names of all resources, e.g. a deployment named
# "wordpress" becomes "alices-wordpress".
# Note that it should also match with the prefix (text before '-') of the namespace
# field above.
namePrefix: k8s-agents-operator-

# Labels to add to all resources and selectors.
commonLabels:
app.kubernetes.io/name: k8s-agents-operator

bases:
- ../crd
- ../rbac
- ../manager
- ../webhook
- ../certmanager
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
#- ../prometheus

patchesStrategicMerge:
# Protect the /metrics endpoint by putting it behind auth.
# If you want your controller-manager to expose the /metrics
# endpoint w/o any authn/z, please comment the following line.
- manager_auth_proxy_patch.yaml

- manager_webhook_patch.yaml
- webhookcainjection_patch.yaml

# the following config is for teaching kustomize how to do var substitution
vars:
- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
objref:
kind: Certificate
group: cert-manager.io
version: v1
name: serving-cert # this name should match the one in certificate.yaml
fieldref:
fieldpath: metadata.namespace
- name: CERTIFICATE_NAME
objref:
kind: Certificate
group: cert-manager.io
version: v1
name: serving-cert # this name should match the one in certificate.yaml
- name: SERVICE_NAMESPACE # namespace of the service
objref:
kind: Service
version: v1
name: webhook-service
fieldref:
fieldpath: metadata.namespace
- name: SERVICE_NAME
objref:
kind: Service
version: v1
name: webhook-service
35 changes: 35 additions & 0 deletions tests/kustomize/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This patch inject a sidecar container which is a HTTP proxy for the
# controller manager, it performs RBAC authorization against the Kubernetes API using SubjectAccessReviews.
apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
spec:
template:
spec:
containers:
- name: kube-rbac-proxy
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.13.0
args:
- "--secure-listen-address=0.0.0.0:8443"
- "--upstream=http://127.0.0.1:8080/"
- "--logtostderr=true"
- "--v=0"
ports:
- containerPort: 8443
name: https
protocol: TCP
resources:
limits:
cpu: 500m
memory: 128Mi
requests:
cpu: 5m
memory: 64Mi
- name: manager
args:
- "--metrics-addr=127.0.0.1:8080"
- "--enable-leader-election"
- "--zap-log-level=info"
- "--zap-time-encoding=rfc3339nano"
23 changes: 23 additions & 0 deletions tests/kustomize/default/manager_webhook_patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
spec:
template:
spec:
containers:
- name: manager
ports:
- containerPort: 9443
name: webhook-server
protocol: TCP
volumeMounts:
- mountPath: /tmp/k8s-webhook-server/serving-certs
name: cert
readOnly: true
volumes:
- name: cert
secret:
defaultMode: 420
secretName: k8s-agents-operator-controller-manager-service-cert
15 changes: 15 additions & 0 deletions tests/kustomize/default/webhookcainjection_patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This patch add annotation to admission webhook config and
# the variables $(CERTIFICATE_NAMESPACE) and $(CERTIFICATE_NAME) will be substituted by kustomize.
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: mutating-webhook-configuration
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: validating-webhook-configuration
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
8 changes: 8 additions & 0 deletions tests/kustomize/manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resources:
- manager.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: newrelic/k8s-agents-operator
newTag: latest
51 changes: 51 additions & 0 deletions tests/kustomize/manager/manager.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
apiVersion: v1
kind: Namespace
metadata:
labels:
app.kubernetes.io/name: k8s-agents-operator
control-plane: controller-manager
name: system
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
labels:
app.kubernetes.io/name: k8s-agents-operator
control-plane: controller-manager
spec:
selector:
matchLabels:
app.kubernetes.io/name: k8s-agents-operator
control-plane: controller-manager
replicas: 1
template:
metadata:
labels:
app.kubernetes.io/name: k8s-agents-operator
control-plane: controller-manager
spec:
containers:
- args:
- --enable-leader-election
image: controller
name: manager
livenessProbe:
httpGet:
path: /healthz
port: 8081
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /readyz
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
resources:
requests:
cpu: 100m
memory: 64Mi
serviceAccountName: controller-manager
terminationGracePeriodSeconds: 10
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
apiVersion: operators.coreos.com/v1alpha1
kind: ClusterServiceVersion
metadata:
annotations:
alm-examples: '[]'
capabilities: Basic Install
name: k8s-agents-operator.v0.0.0
namespace: placeholder
spec:
apiservicedefinitions: {}
customresourcedefinitions:
owned:
- description: Instrumentation is the Schema for the instrumentations API
displayName: New Relic Instrumentation
kind: Instrumentation
name: instrumentations.newrelic.com
resources:
- kind: Pod
name: ""
version: v1
version: v1alpha1
description: The New Relic agent operator is an admission controller API that enables
the instrumentation of application workloads (including Java, NodeJS, Go, DotNet,
PHP, and Python) using a custom resource definition.
displayName: New Relic Agent Operator
icon:
- base64data: "PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA4MTkgMTU4Ljk3Ij48ZGVmcz48c3R5bGU+LmNscy0xe2ZpbGw6IzAwYW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A5Ljc4IDY0NS42MyAyNy4xMSIvPjxyZWN0IGNsYXNzPSJjbHMtMyIgeD0iNjkyLjE0IiB5PSI0MS4xOSIgd2lkdGg9IjE5LjUiIGhlaWdodD0iNzkuNTYiLz48cGF0aCBjbGFzcz0iY2xzLTMiIGQ9Ik04MjEuNTksMTE2YTcuNTIsNy41MiwwLDEsMCw3LjQxLDcuNTJBNy4yOCw3LjI4LDAsMCwwLDgyMS41OSwxMTZabTAsMTMuODlhNi4zNyw2LjM3LDAsMSwxLDYuMjYtNi4zN0E2LjEyLDYuMTIsMCwwLDEsODIxLjU5LDEyOS44NVoiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0xMCAtMTAuNTEpIi8+PHBhdGggY2xhc3M9ImNscy0zIiBkPSJNODI0LjgyLDEyMi4xM2EyLjY0LDIuNjQsMCwwLDAtMi44Mi0yLjYyaC0zLjM0djcuODRoMS4xNXYtMi43MmgxLjA1bDIuNzEsMi43Mkg4MjVsLTIuNzEtMi43MkEyLjUzLDIuNTMsMCwwLDAsODI0LjgyLDEyMi4xM1ptLTUsMS4zNXYtMi44Mkg4MjJhMS41LDEuNSwwLDAsMSwxLjY4LDEuNDdjMCwuODMtLjUzLDEuMzUtMS42OCwxLjM1WiIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTEwIC0xMC41MSkiLz48L3N2Zz4="
mediatype: "image/svg+xml"
install:
spec:
deployments: null
strategy: ""
installModes:
- supported: false
type: OwnNamespace
- supported: false
type: SingleNamespace
- supported: false
type: MultiNamespace
- supported: true
type: AllNamespaces
keywords:
- newrelic
- instrumentation
- apm
links:
- name: Newrelic Agent Operator
url: https://k8s-agents-operator.domain
maintainers:
- email: alozoya@newrelic.com
name: Andrew Lozoya
maturity: alpha
provider:
name: New Relic
url: newrelic.com
version: 0.0.0
4 changes: 4 additions & 0 deletions tests/kustomize/manifests/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resources:
- ../default
- ../samples
- ../scorecard
2 changes: 2 additions & 0 deletions tests/kustomize/prometheus/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
resources:
- monitor.yaml
26 changes: 26 additions & 0 deletions tests/kustomize/prometheus/monitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

# Prometheus Monitor Service (Metrics)
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
app.kubernetes.io/name: k8s-agents-operator
control-plane: controller-manager
name: controller-manager-metrics-monitor
namespace: system
spec:
endpoints:
- path: /metrics
port: https
scheme: https
bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
tlsConfig:
insecureSkipVerify: false
ca:
secret:
key: ca.crt
name: k8s-agents-operator-controller-manager-service-cert
selector:
matchLabels:
app.kubernetes.io/name: k8s-agents-operator
control-plane: controller-manager
Loading
Loading