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: implement fullstack-cluster-setup chart for shared resources #363

Merged
merged 16 commits into from
Sep 21, 2023
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
24 changes: 24 additions & 0 deletions build-logic/project-plugins/src/main/kotlin/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,30 @@ class Utils {
updateStringInFile(manifestFile, "appVersion:", "appVersion: \"${newVersion}\"")
}

@JvmStatic
fun updateHelmChartVersion(project: Project, newVersion: SemVer) {
updateHelmCharts(project) {chart ->
updateHelmChartVersion(project, chart.name, newVersion)
}
}

@JvmStatic
fun updateHelmChartAppVersion(project: Project, newVersion: SemVer) {
updateHelmCharts(project) {chart ->
updateHelmChartAppVersion(project, chart.name, newVersion)
}
}

@JvmStatic
fun updateHelmCharts(project: Project, fn: (File) -> Unit) {
val chartDir = File(project.rootProject.projectDir, "charts")
chartDir.listFiles()?.forEach { chart ->
if (chart.isDirectory && File(chart, "Chart.yaml").exists()) {
fn(chart)
}
}
}

private fun updateStringInFile(file: File, startsWith: String, newString: String, ignoreLeadingSpace: Boolean = true) {
var lines: List<String> = mutableListOf()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,15 @@ tasks.register("githubVersionSummary") {
}
}

val HEDERA_NETWORK_CHART = "hedera-network"

tasks.register("versionAsSpecified") {
group = "versioning"
doLast {
val verStr = findProperty("newVersion")?.toString()
?: throw IllegalArgumentException("No newVersion property provided! Please add the parameter -PnewVersion=<version> when running this task.")

val newVer = SemVer.parse(verStr)
Utils.updateHelmChartVersion(project, HEDERA_NETWORK_CHART, newVer)
Utils.updateHelmChartAppVersion(project, HEDERA_NETWORK_CHART, newVer)
Utils.updateHelmChartVersion(project, newVer)
Utils.updateHelmChartAppVersion(project, newVer)
Utils.updateVersion(project, newVer)
}
}
Expand All @@ -71,8 +69,8 @@ tasks.register("versionAsSnapshot") {
val currVer = SemVer.parse(project.version.toString())
val newVer = SemVer(currVer.major, currVer.minor, currVer.patch, "SNAPSHOT")

Utils.updateHelmChartVersion(project, HEDERA_NETWORK_CHART, newVer)
Utils.updateHelmChartAppVersion(project, HEDERA_NETWORK_CHART, newVer)
Utils.updateHelmChartVersion(project, newVer)
Utils.updateHelmChartAppVersion(project, newVer)
Utils.updateVersion(project, newVer)
}
}
Expand Down
23 changes: 23 additions & 0 deletions charts/fullstack-cluster-setup/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions charts/fullstack-cluster-setup/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: fullstack-cluster-setup
description: A Helm chart to setup shared resources for fullstack-testing

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
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.8.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.8.0"
Empty file.
51 changes: 51 additions & 0 deletions charts/fullstack-cluster-setup/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "fullstack-cluster-setup.name" -}}
{{- default .Chart.Name .Values.global.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "fullstack-cluster-setup.fullname" -}}
{{- if .Values.global.fullnameOverride }}
{{- .Values.global.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.global.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "fullstack-cluster-setup.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "fullstack-cluster-setup.labels" -}}
helm.sh/chart: {{ include "fullstack-cluster-setup.chart" . }}
{{ include "fullstack-cluster-setup.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "fullstack-cluster-setup.selectorLabels" -}}
app.kubernetes.io/name: {{ include "fullstack-cluster-setup.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: gateway.networking.k8s.io/v1beta1
kind: GatewayClass
metadata:
name: fst-gateway-class
labels:
fullstack.hedera.com/type: gateway-class
spec:
controllerName: "gateway.envoyproxy.io/gatewayclass-controller"
#controllerName: "haproxy-ingress.github.io/controller"
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: pod-monitor-role
labels:
fullstack.hedera.com/type: cluster-role
rules:
- apiGroups: [ "" ]
resources:
- pods
- services
- clusterroles
- pods/log
- secrets
verbs:
- get
- list
- apiGroups: [ "" ]
resources:
- pods/exec
verbs:
- create
- apiGroups: [ "gateway.networking.k8s.io" ]
resources:
- gatewayclasses
- gateways
- httproutes
- tcproutes
verbs:
- get
- list
8 changes: 8 additions & 0 deletions charts/fullstack-cluster-setup/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Default values for fullstack-cluster-setup.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

global:
namespaceOverride: ""
nameOverride: ""
fullnameOverride: ""
2 changes: 1 addition & 1 deletion charts/hedera-network/Chart.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ dependencies:
repository: https://operator.min.io/
version: 5.0.7
digest: sha256:cf355b295abceb5814ef57d3e146ec9d4e8db7365a700079d683bd5f766ad374
generated: "2023-09-16T13:47:19.087992+10:00"
generated: "2023-09-20T13:51:41.203996+10:00"
12 changes: 0 additions & 12 deletions charts/hedera-network/templates/gateway-api/gateway.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
{{- if $.Values.gatewayApi.gatewayClass.enable | eq "true" }}
apiVersion: gateway.networking.k8s.io/v1beta1
kind: GatewayClass
metadata:
name: {{ $.Values.gatewayApi.gatewayClass.name }}
namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }}
labels:
fullstack.hedera.com/type: gateway-class
spec:
controllerName: {{ $.Values.gatewayApi.gatewayClass.controllerName }}
{{- end }}
{{- if $.Values.gatewayApi.gateway.enable | eq "true" }}
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
Expand Down
42 changes: 0 additions & 42 deletions charts/hedera-network/templates/rbac/pod-monitor-role.yaml

This file was deleted.

19 changes: 19 additions & 0 deletions charts/hedera-network/templates/rbac/pod-monitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: pod-monitor
namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: pod-monitor-role-binding
namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }}
subjects:
- kind: ServiceAccount
name: pod-monitor
namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }}
roleRef:
kind: ClusterRole
name: {{ $.Values.tester.clusterRoleName }}
apiGroup: rbac.authorization.k8s.io
5 changes: 0 additions & 5 deletions charts/hedera-network/templates/rbac/service-accounts.yaml

