Simplify and refactor k8s labels and annnotations (#227)

The conduit.io/* k8s labels and annotations we're redundant in some
cases, and not flexible enough in others.

This change modifies the labels in the following ways:
`conduit.io/plane: control` => `conduit.io/controller-component: web`
`conduit.io/controller: conduit` => `conduit.io/controller-ns: conduit`
`conduit.io/plane: data` => (remove, redundant with `conduit.io/controller-ns`)
It also centralizes all k8s labels and annotations into
pkg/k8s/labels.go, and adds tests for the install command.

Part of #201

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
This commit is contained in:
Andrew Seigner 2018-02-01 14:12:06 -08:00 committed by GitHub
parent abaf498cfc
commit 277c06cf1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 582 additions and 93 deletions

View File

@ -135,7 +135,7 @@ jobs:
- bin/docker-push $CONDUIT_TAG - bin/docker-push $CONDUIT_TAG
- bin/docker-retag-all $CONDUIT_TAG master && bin/docker-push master - bin/docker-retag-all $CONDUIT_TAG master && bin/docker-push master
- target/cli/linux/conduit install --version=$CONDUIT_TAG |tee conduit.yml - target/cli/linux/conduit install --version=$CONDUIT_TAG |tee conduit.yml
- kubectl -n conduit apply -f conduit.yml --prune --selector='conduit.io/plane=control' - kubectl -n conduit apply -f conduit.yml --prune --selector='conduit.io/control-plane-component'
notifications: notifications:
email: email:

8
Gopkg.lock generated
View File

@ -239,6 +239,12 @@
revision = "879c5887cd475cd7864858769793b2ceb0d44feb" revision = "879c5887cd475cd7864858769793b2ceb0d44feb"
version = "v1.1.0" version = "v1.1.0"
[[projects]]
name = "github.com/sergi/go-diff"
packages = ["diffmatchpatch"]
revision = "1744e2970ca51c86172c8190fadad617561ed6e7"
version = "v1.0.0"
[[projects]] [[projects]]
name = "github.com/sirupsen/logrus" name = "github.com/sirupsen/logrus"
packages = ["."] packages = ["."]
@ -349,6 +355,6 @@
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"
analyzer-version = 1 analyzer-version = 1
inputs-digest = "b9949249a1b88b851ea33a371af8a547536aacc14c0f642f7741a8cd6fac66ea" inputs-digest = "902019db7e0b8a324ccaaa9dd06470f8639063a41a7b80eaafa56088c92ac7d5"
solver-name = "gps-cdcl" solver-name = "gps-cdcl"
solver-version = 1 solver-version = 1

View File

@ -7,5 +7,6 @@ set -eu
sha=$(. bin/_tag.sh ; go_deps_sha) sha=$(. bin/_tag.sh ; go_deps_sha)
for f in $( grep -lR --include=Dockerfile\* go-deps: . ) ; do for f in $( grep -lR --include=Dockerfile\* go-deps: . ) ; do
sed -E -i'' -e "s|runconduit/go-deps:[^ ]+|runconduit/go-deps:${sha}|" "$f" sed -E -i.bak -e "s|runconduit/go-deps:[^ ]+|runconduit/go-deps:${sha}|" "$f"
rm "$f".bak
done done

View File

@ -7,5 +7,6 @@ set -eu
sha=$(. bin/_tag.sh ; proxy_deps_sha) sha=$(. bin/_tag.sh ; proxy_deps_sha)
for f in $( grep -lR --include=Dockerfile\* proxy-deps: . ) ; do for f in $( grep -lR --include=Dockerfile\* proxy-deps: . ) ; do
sed -E -i'' -e "s|runconduit/proxy-deps:[^ ]+|runconduit/proxy-deps:${sha}|" "$f" sed -E -i.bak -e "s|runconduit/proxy-deps:[^ ]+|runconduit/proxy-deps:${sha}|" "$f"
rm "$f".bak
done done

View File

@ -1,5 +1,5 @@
## compile binaries ## compile binaries
FROM gcr.io/runconduit/go-deps:dac3fae6 as golang FROM gcr.io/runconduit/go-deps:7bceac7a as golang
ARG CONDUIT_VERSION ARG CONDUIT_VERSION
WORKDIR /go/src/github.com/runconduit/conduit WORKDIR /go/src/github.com/runconduit/conduit
COPY cli cli COPY cli cli
@ -10,7 +10,7 @@ RUN CGO_ENABLED=0 GOOS=darwin go build -a -installsuffix cgo -o /out/conduit-dar
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o /out/conduit-linux -ldflags "-X github.com/runconduit/conduit/pkg/version.Version=$CONDUIT_VERSION" ./cli RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o /out/conduit-linux -ldflags "-X github.com/runconduit/conduit/pkg/version.Version=$CONDUIT_VERSION" ./cli
RUN CGO_ENABLED=0 GOOS=windows go build -a -installsuffix cgo -o /out/conduit-windows -ldflags "-X github.com/runconduit/conduit/pkg/version.Version=$CONDUIT_VERSION" ./cli RUN CGO_ENABLED=0 GOOS=windows go build -a -installsuffix cgo -o /out/conduit-windows -ldflags "-X github.com/runconduit/conduit/pkg/version.Version=$CONDUIT_VERSION" ./cli
## export without sources & depdenndencies ## export without sources & dependencies
FROM gcr.io/runconduit/base:2017-10-30.01 FROM gcr.io/runconduit/base:2017-10-30.01
COPY --from=golang /out /out COPY --from=golang /out /out
WORKDIR /out WORKDIR /out

View File

@ -9,6 +9,7 @@ import (
"strings" "strings"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/runconduit/conduit/pkg/k8s"
"github.com/runconduit/conduit/pkg/version" "github.com/runconduit/conduit/pkg/version"
"github.com/spf13/cobra" "github.com/spf13/cobra"
batchV1 "k8s.io/api/batch/v1" batchV1 "k8s.io/api/batch/v1"
@ -19,20 +20,16 @@ import (
) )
var ( var (
initImage string initImage string
proxyImage string proxyImage string
proxyUID int64 proxyUID int64
inboundPort uint inboundPort uint
outboundPort uint outboundPort uint
ignoreInboundPorts []uint ignoreInboundPorts []uint
ignoreOutboundPorts []uint ignoreOutboundPorts []uint
proxyControlPort uint proxyControlPort uint
proxyAPIPort uint proxyAPIPort uint
proxyLogLevel string proxyLogLevel string
conduitCreatedByAnnotation = "conduit.io/created-by"
conduitProxyVersionAnnotation = "conduit.io/proxy-version"
conduitControlLabel = "conduit.io/controller"
conduitPlaneLabel = "conduit.io/plane"
) )
var injectCmd = &cobra.Command{ var injectCmd = &cobra.Command{
@ -290,14 +287,13 @@ func injectPodTemplateSpec(t *v1.PodTemplateSpec) enhancedPodTemplateSpec {
if t.Annotations == nil { if t.Annotations == nil {
t.Annotations = make(map[string]string) t.Annotations = make(map[string]string)
} }
t.Annotations[conduitCreatedByAnnotation] = fmt.Sprintf("conduit/cli %s", version.Version) t.Annotations[k8s.CreatedByAnnotation] = k8s.CreatedByAnnotationValue()
t.Annotations[conduitProxyVersionAnnotation] = conduitVersion t.Annotations[k8s.ProxyVersionAnnotation] = conduitVersion
if t.Labels == nil { if t.Labels == nil {
t.Labels = make(map[string]string) t.Labels = make(map[string]string)
} }
t.Labels[conduitControlLabel] = controlPlaneNamespace t.Labels[k8s.ControllerNSLabel] = controlPlaneNamespace
t.Labels[conduitPlaneLabel] = "data"
t.Spec.Containers = append(t.Spec.Containers, sidecar) t.Spec.Containers = append(t.Spec.Containers, sidecar)
return enhancedPodTemplateSpec{ return enhancedPodTemplateSpec{
t, t,

View File

@ -2,10 +2,12 @@ package cmd
import ( import (
"fmt" "fmt"
"io"
"os" "os"
"regexp" "regexp"
"text/template" "text/template"
"github.com/runconduit/conduit/pkg/k8s"
"github.com/runconduit/conduit/pkg/version" "github.com/runconduit/conduit/pkg/version"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -24,7 +26,7 @@ kind: ServiceAccount
apiVersion: v1 apiVersion: v1
metadata: metadata:
name: conduit-controller name: conduit-controller
namespace: conduit namespace: {{.Namespace}}
### RBAC ### ### RBAC ###
--- ---
@ -45,7 +47,7 @@ kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1 apiVersion: rbac.authorization.k8s.io/v1beta1
metadata: metadata:
name: conduit-controller name: conduit-controller
namespace: conduit namespace: {{.Namespace}}
roleRef: roleRef:
apiGroup: rbac.authorization.k8s.io apiGroup: rbac.authorization.k8s.io
kind: ClusterRole kind: ClusterRole
@ -53,7 +55,7 @@ roleRef:
subjects: subjects:
- kind: ServiceAccount - kind: ServiceAccount
name: conduit-controller name: conduit-controller
namespace: conduit namespace: {{.Namespace}}
### Service Account Prometheus ### ### Service Account Prometheus ###
--- ---
@ -61,7 +63,7 @@ kind: ServiceAccount
apiVersion: v1 apiVersion: v1
metadata: metadata:
name: conduit-prometheus name: conduit-prometheus
namespace: conduit namespace: {{.Namespace}}
### RBAC ### ### RBAC ###
--- ---
@ -79,7 +81,7 @@ kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1 apiVersion: rbac.authorization.k8s.io/v1beta1
metadata: metadata:
name: conduit-prometheus name: conduit-prometheus
namespace: conduit namespace: {{.Namespace}}
roleRef: roleRef:
apiGroup: rbac.authorization.k8s.io apiGroup: rbac.authorization.k8s.io
kind: ClusterRole kind: ClusterRole
@ -87,7 +89,7 @@ roleRef:
subjects: subjects:
- kind: ServiceAccount - kind: ServiceAccount
name: conduit-prometheus name: conduit-prometheus
namespace: conduit namespace: {{.Namespace}}
### Controller ### ### Controller ###
--- ---
@ -98,9 +100,9 @@ metadata:
namespace: {{.Namespace}} namespace: {{.Namespace}}
labels: labels:
app: controller app: controller
conduit.io/plane: control {{.ControllerComponentLabel}}: controller
annotations: annotations:
conduit.io/created-by: "{{.CliVersion}}" {{.CreatedByAnnotation}}: {{.CliVersion}}
spec: spec:
type: ClusterIP type: ClusterIP
selector: selector:
@ -118,9 +120,9 @@ metadata:
namespace: {{.Namespace}} namespace: {{.Namespace}}
labels: labels:
app: controller app: controller
conduit.io/plane: control {{.ControllerComponentLabel}}: controller
annotations: annotations:
conduit.io/created-by: "{{.CliVersion}}" {{.CreatedByAnnotation}}: {{.CliVersion}}
spec: spec:
type: ClusterIP type: ClusterIP
selector: selector:
@ -138,18 +140,18 @@ metadata:
namespace: {{.Namespace}} namespace: {{.Namespace}}
labels: labels:
app: controller app: controller
conduit.io/plane: control {{.ControllerComponentLabel}}: controller
annotations: annotations:
conduit.io/created-by: "{{.CliVersion}}" {{.CreatedByAnnotation}}: {{.CliVersion}}
spec: spec:
replicas: {{.ControllerReplicas}} replicas: {{.ControllerReplicas}}
template: template:
metadata: metadata:
labels: labels:
app: controller app: controller
conduit.io/plane: control {{.ControllerComponentLabel}}: controller
annotations: annotations:
conduit.io/created-by: "{{.CliVersion}}" {{.CreatedByAnnotation}}: {{.CliVersion}}
spec: spec:
serviceAccount: conduit-controller serviceAccount: conduit-controller
containers: containers:
@ -234,9 +236,9 @@ metadata:
namespace: {{.Namespace}} namespace: {{.Namespace}}
labels: labels:
app: web app: web
conduit.io/plane: control {{.ControllerComponentLabel}}: web
annotations: annotations:
conduit.io/created-by: "{{.CliVersion}}" {{.CreatedByAnnotation}}: {{.CliVersion}}
spec: spec:
type: ClusterIP type: ClusterIP
selector: selector:
@ -257,18 +259,18 @@ metadata:
namespace: {{.Namespace}} namespace: {{.Namespace}}
labels: labels:
app: web app: web
conduit.io/plane: control {{.ControllerComponentLabel}}: web
annotations: annotations:
conduit.io/created-by: "{{.CliVersion}}" {{.CreatedByAnnotation}}: {{.CliVersion}}
spec: spec:
replicas: {{.WebReplicas}} replicas: {{.WebReplicas}}
template: template:
metadata: metadata:
labels: labels:
app: web app: web
conduit.io/plane: control {{.ControllerComponentLabel}}: web
annotations: annotations:
conduit.io/created-by: "{{.CliVersion}}" {{.CreatedByAnnotation}}: {{.CliVersion}}
spec: spec:
containers: containers:
- name: web - name: web
@ -297,9 +299,9 @@ metadata:
namespace: {{.Namespace}} namespace: {{.Namespace}}
labels: labels:
app: prometheus app: prometheus
conduit.io/plane: control {{.ControllerComponentLabel}}: prometheus
annotations: annotations:
conduit.io/created-by: "{{.CliVersion}}" {{.CreatedByAnnotation}}: {{.CliVersion}}
spec: spec:
type: ClusterIP type: ClusterIP
selector: selector:
@ -317,18 +319,18 @@ metadata:
namespace: {{.Namespace}} namespace: {{.Namespace}}
labels: labels:
app: prometheus app: prometheus
conduit.io/plane: control {{.ControllerComponentLabel}}: prometheus
annotations: annotations:
conduit.io/created-by: "{{.CliVersion}}" {{.CreatedByAnnotation}}: {{.CliVersion}}
spec: spec:
replicas: {{.PrometheusReplicas}} replicas: {{.PrometheusReplicas}}
template: template:
metadata: metadata:
labels: labels:
app: prometheus app: prometheus
conduit.io/plane: control {{.ControllerComponentLabel}}: prometheus
annotations: annotations:
conduit.io/created-by: "{{.CliVersion}}" {{.CreatedByAnnotation}}: {{.CliVersion}}
spec: spec:
serviceAccount: conduit-prometheus serviceAccount: conduit-prometheus
volumes: volumes:
@ -364,9 +366,9 @@ metadata:
namespace: {{.Namespace}} namespace: {{.Namespace}}
labels: labels:
app: prometheus app: prometheus
conduit.io/plane: control {{.ControllerComponentLabel}}: prometheus
annotations: annotations:
conduit.io/created-by: "{{.CliVersion}}" {{.CreatedByAnnotation}}: {{.CliVersion}}
data: data:
prometheus.yml: |- prometheus.yml: |-
global: global:
@ -393,17 +395,19 @@ data:
` `
type installConfig struct { type installConfig struct {
Namespace string Namespace string
ControllerImage string ControllerImage string
WebImage string WebImage string
PrometheusImage string PrometheusImage string
ControllerReplicas uint ControllerReplicas uint
WebReplicas uint WebReplicas uint
PrometheusReplicas uint PrometheusReplicas uint
ImagePullPolicy string ImagePullPolicy string
UUID string UUID string
CliVersion string CliVersion string
ControllerLogLevel string ControllerLogLevel string
ControllerComponentLabel string
CreatedByAnnotation string
} }
var ( var (
@ -424,27 +428,33 @@ var installCmd = &cobra.Command{
if err := validate(); err != nil { if err := validate(); err != nil {
return err return err
} }
template, err := template.New("conduit").Parse(conduitTemplate) config := installConfig{
if err != nil { Namespace: controlPlaneNamespace,
return err ControllerImage: fmt.Sprintf("%s/controller:%s", dockerRegistry, conduitVersion),
WebImage: fmt.Sprintf("%s/web:%s", dockerRegistry, conduitVersion),
PrometheusImage: "prom/prometheus:v1.8.1",
ControllerReplicas: controllerReplicas,
WebReplicas: webReplicas,
PrometheusReplicas: prometheusReplicas,
ImagePullPolicy: imagePullPolicy,
UUID: uuid.NewV4().String(),
CliVersion: k8s.CreatedByAnnotationValue(),
ControllerLogLevel: controllerLogLevel,
ControllerComponentLabel: k8s.ControllerComponentLabel,
CreatedByAnnotation: k8s.CreatedByAnnotation,
} }
template.Execute(os.Stdout, installConfig{ return render(config, os.Stdout)
Namespace: controlPlaneNamespace,
ControllerImage: fmt.Sprintf("%s/controller:%s", dockerRegistry, conduitVersion),
WebImage: fmt.Sprintf("%s/web:%s", dockerRegistry, conduitVersion),
PrometheusImage: "prom/prometheus:v1.8.1",
ControllerReplicas: controllerReplicas,
WebReplicas: webReplicas,
PrometheusReplicas: prometheusReplicas,
ImagePullPolicy: imagePullPolicy,
UUID: uuid.NewV4().String(),
CliVersion: fmt.Sprintf("conduit/cli %s", version.Version),
ControllerLogLevel: controllerLogLevel,
})
return nil
}, },
} }
func render(config installConfig, w io.Writer) error {
template, err := template.New("conduit").Parse(conduitTemplate)
if err != nil {
return err
}
return template.Execute(w, config)
}
var alphaNumDash = regexp.MustCompile("^[a-zA-Z0-9-]+$") var alphaNumDash = regexp.MustCompile("^[a-zA-Z0-9-]+$")
var alphaNumDashDot = regexp.MustCompile("^[\\.a-zA-Z0-9-]+$") var alphaNumDashDot = regexp.MustCompile("^[\\.a-zA-Z0-9-]+$")
var alphaNumDashDotSlash = regexp.MustCompile("^[\\./a-zA-Z0-9-]+$") var alphaNumDashDotSlash = regexp.MustCompile("^[\\./a-zA-Z0-9-]+$")

51
cli/cmd/install_test.go Normal file
View File

@ -0,0 +1,51 @@
package cmd
import (
"bytes"
"io/ioutil"
"testing"
"github.com/sergi/go-diff/diffmatchpatch"
)
func TestRender(t *testing.T) {
t.Run("Should render an install config", func(t *testing.T) {
goldenFileBytes, err := ioutil.ReadFile("testdata/install_output.golden")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
expectedContent := string(goldenFileBytes)
var buf bytes.Buffer
config := installConfig{
Namespace: "Namespace",
ControllerImage: "ControllerImage",
WebImage: "WebImage",
PrometheusImage: "PrometheusImage",
ControllerReplicas: 1,
WebReplicas: 2,
PrometheusReplicas: 3,
ImagePullPolicy: "ImagePullPolicy",
UUID: "UUID",
CliVersion: "CliVersion",
ControllerLogLevel: "ControllerLogLevel",
ControllerComponentLabel: "ControllerComponentLabel",
CreatedByAnnotation: "CreatedByAnnotation",
}
err = render(config, &buf)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
content := buf.String()
if content != expectedContent {
dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(content, expectedContent, true)
patches := dmp.PatchMake(expectedContent, diffs)
patchText := dmp.PatchToText(patches)
t.Fatalf("Unexpected output:\n%+v", patchText)
}
})
}

378
cli/cmd/testdata/install_output.golden vendored Normal file
View File

@ -0,0 +1,378 @@
### Namespace ###
kind: Namespace
apiVersion: v1
metadata:
name: Namespace
### Service Account Controller ###
---
kind: ServiceAccount
apiVersion: v1
metadata:
name: conduit-controller
namespace: Namespace
### RBAC ###
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: conduit-controller
rules:
- apiGroups: ["extensions"]
resources: ["deployments", "replicasets"]
verbs: ["list", "get", "watch"]
- apiGroups: [""]
resources: ["pods", "endpoints", "services"]
verbs: ["list", "get", "watch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: conduit-controller
namespace: Namespace
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: conduit-controller
subjects:
- kind: ServiceAccount
name: conduit-controller
namespace: Namespace
### Service Account Prometheus ###
---
kind: ServiceAccount
apiVersion: v1
metadata:
name: conduit-prometheus
namespace: Namespace
### RBAC ###
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: conduit-prometheus
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["list", "watch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: conduit-prometheus
namespace: Namespace
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: conduit-prometheus
subjects:
- kind: ServiceAccount
name: conduit-prometheus
namespace: Namespace
### Controller ###
---
kind: Service
apiVersion: v1
metadata:
name: api
namespace: Namespace
labels:
app: controller
ControllerComponentLabel: controller
annotations:
CreatedByAnnotation: CliVersion
spec:
type: ClusterIP
selector:
app: controller
ports:
- name: http
port: 8085
targetPort: 8085
---
kind: Service
apiVersion: v1
metadata:
name: proxy-api
namespace: Namespace
labels:
app: controller
ControllerComponentLabel: controller
annotations:
CreatedByAnnotation: CliVersion
spec:
type: ClusterIP
selector:
app: controller
ports:
- name: grpc
port: 8086
targetPort: 8086
---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: controller
namespace: Namespace
labels:
app: controller
ControllerComponentLabel: controller
annotations:
CreatedByAnnotation: CliVersion
spec:
replicas: 1
template:
metadata:
labels:
app: controller
ControllerComponentLabel: controller
annotations:
CreatedByAnnotation: CliVersion
spec:
serviceAccount: conduit-controller
containers:
- name: public-api
ports:
- name: http
containerPort: 8085
- name: admin-http
containerPort: 9995
image: ControllerImage
imagePullPolicy: ImagePullPolicy
args:
- "public-api"
- "-addr=:8085"
- "-metrics-addr=:9995"
- "-telemetry-addr=127.0.0.1:8087"
- "-tap-addr=127.0.0.1:8088"
- "-log-level=ControllerLogLevel"
- name: destination
ports:
- name: grpc
containerPort: 8089
- name: admin-http
containerPort: 9999
image: ControllerImage
imagePullPolicy: ImagePullPolicy
args:
- "destination"
- "-addr=:8089"
- "-metrics-addr=:9999"
- "-log-level=ControllerLogLevel"
- name: proxy-api
ports:
- name: grpc
containerPort: 8086
- name: admin-http
containerPort: 9996
image: ControllerImage
imagePullPolicy: ImagePullPolicy
args:
- "proxy-api"
- "-addr=:8086"
- "-metrics-addr=:9996"
- "-destination-addr=:8089"
- "-telemetry-addr=:8087"
- "-log-level=ControllerLogLevel"
- name: tap
ports:
- name: grpc
containerPort: 8088
- name: admin-http
containerPort: 9998
image: ControllerImage
imagePullPolicy: ImagePullPolicy
args:
- "tap"
- "-addr=:8088"
- "-metrics-addr=:9998"
- "-log-level=ControllerLogLevel"
- name: telemetry
ports:
- name: grpc
containerPort: 8087
- name: admin-http
containerPort: 9997
image: ControllerImage
imagePullPolicy: ImagePullPolicy
args:
- "telemetry"
- "-addr=:8087"
- "-metrics-addr=:9997"
- "-ignore-namespaces=kube-system"
- "-prometheus-url=http://prometheus:9090"
- "-log-level=ControllerLogLevel"
### Web ###
---
kind: Service
apiVersion: v1
metadata:
name: web
namespace: Namespace
labels:
app: web
ControllerComponentLabel: web
annotations:
CreatedByAnnotation: CliVersion
spec:
type: ClusterIP
selector:
app: web
ports:
- name: http
port: 8084
targetPort: 8084
- name: admin-http
port: 9994
targetPort: 9994
---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: web
namespace: Namespace
labels:
app: web
ControllerComponentLabel: web
annotations:
CreatedByAnnotation: CliVersion
spec:
replicas: 2
template:
metadata:
labels:
app: web
ControllerComponentLabel: web
annotations:
CreatedByAnnotation: CliVersion
spec:
containers:
- name: web
ports:
- name: http
containerPort: 8084
- name: admin-http
containerPort: 9994
image: WebImage
imagePullPolicy: ImagePullPolicy
args:
- "-addr=:8084"
- "-metrics-addr=:9994"
- "-api-addr=api:8085"
- "-static-dir=/dist"
- "-template-dir=/templates"
- "-uuid=UUID"
- "-log-level=ControllerLogLevel"
### Prometheus ###
---
kind: Service
apiVersion: v1
metadata:
name: prometheus
namespace: Namespace
labels:
app: prometheus
ControllerComponentLabel: prometheus
annotations:
CreatedByAnnotation: CliVersion
spec:
type: ClusterIP
selector:
app: prometheus
ports:
- name: http
port: 9090
targetPort: 9090
---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: prometheus
namespace: Namespace
labels:
app: prometheus
ControllerComponentLabel: prometheus
annotations:
CreatedByAnnotation: CliVersion
spec:
replicas: 3
template:
metadata:
labels:
app: prometheus
ControllerComponentLabel: prometheus
annotations:
CreatedByAnnotation: CliVersion
spec:
serviceAccount: conduit-prometheus
volumes:
- name: prometheus-config
configMap:
name: prometheus-config
containers:
- name: prometheus
ports:
- name: http
containerPort: 9090
volumeMounts:
- name: prometheus-config
mountPath: /etc/prometheus
readOnly: true
image: PrometheusImage
imagePullPolicy: ImagePullPolicy
args:
- "-storage.local.retention=6h"
- "-storage.local.memory-chunks=500000"
- "-config.file=/etc/prometheus/prometheus.yml"
# TODO remove/replace?
- name: kubectl
image: buoyantio/kubectl:v1.6.2
args: ["proxy", "-p", "8001"]
---
kind: ConfigMap
apiVersion: v1
metadata:
name: prometheus-config
namespace: Namespace
labels:
app: prometheus
ControllerComponentLabel: prometheus
annotations:
CreatedByAnnotation: CliVersion
data:
prometheus.yml: |-
global:
scrape_interval: 10s
evaluation_interval: 10s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'controller'
kubernetes_sd_configs:
- role: pod
namespaces:
names: ['Namespace']
relabel_configs:
- source_labels: [__meta_kubernetes_pod_container_port_name]
action: keep
regex: ^admin-http$
- source_labels: [__meta_kubernetes_pod_container_name]
action: replace
target_label: job

View File

@ -1,5 +1,5 @@
## compile controller services ## compile controller services
FROM gcr.io/runconduit/go-deps:dac3fae6 as golang FROM gcr.io/runconduit/go-deps:7bceac7a as golang
ARG CONDUIT_VERSION ARG CONDUIT_VERSION
WORKDIR /go/src/github.com/runconduit/conduit WORKDIR /go/src/github.com/runconduit/conduit
COPY controller controller COPY controller controller

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"net"
"net/http" "net/http"
"reflect" "reflect"
"testing" "testing"
@ -65,13 +66,13 @@ func TestServer(t *testing.T) {
grpcServer: mockGrpcServer, grpcServer: mockGrpcServer,
} }
httpServer := &http.Server{ listener, err := net.Listen("tcp", "localhost:8889")
Addr: "localhost:8889", if err != nil {
Handler: handler, t.Fatalf("Could not start listener: %v", err)
} }
go func() { go func() {
err := httpServer.ListenAndServe() err := http.Serve(listener, handler)
if err != nil { if err != nil {
t.Fatalf("Could not start server: %v", err) t.Fatalf("Could not start server: %v", err)
} }

View File

@ -20,6 +20,7 @@ import (
public "github.com/runconduit/conduit/controller/gen/public" public "github.com/runconduit/conduit/controller/gen/public"
"github.com/runconduit/conduit/controller/k8s" "github.com/runconduit/conduit/controller/k8s"
"github.com/runconduit/conduit/controller/util" "github.com/runconduit/conduit/controller/util"
pkgK8s "github.com/runconduit/conduit/pkg/k8s"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
"google.golang.org/grpc" "google.golang.org/grpc"
@ -238,8 +239,8 @@ func (s *server) ListPods(ctx context.Context, req *read.ListPodsRequest) (*publ
status = "Terminating" status = "Terminating"
} }
plane, _ := pod.Labels["conduit.io/plane"] controllerComponent := pod.Labels[pkgK8s.ControllerComponentLabel]
controller, _ := pod.Labels["conduit.io/controller"] controllerNS := pod.Labels[pkgK8s.ControllerNSLabel]
item := &public.Pod{ item := &public.Pod{
Name: pod.Namespace + "/" + pod.Name, Name: pod.Namespace + "/" + pod.Name,
@ -247,8 +248,8 @@ func (s *server) ListPods(ctx context.Context, req *read.ListPodsRequest) (*publ
Status: status, Status: status,
PodIP: pod.Status.PodIP, PodIP: pod.Status.PodIP,
Added: added, Added: added,
ControllerNamespace: controller, ControllerNamespace: controllerNS,
ControlPlane: plane == "control", ControlPlane: controllerComponent != "",
} }
if added { if added {
since := time.Since(updated) since := time.Since(updated)

44
pkg/k8s/labels.go Normal file
View File

@ -0,0 +1,44 @@
/*
Kubernetes labels and annotations used in Conduit's control plane and data plane
Kubernetes configs.
*/
package k8s
import (
"fmt"
"github.com/runconduit/conduit/pkg/version"
)
const (
/*
* Labels
*/
// ControllerComponentLabel identifies this object as a component of Conduit's
// control plane (e.g. web, controller).
ControllerComponentLabel = "conduit.io/control-plane-component"
// ControllerNSLabel is injected into mesh-enabled apps, identifying the
// namespace of the Conduit control plane.
ControllerNSLabel = "conduit.io/control-plane-ns"
/*
* Annotations
*/
// CreatedByAnnotation indicates the source of the injected data plane
// (e.g. conduit/cli v0.1.3).
CreatedByAnnotation = "conduit.io/created-by"
// ProxyVersionAnnotation indicates the version of the injected data plane
// (e.g. v0.1.3).
ProxyVersionAnnotation = "conduit.io/proxy-version"
)
// CreatedByAnnotationValue returns the value associated with
// CreatedByAnnotation.
func CreatedByAnnotationValue() string {
return fmt.Sprintf("conduit/cli %s", version.Version)
}

View File

@ -1,5 +1,5 @@
## compile proxy-init utility ## compile proxy-init utility
FROM gcr.io/runconduit/go-deps:dac3fae6 as golang FROM gcr.io/runconduit/go-deps:7bceac7a as golang
WORKDIR /go/src/github.com/runconduit/conduit WORKDIR /go/src/github.com/runconduit/conduit
COPY ./proxy-init ./proxy-init COPY ./proxy-init ./proxy-init
RUN CGO_ENABLED=0 GOOS=linux go install -v -a -installsuffix cgo ./proxy-init/ RUN CGO_ENABLED=0 GOOS=linux go install -v -a -installsuffix cgo ./proxy-init/

View File

@ -5,7 +5,7 @@
## Build the rust proxy into a binary. ## Build the rust proxy into a binary.
# #
# If the RELEASE arg is set and non-empty, a release artifact is built. # If the RELEASE arg is set and non-empty, a release artifact is built.
FROM gcr.io/runconduit/proxy-deps:fb72d14b as build FROM gcr.io/runconduit/proxy-deps:b84ed5d0 as build
WORKDIR /usr/src/conduit WORKDIR /usr/src/conduit
# Ranked roughly from least to most likely to change. Cargo.lock is the least likely # Ranked roughly from least to most likely to change. Cargo.lock is the least likely
# because it is supposed to be cached in the deps base image. # because it is supposed to be cached in the deps base image.

View File

@ -4,7 +4,7 @@
# are omitted from the resulting image so that artifacts may be built from source over # are omitted from the resulting image so that artifacts may be built from source over
# this image. # this image.
# #
# When this file is changed, you must run `bin/update-go-deps-shas`. # When this file is changed, you must run `bin/update-proxy-deps-shas`.
# Compile the application to ensure we've obtained all build dependencies and that they # Compile the application to ensure we've obtained all build dependencies and that they
# compile. # compile.

View File

@ -12,7 +12,7 @@ RUN $HOME/.yarn/bin/yarn install --pure-lockfile
RUN $HOME/.yarn/bin/yarn webpack RUN $HOME/.yarn/bin/yarn webpack
## compile go server ## compile go server
FROM gcr.io/runconduit/go-deps:dac3fae6 as golang FROM gcr.io/runconduit/go-deps:7bceac7a as golang
ARG CONDUIT_VERSION ARG CONDUIT_VERSION
WORKDIR /go/src/github.com/runconduit/conduit WORKDIR /go/src/github.com/runconduit/conduit
COPY web web COPY web web