mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-09-15 12:18:57 +00:00
Add ability to set target namespace for helm chart template
This commit is contained in:
@@ -51,6 +51,10 @@ type HelmChart struct {
|
|||||||
// If omitted, the flag --generate-name is passed to 'helm template'.
|
// If omitted, the flag --generate-name is passed to 'helm template'.
|
||||||
ReleaseName string `json:"releaseName,omitempty" yaml:"releaseName,omitempty"`
|
ReleaseName string `json:"releaseName,omitempty" yaml:"releaseName,omitempty"`
|
||||||
|
|
||||||
|
// Namespace set the target namespace for a release. It is .Release.Namespace
|
||||||
|
// in the helm template
|
||||||
|
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
|
||||||
|
|
||||||
// ValuesFile is local file path to a values file to use _instead of_
|
// ValuesFile is local file path to a values file to use _instead of_
|
||||||
// the default values that accompanied the chart.
|
// the default values that accompanied the chart.
|
||||||
// The default values are in '{ChartHome}/{Name}/values.yaml'.
|
// The default values are in '{ChartHome}/{Name}/values.yaml'.
|
||||||
|
|||||||
@@ -272,6 +272,9 @@ func (p *HelmChartInflationGeneratorPlugin) templateCommand() []string {
|
|||||||
if p.ReleaseName != "" {
|
if p.ReleaseName != "" {
|
||||||
args = append(args, p.ReleaseName)
|
args = append(args, p.ReleaseName)
|
||||||
}
|
}
|
||||||
|
if p.Namespace != "" {
|
||||||
|
args = append(args, "--namespace", p.Namespace)
|
||||||
|
}
|
||||||
args = append(args, filepath.Join(p.absChartHome(), p.Name))
|
args = append(args, filepath.Join(p.absChartHome(), p.Name))
|
||||||
if p.ValuesFile != "" {
|
if p.ValuesFile != "" {
|
||||||
args = append(args, "--values", p.ValuesFile)
|
args = append(args, "--values", p.ValuesFile)
|
||||||
|
|||||||
@@ -20,46 +20,150 @@ func TestHelmChartInflationGenerator(t *testing.T) {
|
|||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
kind: HelmChartInflationGenerator
|
kind: HelmChartInflationGenerator
|
||||||
metadata:
|
metadata:
|
||||||
name: myMc
|
name: myPipeline
|
||||||
name: minecraft
|
name: ocp-pipeline
|
||||||
version: 3.1.3
|
namespace: mynamespace
|
||||||
repo: https://itzg.github.io/minecraft-server-charts
|
version: 0.1.16
|
||||||
|
repo: https://bcgov.github.io/helm-charts
|
||||||
releaseName: moria
|
releaseName: moria
|
||||||
|
valuesInline:
|
||||||
|
releaseNamespace: ""
|
||||||
|
rbac:
|
||||||
|
create: true
|
||||||
|
rules:
|
||||||
|
- apiGroups: [""]
|
||||||
|
verbs: ["*"]
|
||||||
|
resouces: ["*"]
|
||||||
`)
|
`)
|
||||||
|
|
||||||
th.AssertActualEqualsExpected(rm, `
|
th.AssertActualEqualsExpected(rm, `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
data:
|
data:
|
||||||
rcon-password: Q0hBTkdFTUUh
|
config: eyJleGFtcGxlIjoidmFsdWUifQ==
|
||||||
kind: Secret
|
kind: Secret
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app: moria-minecraft
|
chart: ocp-pipeline-0.1.16
|
||||||
chart: minecraft-3.1.3
|
|
||||||
heritage: Helm
|
heritage: Helm
|
||||||
release: moria
|
release: moria
|
||||||
name: moria-minecraft
|
name: moria-config
|
||||||
type: Opaque
|
type: Opaque
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Service
|
data:
|
||||||
|
WebHookSecretKey: MTIzNDU2Nzg=
|
||||||
|
kind: Secret
|
||||||
metadata:
|
metadata:
|
||||||
annotations: {}
|
|
||||||
labels:
|
labels:
|
||||||
app: moria-minecraft
|
chart: ocp-pipeline-0.1.16
|
||||||
chart: minecraft-3.1.3
|
|
||||||
heritage: Helm
|
heritage: Helm
|
||||||
release: moria
|
release: moria
|
||||||
name: moria-minecraft
|
name: moria-git-webhook-secret
|
||||||
|
type: Opaque
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: Role
|
||||||
|
metadata:
|
||||||
|
name: moria-ocp-pipeline
|
||||||
|
namespace: mynamespace
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
resouces:
|
||||||
|
- '*'
|
||||||
|
verbs:
|
||||||
|
- '*'
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: RoleBinding
|
||||||
|
metadata:
|
||||||
|
name: moria-ocp-pipeline
|
||||||
|
namespace: mynamespace
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: Role
|
||||||
|
name: moria-ocp-pipeline
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: jenkins
|
||||||
|
namespace: mynamespace
|
||||||
|
---
|
||||||
|
apiVersion: build.openshift.io/v1
|
||||||
|
kind: BuildConfig
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: ocp-pipeline
|
||||||
|
chart: ocp-pipeline-0.1.16
|
||||||
|
heritage: Helm
|
||||||
|
release: moria
|
||||||
|
name: moria-ocp-pipeline-deploy
|
||||||
|
namespace: null
|
||||||
spec:
|
spec:
|
||||||
ports:
|
nodeSelector: {}
|
||||||
- name: minecraft
|
resources:
|
||||||
port: 25565
|
limits:
|
||||||
protocol: TCP
|
cpu: 4000m
|
||||||
targetPort: minecraft
|
memory: 8G
|
||||||
selector:
|
requests:
|
||||||
app: moria-minecraft
|
cpu: 2000m
|
||||||
type: ClusterIP
|
memory: 4G
|
||||||
|
strategy:
|
||||||
|
jenkinsPipelineStrategy:
|
||||||
|
jenkinsfile: |-
|
||||||
|
def helmName = "helm-v3.1.0-linux-amd64.tar.gz"
|
||||||
|
def chartName = "metadata-curator"
|
||||||
|
def chartRepo = "http://bcgov.github.io/helm-charts"
|
||||||
|
def releaseName = "mc"
|
||||||
|
def releaseNamespace = ""
|
||||||
|
def forceRecreate = "false"
|
||||||
|
def callAnotherPipe = "false"
|
||||||
|
def useEnv = "false"
|
||||||
|
def fromEnv = "commit"
|
||||||
|
def setFlag = "image.tag"
|
||||||
|
|
||||||
|
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 moria-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 '' http://otherwebhookUrl
|
||||||
|
fi
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
type: JenkinsPipeline
|
||||||
|
triggers:
|
||||||
|
- generic:
|
||||||
|
allowEnv: true
|
||||||
|
secretReference:
|
||||||
|
name: moria-git-webhook-secret
|
||||||
|
type: generic
|
||||||
|
status:
|
||||||
|
lastVersion: 0
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user