Skip to content

Commit 2d5c231

Browse files
authored
Merge pull request #2 from att-cloudnative-labs/knative-service-configure
Knative service configure
2 parents 658a060 + 0958ad9 commit 2d5c231

File tree

2,315 files changed

+6687
-657016
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,315 files changed

+6687
-657016
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
## Development release
44

5+
0.7.0-BETA-1
6+
7+
- KconfigBindings renamed to DeploymentBinding
8+
- Support for StatefulSets with an accompanying resource StatefulSetBinding
9+
- Support for Knative Services with an accompanying resource KnativeServiceBinding
10+
- Pkg names are now aligned with github location
11+
- Binary and k8s resources renamed from kconfig-controller-manager to kconfig-controller
12+
513
0.6.0-BETA-1
614

715
- ExternalResources (ConfigMaps/Secrets) are now updated in one kubernetes api call per resource. Previously, multiple value changes (or adds) would result in an attempt to update the secret or configmap for each change. This would create a conflict error forcing the remaining values to be updated in retries.

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Go parameters
2-
VERSION=v0.6.0-beta-1
3-
DOCKERIMAGE=docker-registry.aeg.cloud/common-system/kconfig-controller
2+
VERSION=v0.7.0-beta-1
3+
DOCKERIMAGE=docker-registry.aeg.cloud/kconfig-system/kconfig-controller
44
GOCMD=go
55
GOBUILD=$(GOCMD) build
66
GOCLEAN=$(GOCMD) clean
77
GOTEST=$(GOCMD) test
88
GOGET=$(GOCMD) get
9-
KCONFIGPKG=github.com/gbraxton/kconfig/cmd
9+
KCONFIGPKG=github.com/att-cloudnative-labs/kconfig-controller/cmd
1010
CLIENTSET=pkg/client/clientset/versioned/clientset.go
1111
BINARY_NAME=kconfig-controller
1212
BINARY_UNIX=$(BINARY_NAME)_unix

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
----
44

5-
Kconfig is a Kubernetes Custom-controller and CRD for externalizing configuration of Kubernetes deployments. Kconfig allows environment variables to be defined in a single resource that selects deployments based on labels, and inserts the specified environment variables into the deployment.
5+
Kconfig is a Kubernetes Custom-controller and CRD for externalizing configuration of Kubernetes deployments, statefulsets, and knative services. Kconfig allows environment variables to be defined in a single resource that selects the target workload resource based on labels, and inserts the specified environment variables into the target workload resource.
66

7-
Multiple Kconfig resources can select a single deployment and the deployment will have the aggregation of each of those Kconfigs. In addition, Kconfigs have a level field which determines the order, in relation to other Kconfigs that select the same deployment, in which enviroment variables from multiple Kconfigs are defined in the container environment.
7+
Multiple Kconfig resources can select a single target resource and the target will have the aggregation of each of those Kconfigs. In addition, Kconfigs have a level field which determines the order, in relation to other Kconfigs that select the same target resource, in which environment variables from multiple Kconfigs are defined in the container environment.
88

99
Aside from defining simple key/value pairs, Kconfigs can also define and reference environment variables to be stored in configmaps and/or secrets.
1010

11-
For a deployment to have its environment variables controlled by Kconfigs, it needs the annotation ```kconfigcontroller.atteg.com/env=true```.
11+
For a target to have its environment variables controlled by Kconfigs, it needs the annotation ```kconfigcontroller.atteg.com/env=true```.
1212

13-
Kconfigs have a secondary resource, KconfigBindings. These resources should not be created/manipulated directly by users and are used by the control loops. These KconfigBinding resources serve as a target for Kconfigs to update their changes whereafter, the controller can re-processed the contained enviroment variables for all Kconfigs that target a particular deployment. Note that there will always be one KconfigBinding for each Deployment that contains the kconfig enabled annotation shown above.
13+
Kconfig-controller also has secondary resources, DeploymentBindings, StatefulSetBindings, and KnativeServiceBindings. These resources should not be created/manipulated directly by users and are used by the control loops. These resources serve as a target for Kconfigs to update their changes whereafter, the controller can re-processed the contained environment variables for all Kconfigs that target a particular deployment, statefulset, or knative service. Note that there will always be one of these 'binding resources for each workload resource that contains the kconfig enabled annotation shown above.
1414

