Skip to content

Commit

Permalink
✨ Move from Service to TunnelBinding
Browse files Browse the repository at this point in the history
  • Loading branch information
adyanth committed Nov 14, 2022
1 parent 4d480be commit f8d8234
Show file tree
Hide file tree
Showing 20 changed files with 1,255 additions and 641 deletions.
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,13 @@ resources:
kind: ClusterTunnel
path: github.com/adyanth/cloudflare-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: cfargotunnel.com
group: networking
kind: TunnelBinding
path: github.com/adyanth/cloudflare-operator/api/v1alpha1
version: v1alpha1
version: "3"
112 changes: 112 additions & 0 deletions api/v1alpha1/tunnelbinding_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
Copyright 2022.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// TunnelBindingSubject defines the subject TunnelBinding connects to the Tunnel
type TunnelBindingSubject struct {
// Kind can be Service
//+kubebuilder:validation:Required
//+kubebuilder:default:="Service"
Kind string `json:"kind"`
//+kubebuilder:validation:Required
Name string `json:"name"`
Spec TunnelBindingSubjectSpec `json:"spec"`
}

type TunnelBindingSubjectSpec struct {
// Fqdn specifies the DNS name to access this service from.
// Defaults to the service.metadata.name + tunnel.spec.domain.
// If specifying this, make sure to use the same domain that the tunnel belongs to.
// This is not validated and used as provided
//+kubebuilder:validation:Optional
Fqdn string `json:"fqdn,omitempty"`

// Protocol specifies the protocol for the service. Should be one of http, https, tcp, udp, ssh or rdp.
// Defaults to http, with the exceptions of https for 443, smb for 139 and 445, rdp for 3389 and ssh for 22 if the service has a TCP port.
// The only available option for a UDP port is udp, which is default.
//+kubebuilder:validation:Optional
Protocol string `json:"protocol,omitempty"`

// Target specified where the tunnel should proxy to.
// Defaults to the form of <protocol>://<service.metadata.name>.<service.metadata.namespace>.svc:<port>
//+kubebuilder:validation:Optional
Target string `json:"target,omitempty"`

// CaPool trusts the CA certificate referenced by the key in the secret specified in tunnel.spec.originCaPool.
// tls.crt is trusted globally and does not need to be specified. Only useful if the protocol is HTTPS.
//+kubebuilder:validation:Optional
CaPool string `json:"caPool,omitempty"`

// NoTlsVerify sisables TLS verification for this service.
// Only useful if the protocol is HTTPS.
//+kubebuilder:validation:Optional
//+kubebuilder:default:="false"
NoTlsVerify bool `json:"noTlsVerify"`
}

// TunnelRef defines the Tunnel TunnelBinding connects to
type TunnelRef struct {
// Kind can be Tunnel or ClusterTunnel
//+kubebuilder:validation:Required
Kind string `json:"kind"`
// Name of the tunnel resource
//+kubebuilder:validation:Required
Name string `json:"name"`
}

// ServiceInfo stores the Hostname and Target for each service
type ServiceInfo struct {
// FQDN of the service
Hostname string `json:"hostname"`
// Target for cloudflared
Target string `json:"target"`
}

// TunnelBindingStatus defines the observed state of TunnelBinding
type TunnelBindingStatus struct {
Services []ServiceInfo `json:"services"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// TunnelBinding is the Schema for the tunnelbindings API
type TunnelBinding struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Subjects []TunnelBindingSubject `json:"subjects"`
TunnelRef TunnelRef `json:"tunnelRef"`
Status TunnelBindingStatus `json:"status"`
}

//+kubebuilder:object:root=true

// TunnelBindingList contains a list of TunnelBinding
type TunnelBindingList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []TunnelBinding `json:"items"`
}

func init() {
SchemeBuilder.Register(&TunnelBinding{}, &TunnelBindingList{})
}
145 changes: 145 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

46 changes: 45 additions & 1 deletion bundle/manifests/cloudflare-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,25 @@ metadata:
},
"size": 2
}
},
{
"apiVersion": "networking.cfargotunnel.com/v1alpha1",
"kind": "TunnelBinding",
"metadata": {
"labels": {
"app.kubernetes.io/created-by": "cloudflare-operator",
"app.kubernetes.io/instance": "tunnelbinding-sample",
"app.kubernetes.io/managed-by": "kustomize",
"app.kubernetes.io/name": "tunnelbinding",
"app.kubernetes.io/part-of": "cloudflare-operator"
},
"name": "tunnelbinding-sample"
},
"spec": null
}
]
capabilities: Basic Install
operators.operatorframework.io/builder: operator-sdk-v1.20.1
operators.operatorframework.io/builder: operator-sdk-v1.25.1
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
name: cloudflare-operator.v0.8.2
namespace: placeholder
Expand All @@ -60,6 +75,9 @@ spec:
kind: ClusterTunnel
name: clustertunnels.networking.cfargotunnel.com
version: v1alpha1
- kind: TunnelBinding
name: tunnelbindings.networking.cfargotunnel.com
version: v1alpha1
- description: Tunnel is the Schema for the tunnels API
displayName: Tunnel
kind: Tunnel
Expand Down Expand Up @@ -160,6 +178,32 @@ spec:
- get
- patch
- update
- apiGroups:
- networking.cfargotunnel.com
resources:
- tunnelbindings
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- networking.cfargotunnel.com
resources:
- tunnelbindings/finalizers
verbs:
- update
- apiGroups:
- networking.cfargotunnel.com
resources:
- tunnelbindings/status
verbs:
- get
- patch
- update
- apiGroups:
- networking.cfargotunnel.com
resources:
Expand Down
Loading

0 comments on commit f8d8234

Please sign in to comment.