Skip to content

Commit

Permalink
Merge pull request #56 from srl-labs/tests/starting-helm-test-setup
Browse files Browse the repository at this point in the history
Tests/starting helm test setup
  • Loading branch information
carlmontanari authored Oct 21, 2023
2 parents 0c23269 + d2e04ca commit 9a67243
Show file tree
Hide file tree
Showing 44 changed files with 1,343 additions and 80 deletions.
8 changes: 5 additions & 3 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ linters:
- gocheckcompilerdirectives
- gochecknoglobals
- gochecknoinits
- gochecksumtype
- gocognit
- goconst
- gocritic
Expand All @@ -95,6 +96,7 @@ linters:
- grouper
- importas
- ineffassign
- inamedparam
- lll
- maintidx
- makezero
Expand All @@ -106,7 +108,7 @@ linters:
- nlreturn
- noctx
- nolintlint
- nolintlint
- perfsprint
- prealloc
- predeclared
- reassign
Expand Down Expand Up @@ -163,7 +165,7 @@ issues:
text: "package-comments"

run:
go: '1.20'
go: '1.21'
skip-dirs:
- .private
timeout: 5m
Expand All @@ -172,4 +174,4 @@ output:
uniq-by-line: false

service:
golangci-lint-version: 1.52.x
golangci-lint-version: 1.55.x
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ fmt: ## Run formatters

lint: fmt ## Run linters; runs with GOOS env var for linting on darwin
golangci-lint run
helm lint --quiet charts/clabernetes
helm lint --quiet charts/clicker

test: ## Run unit tests
gotestsum --format testname --hide-summary=skipped -- -coverprofile=cover.out `go list ./... | grep -v e2e`
Expand All @@ -29,6 +31,12 @@ test-e2e: ## Run e2e tests
cov: ## Produce html coverage report
go tool cover -html=cover.out

install-tools: ## Install lint/test tools
go install mvdan.cc/gofumpt@latest
go install golang.org/x/tools/cmd/goimports@latest
go install github.com/segmentio/golines@latest
go install gotest.tools/gotestsum@latest

install-code-generators: ## Install latest code-generator tools
go install k8s.io/code-generator/cmd/deepcopy-gen@latest
go install k8s.io/code-generator/cmd/openapi-gen@latest
Expand Down
3 changes: 3 additions & 0 deletions charts/clabernetes/.helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
.project
.idea/
*.tmproj

# ignore
tests
33 changes: 33 additions & 0 deletions charts/clabernetes/tests/clicker/clicker_enabled_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package default_vaules_test

import (
"fmt"
"os"
"testing"

clabernetesconstants "github.com/srl-labs/clabernetes/constants"

clabernetestesthelper "github.com/srl-labs/clabernetes/testhelper"
)

func TestMain(m *testing.M) {
clabernetestesthelper.Flags()

os.Exit(m.Run())
}

