Skip to content

Commit

Permalink
test(chart): add helm unittest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
basti1302 committed Jun 6, 2024
1 parent 03205e2 commit 2d4d71f
Show file tree
Hide file tree
Showing 23 changed files with 818 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ jobs:
run: |
make lint
- name: install Helm unittest plugin
shell: bash
run: |
helm plugin install https://github.com/helm-unittest/helm-unittest.git
- name: test
run: |
make test
Expand Down
8 changes: 7 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Contributing
- Docker
- kubectl version v1.11.3+.
- Access to a Kubernetes v1.11.3+ cluster.
- [helm](https://helm.sh/docs/intro/install/)
- [helm unittest plug-in](https://github.com/helm-unittest/helm-unittest/tree/main)

## Deploying to a Local Cluster for Testing Purposes

Expand Down Expand Up @@ -79,12 +81,17 @@ make undeploy-via-kustomize

When undeploying the controllor, the same tool (helm vs. kustomiz) should be used as when deploying it.

This will also remove the custom resource definition. However, the custom resource definition can also be removed
separately via `make uninstall` without removing the operator.

## Run Tests

```
make test
```

This will run the go unit tests as well as the helm chart tests.

### End-to-End Tests

The end-to-end tests currently only support Kubernetes via Docker Desktop on Mac.
Expand All @@ -102,4 +109,3 @@ More information can be found via the [Kubebuilder Documentation](https://book.k
## Contributing

No contribution guidelines are available at this point.

1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ vet: ## Run go vet against code.
.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
cd helm-chart/dash0-operator && helm unittest -f 'tests/**/*.yaml' .

# Invoking ginkgo via go run makes sure we use the version from go.mod and not a version installed globally, which
# would be used when simply running `ginkgo -v test/e2e`. An alternative would be to invoke ginkgo via go test, that
Expand Down
1 change: 1 addition & 0 deletions helm-chart/dash0-operator/.helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*.tmp
*.orig
*~
tests/
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
cluster role bindings should match snapshot:
1: |
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
app.kubernetes.io/component: rbac
app.kubernetes.io/instance: manager-rolebinding
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: clusterrolebinding
app.kubernetes.io/part-of: dash0-operator
app.kubernetes.io/version: 1.0.0
helm.sh/chart: dash0-operator-1.0.0
name: dash0-operator-manager-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: dash0-operator-manager-role
subjects:
- kind: ServiceAccount
name: dash0-operator-controller-manager
namespace: NAMESPACE
2: |
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
app.kubernetes.io/component: kube-rbac-proxy
app.kubernetes.io/instance: proxy-rolebinding
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: clusterrolebinding
app.kubernetes.io/part-of: dash0-operator
app.kubernetes.io/version: 1.0.0
helm.sh/chart: dash0-operator-1.0.0
name: dash0-operator-proxy-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: dash0-operator-proxy-role
subjects:
- kind: ServiceAccount
name: dash0-operator-controller-manager
namespace: NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
cluster roles should match snapshot:
1: |
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: dash0-operator-manager-role
rules:
- apiGroups:
- apps
resources:
- daemonsets
- deployments
- replicasets
- statefulsets
verbs:
- get
- list
- patch
- update
- watch
- apiGroups:
- batch
resources:
- cronjobs
- jobs
verbs:
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
- events
verbs:
- create
- apiGroups:
- ""
resources:
- namespaces
verbs:
- get
- apiGroups:
- operator.dash0.com
resources:
- dash0s
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- operator.dash0.com
resources:
- dash0s/finalizers
verbs:
- update
- apiGroups:
- operator.dash0.com
resources:
- dash0s/status
verbs:
- get
- patch
- update
2: |
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/component: kube-rbac-proxy
app.kubernetes.io/instance: metrics-reader
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: clusterrole
app.kubernetes.io/part-of: dash0-operator
app.kubernetes.io/version: 1.0.0
helm.sh/chart: dash0-operator-1.0.0
name: dash0-operator-metrics-reader
rules:
- nonResourceURLs:
- /metrics
verbs:
- get
3: |
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/component: kube-rbac-proxy
app.kubernetes.io/instance: proxy-role
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: clusterrole
app.kubernetes.io/part-of: dash0-operator
app.kubernetes.io/version: 1.0.0
helm.sh/chart: dash0-operator-1.0.0
name: dash0-operator-proxy-role
rules:
- apiGroups:
- authentication.k8s.io
resources:
- tokenreviews
verbs:
- create
- apiGroups:
- authorization.k8s.io
resources:
- subjectaccessreviews
verbs:
- create
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
custom resource definition should match snapshot:
1: |
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: NAMESPACE/dash0-operator-serving-cert
controller-gen.kubebuilder.io/version: v0.14.0
name: dash0s.operator.dash0.com
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
name: dash0-operator-webhook-service
namespace: NAMESPACE
path: /convert
conversionReviewVersions:
- v1
group: operator.dash0.com
names:
kind: Dash0
listKind: Dash0List
plural: dash0s
singular: dash0
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: Dash0 is the Schema for the dash0s 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: Dash0Spec defines the desired state of the Dash0 custom resource.
type: object
status:
description: Dash0Status defines the observed state of the Dash0 custom resource.
properties:
conditions:
items:
description: |-
Condition contains details for one aspect of the current state of this API Resource.
---
This struct is intended for direct use as an array at the field path .status.conditions. For example,


type FooStatus struct{
// Represents the observations of a foo's current state.
// Known .status.conditions.type are: "Available", "Progressing", and "Degraded"
// +patchMergeKey=type
// +patchStrategy=merge
// +listType=map
// +listMapKey=type
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`


// other fields
}
properties:
lastTransitionTime:
description: |-
lastTransitionTime is the last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: |-
message is a human readable message indicating details about the transition.
This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: |-
observedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: |-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
Producers of specific condition types may define expected values and meanings for this field,
and whether the values are considered a guaranteed API.
The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: |-
type of condition in CamelCase or in foo.example.com/CamelCase.
---
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be
useful (see .node.status.conditions), the ability to deconflict is important.
The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
type: object
type: object
served: true
storage: true
subresources:
status: {}
Loading

0 comments on commit 2d4d71f

Please sign in to comment.