Skip to content

Commit 27fda2c

Browse files
blackjidalexellis
authored andcommitted
Add annotated-only flag to opt-out by default
The operator creates a tunnel for every loadbalancer services. There are cases were you might want the operator to manage only annotated services. Here we add the `annotated-only` flag to tell the operator to manage only the services with the `dev.inlets.manage=true` annotation. Signed-off-by: Juan Ignacio Donoso <[email protected]>
1 parent 1f482f5 commit 27fda2c

File tree

7 files changed

+48
-7
lines changed

7 files changed

+48
-7
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,15 @@ spec:
137137
type: LoadBalancer
138138
```
139139
140+
## Annotations
141+
142+
By default the operator will create a tunnel for every loadbalancer service.
143+
140144
To ignore a service such as `traefik` type in: `kubectl annotate svc/traefik -n kube-system dev.inlets.manage=false`
141145

146+
You can also set the operator to ignore the services by default and only manage them when the annotation is true. `dev.inlets.manage=true`
147+
To do this, run the operator with the flag `-annotated-only`
148+
142149
## Monitor/view logs
143150

144151
The operator deployment is in the `kube-system` namespace.

artifacts/operator.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ spec:
2424
imagePullPolicy: Always
2525
command:
2626
- ./inlets-operator
27+
# - "-annotated-only"
2728
- "-provider=digitalocean"
2829
- "-access-key-file=/var/secrets/inlets/inlets-access-key"
2930
# For Packet users

chart/inlets-operator/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,26 @@
2626
kubectl apply -f ./artifacts/crd.yaml
2727
```
2828

29+
## Configuration
30+
31+
The following table lists the configurable parameters of the `inlets-operator` chart and their default values,
32+
and can be overwritten via the helm `--set` flag.
33+
34+
Parameter | Description | Default
35+
--- | --- | ---
36+
`image` | Docker image for the Inlets Operator | `inlets/inlets-operator:0.4.2`
37+
`clientImage` | Docker image for the inlets client | `inlets/inlets:2.6.1`
38+
`provider` | Your infrastructure provider - 'packet' or 'digitalocean' | `""`
39+
`region` | The region to provision hosts into | `""`
40+
`accessKeyFile` | Read the access key for your infrastructure provider from a file (recommended) | `/var/secrets/inlets/inlets-access-key`
41+
`packetProjectId` | The project ID if using Packet.com as the provider | `""`
42+
`annotatedOnly` | Only create a tunnel for annotated services. | `false`
43+
`inletsProLicense` | License for use with inlets-pro | `""`
44+
`resources` | Operator resources requests & limits | `{"requests":{"cpu": "100m", "memory": "128Mi"}}`
45+
`nodeSelector` | Node labels for data pod assignment | `{}`
46+
`tolerations` | Node tolerations | `[]`
47+
`affinity` | Node affinity policy | `{}`
48+
2949
## Deploy an example configuration
3050

3151
### DigitalOcean with inlets OSS (recommended)

chart/inlets-operator/templates/deployment.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ spec:
2626
imagePullPolicy: {{ .Values.pullPolicy }}
2727
command:
2828
- ./inlets-operator
29+
{{- if .Value.annotatedOnly }}
30+
- "-annotated-only"
31+
{{- end }}
2932
- "-provider={{.Values.provider}}"
3033
- "-access-key-file={{.Values.accessKeyFile}}"
3134
- "-license={{.Values.inletsProLicense}}"

chart/inlets-operator/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ accessKeyFile: "/var/secrets/inlets/inlets-access-key"
1111
# Obtain from https://github.com/alexellis/inlets-pro-pkg
1212
inletsProLicense: ""
1313

14+
annotatedOnly: false
15+
1416
image: "inlets/inlets-operator:0.4.2"
1517
pullPolicy: "IfNotPresent"
1618
clientImage: "inlets/inlets:2.6.1"

controller.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"fmt"
55
"log"
6+
"strconv"
67
"strings"
78
"time"
89

@@ -87,7 +88,8 @@ func NewController(
8788
deploymentInformer appsinformers.DeploymentInformer,
8889
tunnelInformer informers.TunnelInformer,
8990
serviceInformer coreinformers.ServiceInformer,
90-
infra *InfraConfig) *Controller {
91+
infra *InfraConfig,
92+
) *Controller {
9193

9294
// Create event broadcaster
9395
// Add sample-controller types to the default Kubernetes Scheme so Events can be
@@ -323,7 +325,7 @@ func (c *Controller) syncHandler(key string) error {
323325
found, err := tunnels.Get(name, ops)
324326

325327
if errors.IsNotFound(err) {
326-
if manageService(*service) {
328+
if manageService(*c, *service) {
327329
pwdRes, pwdErr := password.Generate(64, 10, 0, false, true)
328330
if pwdErr != nil {
329331
log.Fatalf("Error generating password for inlets server %s", pwdErr.Error())
@@ -357,7 +359,7 @@ func (c *Controller) syncHandler(key string) error {
357359
} else {
358360
log.Printf("Tunnel exists: %s\n", found.Name)
359361

360-
if manageService(*service) == false {
362+
if manageService(*c, *service) == false {
361363
log.Printf("Removing tunnel: %s\n", found.Name)
362364

363365
err := tunnels.Delete(found.Name, &metav1.DeleteOptions{})
@@ -805,12 +807,16 @@ curl -sLO https://raw.githubusercontent.com/inlets/inlets/master/hack/inlets-pro
805807
systemctl enable inlets-pro`
806808
}
807809

808-
func manageService(service corev1.Service) bool {
810+
func manageService(controller Controller, service corev1.Service) bool {
809811
annotations := service.Annotations
810-
if v, ok := annotations["dev.inlets.manage"]; ok && v == "false" {
811-
return false
812+
813+
value, ok := annotations["dev.inlets.manage"]
814+
if ok {
815+
valueBool, _ := strconv.ParseBool(value)
816+
return valueBool
812817
}
813-
return true
818+
819+
return !controller.infraConfig.AnnotatedOnly
814820
}
815821

816822
func getPortsString(service *corev1.Service) string {

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type InfraConfig struct {
3838
SecretKeyFile string
3939
ProjectID string
4040
InletsClientImage string
41+
AnnotatedOnly bool
4142
ProConfig InletsProConfig
4243
}
4344

@@ -68,6 +69,7 @@ func main() {
6869
flag.StringVar(&infra.OrganizationID, "organization-id", "", "The organization id if using Scaleway as the provider")
6970
flag.StringVar(&infra.ProjectID, "project-id", "", "The project ID if using Packet.com as the provider")
7071
flag.StringVar(&infra.ProConfig.License, "license", "", "Supply a license for use with inlets-pro")
72+
flag.BoolVar(&infra.AnnotatedOnly, "annotated-only", false, "Only create a tunnel for annotated services. Annotate with dev.inlets.manage=true.")
7173

7274
flag.Parse()
7375

0 commit comments

Comments
 (0)