// TestDefaultValues -- really just here to ensure that we dont accidentally break our charts; this
// will probably be *highly* irritating in times of lots of chart updates, but, once we know the
// template are in a good place we can always just re-generate the "golden" outputs.
func TestClickerEnabled(t *testing.T) {
t.Parallel()

testName := "clicker-enabled"

clabernetestesthelper.HelmTest(
t,
testName,
clabernetesconstants.Clabernetes,
fmt.Sprintf("%s-values.yaml", testName),
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
# ensure that "global" values (not actually helm globals, but values we pass via yaml anchor)
# are non-default and passed to the clicker cahrt and render properly
appName: &_appName clabernetes-plus-clicker

# extra labels/annotations that are added to all objects
globalAnnotations: &_globalAnnotations
someannotation: someannotationvalue
annotherannotation: anotherannotationvalue
globalLabels: &_globalLabels
somelabel: somelabelvalue
anotherlabel: anotherlabelvalue

# ensure that when enabled clicker stuff is rendered
clicker:
enabled: true
appName: *_appName
globalAnnotations: *_globalAnnotations
globalLabels: *_globalLabels
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
# Source: clabernetes/charts/clicker/templates/clusterrole.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
chart: "clicker-0.0.16"
release: release-name
heritage: Helm
clabernetes/app: clabernetes-plus-clicker
clabernetes/name: "clabernetes-plus-clicker-clicker-cluster-role"
clabernetes/component: cluster-role
anotherlabel: anotherlabelvalue
somelabel: somelabelvalue
annotations:
annotherannotation: anotherannotationvalue
someannotation: someannotationvalue
name: "clabernetes-plus-clicker-clicker-cluster-role"
rules:
- apiGroups:
- ""
resources:
- nodes
verbs:
- "*"
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- list
- create
- watch
- delete
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
# Source: clabernetes/charts/clicker/templates/clusterrolebinding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: clabernetes-clicker
labels:
chart: "clicker-0.0.16"
release: release-name
heritage: Helm
clabernetes/app: clabernetes-plus-clicker
clabernetes/name: "clabernetes-plus-clicker-clicker-cluster-role-binding"
clabernetes/component: cluster-role-binding
anotherlabel: anotherlabelvalue
somelabel: somelabelvalue
annotations:
annotherannotation: anotherannotationvalue
someannotation: someannotationvalue
subjects:
- kind: ServiceAccount
name: "clabernetes-plus-clicker-clicker-service-account"
namespace: clabernetes
roleRef:
kind: ClusterRole
name: "clabernetes-plus-clicker-cluster-role"
apiGroup: rbac.authorization.k8s.io
---
# Source: clabernetes/charts/clicker/templates/clusterrolebinding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: clabernetes-clicker-nodes
labels:
chart: "clicker-0.0.16"
release: release-name
heritage: Helm
clabernetes/app: clabernetes-plus-clicker
clabernetes/name: "clabernetes-plus-clicker-clicker-cluster-role-binding"
clabernetes/component: cluster-role-binding
subjects:
- kind: ServiceAccount
name: "clabernetes-plus-clicker-clicker-service-account"
namespace: clabernetes
roleRef:
kind: ClusterRole
name: "clabernetes-plus-clicker-clicker-cluster-role"
apiGroup: rbac.authorization.k8s.io
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
# Source: clabernetes/charts/clicker/templates/job.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: clabernetes-plus-clicker-clicker
namespace: clabernetes
labels:
chart: "clicker-0.0.16"
release: release-name
heritage: Helm
clabernetes/app: clabernetes-plus-clicker
clabernetes/name: "clabernetes-plus-clicker-clicker"
clabernetes/component: clicker
anotherlabel: anotherlabelvalue
somelabel: somelabelvalue
annotations:
annotherannotation: anotherannotationvalue
someannotation: someannotationvalue
spec:
template:
metadata:
labels:
chart: "clicker-0.0.16"
release: release-name
heritage: Helm
clabernetes/app: clabernetes-plus-clicker
clabernetes/name: "clabernetes-plus-clicker-clicker"
clabernetes/component: clicker
anotherlabel: anotherlabelvalue
somelabel: somelabelvalue
annotations:
annotherannotation: anotherannotationvalue
someannotation: someannotationvalue
spec:
containers:
- name: clicker
image: "ghcr.io/srl-labs/clabernetes/clabernetes-manager:0.0.16"
imagePullPolicy: IfNotPresent
command: [
"/clabernetes/manager",
"clicker",
]
env:
- name: APP_NAME
value: clabernetes-plus-clicker
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: CLICKER_LOGGER_LEVEL
value: info
- name: CLICKER_WORKER_COMMAND
value: /bin/sh
- name: CLICKER_WORKER_SCRIPT
value: echo "hello, there"
- name: CLICKER_WORKER_RESOURCES
value: "requests:\n cpu: 50m\n memory: 128Mi"
- name: CLICKER_GLOBAL_ANNOTATIONS
value: "annotherannotation: anotherannotationvalue\nsomeannotation: someannotationvalue"
- name: CLICKER_GLOBAL_LABELS
value: "anotherlabel: anotherlabelvalue\nsomelabel: somelabelvalue"
resources:
requests:
memory: 128Mi
cpu: 50m
restartPolicy: Never
serviceAccountName: "clabernetes-plus-clicker-clicker-service-account"
backoffLimit: 4
ttlSecondsAfterFinished: 300
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
# Source: clabernetes/charts/clicker/templates/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: "clabernetes-plus-clicker-clicker-service-account"
namespace: clabernetes
labels:
chart: "clicker-0.0.16"
release: release-name
heritage: Helm
clabernetes/app: clabernetes-plus-clicker
clabernetes/name: "clabernetes-plus-clicker-clicker-service-account"
clabernetes/component: service-account
anotherlabel: anotherlabelvalue
somelabel: somelabelvalue
annotations:
annotherannotation: anotherannotationvalue
someannotation: someannotationvalue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
# Source: clabernetes/templates/certificate-secret.yaml
apiVersion: v1
kind: Secret
metadata:
labels:
chart: "clabernetes-0.0.16"
release: release-name
heritage: Helm
clabernetes/app: clabernetes-plus-clicker
clabernetes/name: "clabernetes-plus-clicker-certificate"
clabernetes/component: certificate
clabernetes/part-of: manager
anotherlabel: anotherlabelvalue
somelabel: somelabelvalue
annotations:
annotherannotation: anotherannotationvalue
someannotation: someannotationvalue
name: "clabernetes-plus-clicker-certificate"
data: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
# Source: clabernetes/templates/clusterrole.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
chart: "clabernetes-0.0.16"
release: release-name
heritage: Helm
clabernetes/app: clabernetes-plus-clicker
clabernetes/name: "clabernetes-plus-clicker-cluster-role"
clabernetes/component: cluster-role
anotherlabel: anotherlabelvalue
somelabel: somelabelvalue
annotations:
annotherannotation: anotherannotationvalue
someannotation: someannotationvalue
name: "clabernetes-plus-clicker-cluster-role"
rules:
- apiGroups:
- topology.clabernetes
resources:
- "*"
verbs:
- "*"
- apiGroups:
- apiextensions.k8s.io
resources:
- "*"
verbs:
- "*"
- apiGroups:
- ""
resources:
- namespaces
- secrets
- configmaps
- services
verbs:
- get
- list
- create
- update
- delete
- patch
- watch
- apiGroups:
- coordination.k8s.io
resources:
- leases
verbs:
- get
- list
- create
- update
- delete
- patch
- watch
- apiGroups:
- apps
resources:
- deployments
verbs:
- get
- list
- create
- update
- delete
- patch
- watch
Loading

0 comments on commit 9a67243

Please sign in to comment.