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

add: cloudflared protocol option #135

Merged
merged 1 commit into from
Oct 17, 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
15 changes: 9 additions & 6 deletions cmd/cloudflare-tunnel-ingress-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@ type rootCmdFlags struct {
cloudflareAccountId string
cloudflareTunnelName string
namespace string
cloudflaredProtocol string
}

func main() {
var rootLogger = stdr.NewWithOptions(log.New(os.Stderr, "", log.LstdFlags), stdr.Options{LogCaller: stdr.All})

options := rootCmdFlags{
logger: rootLogger.WithName("main"),
ingressClass: "cloudflare-tunnel",
controllerClass: "strrl.dev/cloudflare-tunnel-ingress-controller",
logLevel: 0,
namespace: "default",
logger: rootLogger.WithName("main"),
ingressClass: "cloudflare-tunnel",
controllerClass: "strrl.dev/cloudflare-tunnel-ingress-controller",
logLevel: 0,
namespace: "default",
cloudflaredProtocol: "quic",
}

crlog.SetLogger(rootLogger.WithName("controller-runtime"))
Expand Down Expand Up @@ -100,7 +102,7 @@ func main() {
case <-done:
return
case _ = <-ticker.C:
err := controller.CreateOrUpdateControlledCloudflared(ctx, mgr.GetClient(), tunnelClient, options.namespace)
err := controller.CreateOrUpdateControlledCloudflared(ctx, mgr.GetClient(), tunnelClient, options.namespace, options.cloudflaredProtocol)
if err != nil {
logger.WithName("controlled-cloudflared").Error(err, "create controlled cloudflared")
}
Expand All @@ -120,6 +122,7 @@ func main() {
rootCommand.PersistentFlags().StringVar(&options.cloudflareAccountId, "cloudflare-account-id", options.cloudflareAccountId, "cloudflare account id")
rootCommand.PersistentFlags().StringVar(&options.cloudflareTunnelName, "cloudflare-tunnel-name", options.cloudflareTunnelName, "cloudflare tunnel name")
rootCommand.PersistentFlags().StringVar(&options.namespace, "namespace", options.namespace, "namespace to execute cloudflared connector")
rootCommand.PersistentFlags().StringVar(&options.cloudflaredProtocol, "cloudflared-protocol", options.cloudflaredProtocol, "cloudflared protocol")

err := rootCommand.Execute()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ spec:
- --cloudflare-account-id=$(CLOUDFLARE_ACCOUNT_ID)
- --cloudflare-tunnel-name=$(CLOUDFLARE_TUNNEL_NAME)
- --namespace=$(NAMESPACE)
- --cloudflared-protocol={{ .Values.cloudflared.protocol }}
env:
- name: CLOUDFLARE_API_TOKEN
valueFrom:
Expand Down
19 changes: 11 additions & 8 deletions helm/cloudflare-tunnel-ingress-controller/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ serviceAccount:

podAnnotations: {}

podSecurityContext: {}
podSecurityContext:
{}
# fsGroup: 2000

securityContext: {}
securityContext:
{}
# capabilities:
# drop:
# - ALL
Expand All @@ -58,12 +60,12 @@ resources:
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi

nodeSelector: {}

Expand All @@ -77,3 +79,4 @@ cloudflared:
pullPolicy: IfNotPresent
tag: latest
replicaCount: 1
protocol: quic
Copy link
Contributor

@z0rc z0rc Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default must be auto, not quic. auto is quic with fallback to http2.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I would update it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. I checked the Cloudflared docs, default is auto.
Weird. when I used the default config, it did not fallback to http2, and the tunnel did not work. I thought the default value was quic.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default protocol quic -> http2 updated in aa08f8b

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. I checked the Cloudflared docs, default is auto. Weird. when I used the default config, it did not fallback to http2, and the tunnel did not work. I thought the default value was quic.

just curious, does explicitly setting cloudflared protocol to http2 work for you?

9 changes: 6 additions & 3 deletions pkg/controller/controlled-cloudflared-connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func CreateOrUpdateControlledCloudflared(
kubeClient client.Client,
tunnelClient cloudflarecontroller.TunnelClientInterface,
namespace string,
protocol string,
) error {
logger := log.FromContext(ctx)
list := appsv1.DeploymentList{}
Expand Down Expand Up @@ -62,7 +63,7 @@ func CreateOrUpdateControlledCloudflared(
return errors.Wrap(err, "fetch tunnel token")
}

updatedDeployment := cloudflaredConnectDeploymentTemplating(token, namespace, int32(desiredReplicas))
updatedDeployment := cloudflaredConnectDeploymentTemplating(protocol, token, namespace, int32(desiredReplicas))
existingDeployment.Spec = updatedDeployment.Spec
err = kubeClient.Update(ctx, existingDeployment)
if err != nil {
Expand All @@ -84,7 +85,7 @@ func CreateOrUpdateControlledCloudflared(
return errors.Wrap(err, "invalid replica count")
}

deployment := cloudflaredConnectDeploymentTemplating(token, namespace, int32(replicas))
deployment := cloudflaredConnectDeploymentTemplating(protocol, token, namespace, int32(replicas))
err = kubeClient.Create(ctx, deployment)
if err != nil {
return errors.Wrap(err, "create controlled-cloudflared-connector deployment")
Expand All @@ -93,7 +94,7 @@ func CreateOrUpdateControlledCloudflared(
return nil
}

func cloudflaredConnectDeploymentTemplating(token string, namespace string, replicas int32) *appsv1.Deployment {
func cloudflaredConnectDeploymentTemplating(protocol string, token string, namespace string, replicas int32) *appsv1.Deployment {
appName := "controlled-cloudflared-connector"
image := os.Getenv("CLOUDFLARED_IMAGE")
pullPolicy := os.Getenv("CLOUDFLARED_IMAGE_PULL_POLICY")
Expand Down Expand Up @@ -129,6 +130,8 @@ func cloudflaredConnectDeploymentTemplating(token string, namespace string, repl
ImagePullPolicy: v1.PullPolicy(pullPolicy),
Command: []string{
"cloudflared",
"--protocol",
protocol,
"--no-autoupdate",
"tunnel",
"--metrics",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ var _ = Describe("CreateOrUpdateControlledCloudflared", func() {
},
}

protocol := "quic"

// Act
err = controller.CreateOrUpdateControlledCloudflared(ctx, kubeClient, mockTunnelClient, ns)
err = controller.CreateOrUpdateControlledCloudflared(ctx, kubeClient, mockTunnelClient, ns, protocol)
Expect(err).NotTo(HaveOccurred())

// Assert
Expand Down Expand Up @@ -101,16 +103,18 @@ var _ = Describe("CreateOrUpdateControlledCloudflared", func() {
},
}

protocol := "quic"

// Create initial deployment
err = controller.CreateOrUpdateControlledCloudflared(ctx, kubeClient, mockTunnelClient, ns)
err = controller.CreateOrUpdateControlledCloudflared(ctx, kubeClient, mockTunnelClient, ns, protocol)
Expect(err).NotTo(HaveOccurred())

// Change environment variables
os.Setenv("CLOUDFLARED_REPLICA_COUNT", "3")
os.Setenv("CLOUDFLARED_IMAGE", "cloudflare/cloudflared:2022.3.0")

// Act
err = controller.CreateOrUpdateControlledCloudflared(ctx, kubeClient, mockTunnelClient, ns)
err = controller.CreateOrUpdateControlledCloudflared(ctx, kubeClient, mockTunnelClient, ns, protocol)
Expect(err).NotTo(HaveOccurred())

// Assert
Expand Down
Loading