This file was deleted.

8 changes: 8 additions & 0 deletions charts/hedera-network/templates/tests/test-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@ spec:
env:
- name: TESTS_DIR
value: "/tests" # should be same as mountPath
- name: LOG_DIR
value: "/tmp/fullstack-testing-logs"
- name: LOG_FILE
value: "helm-test.log"
- name: OUTPUT_LOG # outputs the logs from the tests
value: "true"
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
command:
- "/bin/bash"
- "-c"
Expand Down
19 changes: 9 additions & 10 deletions charts/hedera-network/tests/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@
# load .env file if it exists in order to load variables with custom values
ENV_FILE="$(dirname "${BASH_SOURCE[0]}")/.env"
if [[ -f "${ENV_FILE}" ]]; then
export $(cat "${ENV_FILE}" | xargs)
set -a
# shellcheck source=./../temp/.env
source "${ENV_FILE}"
set +a
fi


# set global env variables if not set
BATS_HOME="${BATS_HOME:-../../../dev/bats}"
TESTS_DIR="${TESTS_DIR:-.}"

OUTPUT_LOG="${OUTPUT_LOG}"
LOG_DIR="${LOG_DIR:-/tmp/bats-test-logs}"
LOG_FILE="test.log"
[ ! -d "${LOG_DIR}" ] && mkdir "${LOG_DIR}"

echo ""
echo "Env variables"
echo "=============================================="
echo "--------------------------Env Setup: fullstack-testing Helm Test------------------------------------------------"
echo "NAMESPACE: ${NAMESPACE}"
echo "ENV_FILE: ${ENV_FILE}"
echo "BATS_HOME: ${BATS_HOME}"
echo "TESTS_DIR: ${TESTS_DIR}"
echo "LOG: ${LOG_DIR}/${LOG_FILE}"
echo "OUTPUT_LOG: ${OUTPUT_LOG}"

echo "-----------------------------------------------------------------------------------------------------"
echo ""
4 changes: 4 additions & 0 deletions charts/hedera-network/tests/env.template
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
TOTAL_NODES=3

LOG_DIR="${LOG_DIR:-/tmp/fullstack-testing-logs}"
LOG_FILE="${LOG_FILE:-helm-test.log}"
OUTPUT_LOG="${OUTPUT_LOG:-false}"
Loading