Skip to content

Commit

Permalink
more code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
natasha41575 committed Jan 23, 2023
1 parent 725c473 commit 9e51d97
Show file tree
Hide file tree
Showing 32 changed files with 775 additions and 99 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ linters-settings:
gomnd:
ignored-functions:
- os.WriteFile
- make
gomoddirectives:
replace-local: true
gosec:
Expand Down
78 changes: 32 additions & 46 deletions api/internal/builtins/HelmChartInflationGenerator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions api/krusty/charts/ocp-pipeline/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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
*~
# Various IDEs
.project
.idea/
*.tmproj
5 changes: 5 additions & 0 deletions api/krusty/charts/ocp-pipeline/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Openshift pipelines using Jenkins
name: ocp-pipeline
version: 0.1.16
36 changes: 36 additions & 0 deletions api/krusty/charts/ocp-pipeline/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This directory was copied from https://github.com/bcgov/helm-charts.

# ocp-pipeline Helm Chart

Helm chart to create a pipeline on OCP to use jenkins to deploy another helm chart

## Chart Details

This chart will do the following:

* Deploy A pipeline to deploy another helm chart with jenkins
* Deploy Jenkins if it is not already deployed (OCP does this not this chart)

## Installing the Chart

To install the chart with the release name `my-release`:

```bash
$ helm repo add bcgov https://bcgov.github.io/helm-charts
$ helm install my-release bcgov/ocp-pipeline
```

## Configuration

The following tables list the configurable parameters of the ocp-pipeline chart and their default values.



| Parameter | Description | Default |
| --------------------------------- | ------------------------------------ | ----------------------------------------- |
| `chart.name ` | Name of the chart to deploy | metadata-curator |
| `chart.repo ` | Repo where the chart can be found | http://bcgov.github.io/helm-charts |
| `webhookKey ` | Key to add to the webhook to trigger pipeline | "12345678" |
| `releaseName ` | Helm release name to create/use | mc |
| `releaseNamespace ` | Helm namespace to release to | mc |
| `deployValues ` | Object containing values the helm chart needs | {example: value} |
1 change: 1 addition & 0 deletions api/krusty/charts/ocp-pipeline/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pipeline deployed
32 changes: 32 additions & 0 deletions api/krusty/charts/ocp-pipeline/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "ocp-pipeline.name" -}}
{{- default .Chart.Name .Values.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 "ocp-pipeline.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.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 "ocp-pipeline.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ .Release.Name }}-config
labels:
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
type: Opaque
data:
config: '{{ .Values.deployValues | toJson | b64enc }}'
77 changes: 77 additions & 0 deletions api/krusty/charts/ocp-pipeline/templates/oc-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
apiVersion: build.openshift.io/v1
kind: BuildConfig
status:
lastVersion: 0
metadata:
name: {{ template "ocp-pipeline.fullname" . }}-deploy
#have to set this
namespace: {{ .Values.tillerNamespace }}
labels:
app: {{ template "ocp-pipeline.name" . }}
chart: {{ template "ocp-pipeline.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
nodeSelector: {}
resources:
requests:
cpu: 2000m
memory: 4G
limits:
cpu: 4000m
memory: 8G
triggers:
- type: "generic"
generic:
allowEnv: true
secretReference:
name: "{{ .Release.Name }}-git-webhook-secret"
strategy:
type: JenkinsPipeline
jenkinsPipelineStrategy:
jenkinsfile: |-
def helmName = "helm-v3.1.0-linux-amd64.tar.gz"
def chartName = "{{ .Values.chart.name }}"
def chartRepo = "{{ .Values.chart.repo }}"
def releaseName = "{{ .Values.releaseName }}"
def releaseNamespace = "{{ .Values.releaseNamespace }}"
def forceRecreate = "{{ lower .Values.forceRecreate }}"
def callAnotherPipe = "{{ lower .Values.callAnotherPipe.enabled }}"
def useEnv = "{{ lower .Values.recreate.useEnv }}"
def fromEnv = "{{ .Values.recreate.fromEnv }}"
def setFlag = "{{ .Values.recreate.setFlag }}"
node("nodejs") {
stage("deploy (it's already built)") {
sh """
curl -L -O https://get.helm.sh/${helmName}
tar -zxvf ${helmName}
cd linux-amd64
curl -L -O https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux32
chmod ugo+x ./jq-linux32
npm install -g json2yaml
export CONF1=`oc get secret {{ .Release.Name }}-config -o json | ./jq-linux32 .data.config`
export CONF2=`sed -e 's/^"//' -e 's/"\$//' <<<"\$CONF1"`
export CONF3=`echo \$CONF2 | base64 -d -`
export CONF=`echo \$CONF3 | json2yaml`
echo "\$CONF" > ./config.yaml
oc project ${releaseNamespace}
./helm repo add chart ${chartRepo}
./helm repo update
if [ "${forceRecreate}" = "true" ]; then
./helm upgrade ${releaseName} chart/${chartName} -f ./config.yaml --install --set hashLabel="${releaseName}\$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1)"
elif [ "${useEnv}" = "true" ]; then
./helm upgrade ${releaseName} chart/${chartName} -f ./config.yaml --install --set ${setFlag}=${env[fromEnv]}
else
./helm upgrade ${releaseName} chart/${chartName} -f ./config.yaml --install
fi
if [ "${callAnotherPipe}" = "true" ]; then
curl -d '' {{ .Values.callAnotherPipe.url }}
fi
"""
}
}
11 changes: 11 additions & 0 deletions api/krusty/charts/ocp-pipeline/templates/oc-gitWebhookSecret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ .Release.Name }}-git-webhook-secret
labels:
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
type: Opaque
data:
WebHookSecretKey: {{ .Values.webhookKey | b64enc }}
Loading

0 comments on commit 9e51d97

Please sign in to comment.