Skip to content

Commit

Permalink
Merge pull request #834 from weaveworks/fix-bp-helm-chart-and-bump-to…
Browse files Browse the repository at this point in the history
…-v0.16.0-rc.2

enable configmap creation and bump chart to v0.16.0-rc.2
  • Loading branch information
Chanwit Kaewkasi authored Aug 3, 2023
2 parents 1b291be + f540896 commit 3e3a5f7
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 41 deletions.
4 changes: 2 additions & 2 deletions charts/tf-controller/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ apiVersion: v2
name: tf-controller
description: The Helm chart for Weave GitOps Terraform Controller
type: application
version: 0.16.0-rc.1
appVersion: "v0.16.0-rc.1"
version: 0.16.0-rc.2
appVersion: "v0.16.0-rc.2"
4 changes: 2 additions & 2 deletions charts/tf-controller/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Weave GitOps Terraform Controller

![Version: 0.16.0-rc.1](https://img.shields.io/badge/Version-0.16.0--rc.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v0.16.0-rc.1](https://img.shields.io/badge/AppVersion-v0.16.0--rc.1-informational?style=flat-square)
![Version: 0.16.0-rc.2](https://img.shields.io/badge/Version-0.16.0--rc.2-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v0.16.0-rc.2](https://img.shields.io/badge/AppVersion-v0.16.0--rc.2-informational?style=flat-square)

The Helm chart for Weave GitOps Terraform Controller

Expand Down Expand Up @@ -72,7 +72,7 @@ __Note__: If you need to use the `imagePullSecrets` it would be best to set `ser
| rbac.create | bool | `true` | If `true`, create and use RBAC resources |
| replicaCount | int | `1` | Number of TF-Controller pods to deploy |
| resources | object | `{"limits":{"cpu":"1000m","memory":"1Gi"},"requests":{"cpu":"200m","memory":"64Mi"}}` | Resource limits and requests |
| runner | object | `{"creationTimeout":"5m0s","grpc":{"maxMessageSize":4},"image":{"repository":"ghcr.io/weaveworks/tf-runner","tag":"v0.16.0-rc.1"},"serviceAccount":{"allowedNamespaces":[],"annotations":{},"create":true,"name":""}}` | Runner-specific configurations |
| runner | object | `{"creationTimeout":"5m0s","grpc":{"maxMessageSize":4},"image":{"repository":"ghcr.io/weaveworks/tf-runner","tag":"v0.16.0-rc.2"},"serviceAccount":{"allowedNamespaces":[],"annotations":{},"create":true,"name":""}}` | Runner-specific configurations |
| runner.creationTimeout | string | `"5m0s"` | Timeout for runner-creation (Controller) |
| runner.grpc.maxMessageSize | int | `4` | Maximum GRPC message size (Controller) |
| runner.image.repository | string | `"ghcr.io/weaveworks/tf-runner"` | Runner image repository |
Expand Down
13 changes: 2 additions & 11 deletions charts/tf-controller/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Create a unique list of runner allowed namespaces
Expand the name of the chart.
*/}}
{{- define "planner.name" -}}
{{- printf "%s-planner" (default .Chart.Name .Values.nameOverride) | trunc 63 | trimSuffix "-" }}
{{ include "tf-controller.name" . }}-branch-planner
{{- end }}

{{/*
Expand All @@ -96,16 +96,7 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
If release name contains chart name it will be used as a full name.
*/}}
{{- define "planner.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- printf "%s-planner" .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := printf "%s-planner" (default .Chart.Name .Values.nameOverride) }}
{{- if contains $name .Release.Name }}
{{- printf "%s-planner" .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{ include "tf-controller.fullname" . }}-branch-planner
{{- end }}

{{/*
Expand Down
4 changes: 2 additions & 2 deletions charts/tf-controller/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ image:
pullPolicy: IfNotPresent
# -- Overrides the image tag whose default is the chart appVersion.
# @default -- `.Chart.AppVersion`
tag: "v0.16.0-rc.1"
tag: "v0.16.0-rc.2"
# -- Controller image pull secret
imagePullSecrets: []
# -- Resource limits and requests
Expand Down Expand Up @@ -114,7 +114,7 @@ runner:
repository: ghcr.io/weaveworks/tf-runner
# -- Runner image tag
# @default -- `.Chart.AppVersion`
tag: "v0.16.0-rc.1"
tag: "v0.16.0-rc.2"
grpc:
# -- Maximum GRPC message size (Controller)
maxMessageSize: 4
Expand Down
2 changes: 1 addition & 1 deletion config/branch-planner/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ generatorOptions:
images:
- name: weaveworks/branch-planner
newName: ghcr.io/weaveworks/branch-planner
newTag: v0.16.0-rc.1
newTag: v0.16.0-rc.2
2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ generatorOptions:
images:
- name: weaveworks/tf-controller
newName: ghcr.io/weaveworks/tf-controller
newTag: v0.16.0-rc.1
newTag: v0.16.0-rc.2
19 changes: 14 additions & 5 deletions docs/branch_planner/rc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ spec:
sourceRef:
kind: HelmRepository
name: tf-controller
version: '>=0.15.0-rc.6'
version: '>=0.16.0-rc.2'
interval: 1h0s
releaseName: tf-controller
targetNamespace: flux-system
install:
crds: Create
remediation:
retries: -1
upgrade:
crds: CreateReplace
remediation:
retries: -1
values:
replicaCount: 1
replicaCount: 3
concurrency: 24
resources:
limits:
Expand All @@ -42,11 +46,16 @@ spec:
caCertValidityDuration: 24h
certRotationCheckFrequency: 30m
image:
tag: v0.15.0-rc.6
tag: v0.16.0-rc.2
runner:
image:
tag: v0.15.0-rc.6
tag: v0.16.0-rc.2
grpc:
maxMessageSize: 30
branchPlanner:
enabled: true
image:
tag: v0.15.0-rc.6
tag: v0.16.0-rc.2
configMap:
name: branch-planner
create: true
11 changes: 7 additions & 4 deletions docs/branch_planner/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spec:
sourceRef:
kind: HelmRepository
name: tf-controller
version: '>=0.16.0-rc.1'
version: '>=0.16.0-rc.2'
interval: 1h0s
releaseName: tf-controller
targetNamespace: flux-system
Expand All @@ -46,13 +46,16 @@ spec:
caCertValidityDuration: 24h
certRotationCheckFrequency: 30m
image:
tag: v0.16.0-rc.1
tag: v0.16.0-rc.2
runner:
image:
tag: v0.16.0-rc.1
tag: v0.16.0-rc.2
grpc:
maxMessageSize: 30
branchPlanner:
enabled: true
image:
tag: v0.16.0-rc.1
tag: v0.16.0-rc.2
configMap:
name: branch-planner
create: true
6 changes: 3 additions & 3 deletions docs/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spec:
sourceRef:
kind: HelmRepository
name: tf-controller
version: '>=0.16.0-rc.1'
version: '>=0.16.0-rc.2'
interval: 1h0s
releaseName: tf-controller
targetNamespace: flux-system
Expand All @@ -46,9 +46,9 @@ spec:
caCertValidityDuration: 24h
certRotationCheckFrequency: 30m
image:
tag: v0.16.0-rc.1
tag: v0.16.0-rc.2
runner:
image:
tag: v0.16.0-rc.1
tag: v0.16.0-rc.2
grpc:
maxMessageSize: 30
38 changes: 28 additions & 10 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"gopkg.in/yaml.v2"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -21,7 +22,8 @@ const (
AnnotationErrorRevision = "infra.weave.works/error-revision"

// DefaultNamespace will be used if RUNTIME_NAMESPACE is not defined.
DefaultNamespace = "flux-system"
DefaultNamespace = "flux-system"
DefaultTokenSecretName = "branch-planner-token"
)

// Example ConfigMap
Expand All @@ -34,7 +36,7 @@ const (
// metadata:
// name: branch-based-planner
// data:
// # Secret to use to use GitHub API.
// # Secret to use GitHub API.
// # Key in the secret: token
// secretNamespace: flux-system
// secretName: bbp-token
Expand All @@ -56,23 +58,39 @@ type Config struct {
Labels map[string]string
}

func ReadConfig(ctx context.Context, clusterClient client.Client, ref types.NamespacedName) (Config, error) {
config := Config{}

if ref.Namespace == "" {
ref.Namespace = RuntimeNamespace()
func ReadConfig(ctx context.Context, clusterClient client.Client, configMapObjectKey types.NamespacedName) (Config, error) {
if configMapObjectKey.Namespace == "" {
configMapObjectKey.Namespace = RuntimeNamespace()
}

configMap := &corev1.ConfigMap{}
err := clusterClient.Get(ctx, ref, configMap)
err := clusterClient.Get(ctx, configMapObjectKey, configMap)
if err != nil {
defaultConfig := Config{
SecretName: DefaultTokenSecretName,
SecretNamespace: RuntimeNamespace(),
Resources: []client.ObjectKey{
{Namespace: RuntimeNamespace()},
},
}

// Check for not found error, it's ok to not have a ConfigMap
if errors.IsNotFound(err) {
return defaultConfig, nil
}

// Check for permission error, it's ok to not have access to the ConfigMap
if errors.IsForbidden(err) {
return defaultConfig, nil
}

// Return a generic error for other cases
return Config{}, fmt.Errorf("unable to get ConfigMap: %w", err)
}

config := Config{}
config.SecretNamespace = configMap.Data["secretNamespace"]
config.SecretName = configMap.Data["secretName"]
resourceData := configMap.Data["resources"]

if config.SecretNamespace == "" {
config.SecretNamespace = RuntimeNamespace()
}
Expand Down

0 comments on commit 3e3a5f7

Please sign in to comment.