1515
----
1616

@@ -61,7 +61,7 @@ The first envConfig is a 'Value' type. An empty type field implies a 'Value' typ
6161
## Build
6262
6363
```bash
64-
docker build -f build/Dockerfile -t docker-registry.aeg.cloud/common-system/kconfig-controller:v0.6.0-beta-1 .
64+
docker build -f build/Dockerfile -t docker-registry.aeg.cloud/kconfig-system/kconfig-controller:v0.7.0-beta-1 .
6565
```
6666

6767
## Installation
@@ -75,5 +75,4 @@ kubectl apply -f install/
7575
* Ability to select the container configs apply to. Currently the configs are only placed in the first container in a pod template
7676
* Validate that all existing configmap/secret references in a Kconfig exists and if not, removed them from the Kconfig
7777
* Support for files form and mount locations for files through Kconfigs
78-
* Possible move to injecting the environment variables directly to pods through a custom admission controller
79-
* Support for configuring Statefulsets
78+
* Possible move to injecting the environment variables directly to pods through a custom admission controller

build/Dockerfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
FROM docker.io/golang:1.11 as buildimage
1+
FROM docker.io/golang:1.12.4 as buildimage
22

3-
COPY cmd $GOPATH/src/github.com/gbraxton/kconfig/cmd
4-
COPY internal $GOPATH/src/github.com/gbraxton/kconfig/internal
5-
COPY pkg $GOPATH/src/github.com/gbraxton/kconfig/pkg
6-
COPY vendor $GOPATH/src/github.com/gbraxton/kconfig/vendor
7-
WORKDIR $GOPATH/src/github.com/gbraxton/kconfig/
3+
COPY cmd $GOPATH/src/github.com/att-cloudnative-labs/kconfig-controller/cmd
4+
COPY internal $GOPATH/src/github.com/att-cloudnative-labs/kconfig-controller/internal
5+
COPY pkg $GOPATH/src/github.com/att-cloudnative-labs/kconfig-controller/pkg
6+
COPY go.mod $GOPATH/src/github.com/att-cloudnative-labs/kconfig-controller/go.mod
7+
COPY go.sum $GOPATH/src/github.com/att-cloudnative-labs/kconfig-controller/go.sum
8+
WORKDIR $GOPATH/src/github.com/att-cloudnative-labs/kconfig-controller
89

910
# minimal passwd file is created for user in scratch image
1011
# Empty file is needed to create /tmp directory in scratch image
11-
RUN go get -d -v ./... && \
12-
CGO_ENABLED=0 go build -o /go/bin/kconfig-controller github.com/gbraxton/kconfig/cmd && \
12+
RUN GO111MODULE=on CGO_ENABLED=0 go build -o /go/bin/kconfig-controller ./cmd && \
1313
echo "kconfig:x:1001:1001::/:" > /tmp/passwd.minimal && \
1414
touch /tmp/.empty
1515

cmd/kconfig-controller-manager/app/controllermanager.go

