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

Support specifying an alternate number of replicas for cloudflared #70

Merged
merged 3 commits into from
Jan 9, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ spec:
value: "{{ .Values.cloudflared.image.repository }}:{{ .Values.cloudflared.image.tag }}"
- name: CLOUDFLARED_IMAGE_PULL_POLICY
value: {{ .Values.cloudflared.image.pullPolicy | quote }}
- name: CLOUDFLARED_REPLICA_COUNT
value: {{ .Values.cloudflared.replicaCount | quote }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
Expand Down
1 change: 1 addition & 0 deletions helm/cloudflare-tunnel-ingress-controller/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ cloudflared:
repository: cloudflare/cloudflared
pullPolicy: IfNotPresent
tag: latest
replicaCount: 1
14 changes: 10 additions & 4 deletions pkg/controller/controlled-cloudflared-connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package controller
import (
"context"
"os"
"strconv"

cloudflarecontroller "github.com/STRRL/cloudflare-tunnel-ingress-controller/pkg/cloudflare-controller"
"github.com/pkg/errors"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -40,18 +40,24 @@ func CreateControlledCloudflaredIfNotExist(
return errors.Wrap(err, "fetch tunnel token")
}

deployment := cloudflaredConnectDeploymentTemplating(token, namespace)
replicas, err := strconv.ParseInt(os.Getenv("CLOUDFLARED_REPLICA_COUNT"), 10, 32)
if err != nil {
return errors.Wrap(err, "invalid replica count")
}

deployment := cloudflaredConnectDeploymentTemplating(token, namespace, int32(replicas))
err = kubeClient.Create(ctx, deployment)
if err != nil {
return errors.Wrap(err, "create controlled-cloudflared-connector deployment")
}
return nil
}

func cloudflaredConnectDeploymentTemplating(token string, namespace string) *appsv1.Deployment {
func cloudflaredConnectDeploymentTemplating(token string, namespace string, replicas int32) *appsv1.Deployment {
appName := "controlled-cloudflared-connector"
image := os.Getenv("CLOUDFLARED_IMAGE")
pullPolicy := os.Getenv("CLOUDFLARED_IMAGE_PULL_POLICY")

return &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: appName,
Expand All @@ -62,7 +68,7 @@ func cloudflaredConnectDeploymentTemplating(token string, namespace string) *app
},
},
Spec: appsv1.DeploymentSpec{
Replicas: pointer.Int32(1),
Replicas: &replicas,
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": appName,
Expand Down
Loading