Lines changed: 0 additions & 102 deletions
This file was deleted.
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
package app
2+
3+
import (
4+
"k8s.io/client-go/rest"
5+
"time"
6+
7+
"github.com/spf13/cobra"
8+
9+
"github.com/att-cloudnative-labs/kconfig-controller/internal/app/kconfig-controller/controller/deployment"
10+
"github.com/att-cloudnative-labs/kconfig-controller/internal/app/kconfig-controller/controller/deploymentbinding"
11+
"github.com/att-cloudnative-labs/kconfig-controller/internal/app/kconfig-controller/controller/kconfig"
12+
"github.com/att-cloudnative-labs/kconfig-controller/internal/app/kconfig-controller/controller/knativeservice"
13+
"github.com/att-cloudnative-labs/kconfig-controller/internal/app/kconfig-controller/controller/knativeservicebinding"
14+
"github.com/att-cloudnative-labs/kconfig-controller/internal/app/kconfig-controller/controller/statefulset"
15+
"github.com/att-cloudnative-labs/kconfig-controller/internal/app/kconfig-controller/controller/statefulsetbinding"
16+
"github.com/att-cloudnative-labs/kconfig-controller/internal/app/kconfig-controller/server"
17+
clientset "github.com/att-cloudnative-labs/kconfig-controller/pkg/client/clientset/versioned"
18+
knclientset "github.com/knative/serving/pkg/client/clientset/versioned"
19+
20+
// _ "github.com/att-cloudnative-labs/kconfig-controller/pkg/client/clientset/versioned/scheme"
21+
informers "github.com/att-cloudnative-labs/kconfig-controller/pkg/client/informers/externalversions"
22+
kninformers "github.com/knative/serving/pkg/client/informers/externalversions"
23+
kubeinformers "k8s.io/client-go/informers"
24+
"k8s.io/client-go/kubernetes"
25+
"k8s.io/client-go/tools/clientcmd"
26+
"k8s.io/klog"
27+
"k8s.io/sample-controller/pkg/signals"
28+
)
29+
30+
// NewControllerManagerCommand creates a *cobra.Command object with default parameters
31+
func NewControllerManagerCommand() *cobra.Command {
32+
cmd := &cobra.Command{
33+
Use: "kconfig-controller-manager",
34+
Long: `The Kconfig controller-manager is a daemon controller that provides the
35+
functionality for enacting the state defined in a Kconfig and its associated
36+
resources.`,
37+
Run: run,
38+
}
39+
cmd.Flags().String("master", "", "apiserver url")
40+
cmd.Flags().String("kubeconfig", "", "location of kubeconfig")
41+
return cmd
42+
}
43+
44+
func run(cmd *cobra.Command, args []string) {
45+
46+
masterURL, _ := cmd.Flags().GetString("master")
47+
kubeconfig, _ := cmd.Flags().GetString("kubeconfig")
48+
knativeServicesEnabled, _ := cmd.Flags().GetBool("knative")
49+
50+
// set up signals so we handle the first shutdown signal gracefully
51+
stopCh := signals.SetupSignalHandler()
52+
53+
cfg, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfig)
54+
if err != nil {
55+
klog.Fatalf("Error building kubeconfig: %s", err.Error())
56+
}
57+
58+
stdClient, err := kubernetes.NewForConfig(cfg)
59+
if err != nil {
60+
klog.Fatalf("Error building kubernetes clientset: %s", err.Error())
61+
}
62+
63+
kconfigClient, err := clientset.NewForConfig(cfg)
64+
if err != nil {
65+
klog.Fatalf("Error building kconfig clientset: %s", err.Error())
66+
}
67+
68+
69+
70+
stdInformerFactory := kubeinformers.NewSharedInformerFactory(stdClient, time.Second*30)
71+
kconfigInformerFactory := informers.NewSharedInformerFactory(kconfigClient, time.Second*30)
72+
73+
74+
deploymentBindingController := deploymentbinding.NewController(
75+
stdClient,
76+
kconfigClient,
77+
stdInformerFactory.Core().V1().ConfigMaps(),
78+
stdInformerFactory.Core().V1().Secrets(),
79+
stdInformerFactory.Apps().V1().Deployments(),
80+
kconfigInformerFactory.Kconfigcontroller().V1alpha1().DeploymentBindings(),
81+
)
82+
83+
statefulSetBindingController := statefulsetbinding.NewController(
84+
stdClient,
85+
kconfigClient,
86+
stdInformerFactory.Core().V1().ConfigMaps(),
87+
stdInformerFactory.Core().V1().Secrets(),
88+
stdInformerFactory.Apps().V1().StatefulSets(),
89+
kconfigInformerFactory.Kconfigcontroller().V1alpha1().StatefulSetBindings(),
90+
)
91+
92+
93+
94+
deploymentController := deployment.NewController(
95+
stdClient,
96+
kconfigClient,
97+
stdInformerFactory.Apps().V1().Deployments(),
98+
kconfigInformerFactory.Kconfigcontroller().V1alpha1().DeploymentBindings(),
99+
)
100+
101+
statefulSetController := statefulset.NewController(
102+
stdClient,
103+
kconfigClient,
104+
stdInformerFactory.Apps().V1().StatefulSets(),
105+
kconfigInformerFactory.Kconfigcontroller().V1alpha1().StatefulSetBindings(),
106+
)
107+
108+
109+
110+
kconfigController := kconfig.NewController(
111+
stdClient,
112+
kconfigClient,
113+
stdInformerFactory.Core().V1().ConfigMaps(),
114+
stdInformerFactory.Core().V1().Secrets(),
115+
kconfigInformerFactory.Kconfigcontroller().V1alpha1().Kconfigs(),
116+
kconfigInformerFactory.Kconfigcontroller().V1alpha1().DeploymentBindings(),
117+
kconfigInformerFactory.Kconfigcontroller().V1alpha1().StatefulSetBindings(),
118+
kconfigInformerFactory.Kconfigcontroller().V1alpha1().KnativeServiceBindings(),
119+
)
120+
121+
go stdInformerFactory.Start(stopCh)
122+
go kconfigInformerFactory.Start(stopCh)
123+
124+
if knativeServicesEnabled {
125+
startKnativeControllers(cfg, stdClient, kconfigClient, stdInformerFactory, kconfigInformerFactory, stopCh)
126+
}
127+
128+
go deploymentBindingController.Run(2, stopCh)
129+
go statefulSetBindingController.Run(2, stopCh)
130+
131+
132+
go deploymentController.Run(2, stopCh)
133+
go statefulSetController.Run(2, stopCh)
134+
135+
136+
go kconfigController.Run(2, stopCh)
137+
138+
serverCfg := server.Cfg{Port: 8080}
139+
server := server.NewServer(serverCfg)
140+
go server.Start()
141+
defer server.Stop()
142+
143+
<-stopCh
144+
klog.Infof("Shutting down main process")
145+
}
146+
147+
func startKnativeControllers(cfg *rest.Config, stdClient kubernetes.Interface, kconfigClient clientset.Interface, stdInformerFactory kubeinformers.SharedInformerFactory, kconfigInformerFactory informers.SharedInformerFactory, stopCh <-chan struct{}) {
148+
knativeClient, err := knclientset.NewForConfig(cfg)
149+
if err != nil {
150+
klog.Fatalf("Error building knative clientset: %s", err.Error())
151+
}
152+
153+
knativeInformerFactory := kninformers.NewSharedInformerFactory(knativeClient, time.Second*30)
154+
155+
knativeServiceBindingController := knativeservicebinding.NewController(
156+
stdClient,
157+
kconfigClient,
158+
knativeClient,
159+
stdInformerFactory.Core().V1().ConfigMaps(),
160+
stdInformerFactory.Core().V1().Secrets(),
161+
knativeInformerFactory.Serving().V1alpha1().Services(),
162+
kconfigInformerFactory.Kconfigcontroller().V1alpha1().KnativeServiceBindings(),
163+
)
164+
go knativeServiceBindingController.Run(2, stopCh)
165+
166+
knativeServiceController := knativeservice.NewController(
167+
stdClient,
168+
knativeClient,
169+
kconfigClient,
170+
knativeInformerFactory.Serving().V1alpha1().Services(),
171+
kconfigInformerFactory.Kconfigcontroller().V1alpha1().KnativeServiceBindings(),
172+
)
173+
go knativeServiceController.Run(2, stopCh)
174+
175+
go knativeInformerFactory.Start(stopCh)
176+
}

cmd/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"k8s.io/klog"
1111

12-
"github.com/gbraxton/kconfig/cmd/kconfig-controller-manager/app"
12+
"github.com/att-cloudnative-labs/kconfig-controller/cmd/kconfig-controller/app"
1313
)
1414

1515
func main() {
@@ -20,6 +20,7 @@ func main() {
2020

2121
command := app.NewControllerManagerCommand()
2222
command.Flags().AddGoFlagSet(goflag.CommandLine)
23+
command.Flags().Bool("knative", false, "enable configuration of knative services")
2324

2425
if err := command.Execute(); err != nil {
2526
fmt.Fprintf(os.Stderr, "%v\n", err)

0 commit comments

Comments
 (0)