Skip to content

Commit c04570c

Browse files
committed
first
0 parents  commit c04570c

Some content is hidden

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

53 files changed

+2837
-0
lines changed

.dockerignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore build and test binaries.
3+
bin/
4+
testbin/

.gitignore

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.vscode
2+
open-feature-operator
3+
of-agent
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
bin
11+
testbin/*
12+
13+
# Test binary, build with `go test -c`
14+
*.test
15+
16+
# Output of the go coverage tool, specifically when used with LiteIDE
17+
*.out
18+
19+
# Kubernetes Generated files - skip generated files, except for vendored files
20+
21+
!vendor/**/zz_generated.*
22+
23+
# editor and IDE paraphernalia
24+
.idea
25+
*.swp
26+
*.swo
27+
*~

Dockerfile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Build the manager binary
2+
FROM --platform=$BUILDPLATFORM golang:1.17-alpine AS builder
3+
4+
WORKDIR /workspace
5+
ARG TARGETOS
6+
ARG TARGETARCH
7+
# Copy the Go Modules manifests
8+
COPY go.mod go.mod
9+
COPY go.sum go.sum
10+
# cache deps before building and copying source so that we don't need to re-download as much
11+
# and so that source changes don't invalidate our downloaded layer
12+
RUN go mod download
13+
14+
# Copy the go source
15+
COPY main.go main.go
16+
COPY apis/ apis/
17+
COPY webhooks/ webhooks/
18+
COPY controllers/ controllers/
19+
20+
# Build
21+
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -o manager main.go
22+
23+
# Use distroless as minimal base image to package the manager binary
24+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
25+
FROM gcr.io/distroless/static:nonroot
26+
WORKDIR /
27+
COPY --from=builder /workspace/manager .
28+
USER 65532:65532
29+
30+
ENTRYPOINT ["/manager"]

Makefile

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
2+
# Image URL to use all building/pushing image targets
3+
IMG ?= controller:latest
4+
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5+
ENVTEST_K8S_VERSION = 1.23
6+
7+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
8+
ifeq (,$(shell go env GOBIN))
9+
GOBIN=$(shell go env GOPATH)/bin
10+
else
11+
GOBIN=$(shell go env GOBIN)
12+
endif
13+
14+
# Setting SHELL to bash allows bash commands to be executed by recipes.
15+
# This is a requirement for 'setup-envtest.sh' in the test target.
16+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
17+
SHELL = /usr/bin/env bash -o pipefail
18+
.SHELLFLAGS = -ec
19+
20+
.PHONY: all
21+
all: build
22+
23+
##@ General
24+
25+
# The help target prints out all targets with their descriptions organized
26+
# beneath their categories. The categories are represented by '##@' and the
27+
# target descriptions by '##'. The awk commands is responsible for reading the
28+
# entire set of makefiles included in this invocation, looking for lines of the
29+
# file as xyz: ## something, and then pretty-format the target and help. Then,
30+
# if there's a line with ##@ something, that gets pretty-printed as a category.
31+
# More info on the usage of ANSI control characters for terminal formatting:
32+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
33+
# More info on the awk command:
34+
# http://linuxcommand.org/lc3_adv_awk.php
35+
36+
.PHONY: help
37+
help: ## Display this help.
38+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
39+
40+
##@ Development
41+
42+
.PHONY: manifests
43+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
44+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
45+
46+
.PHONY: generate
47+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
48+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
49+
50+
.PHONY: fmt
51+
fmt: ## Run go fmt against code.
52+
go fmt ./...
53+
54+
.PHONY: vet
55+
vet: ## Run go vet against code.
56+
go vet ./...
57+
58+
.PHONY: test
59+
test: manifests generate fmt vet envtest ## Run tests.
60+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
61+
62+
##@ Build
63+
64+
.PHONY: build
65+
build: generate fmt vet ## Build manager binary.
66+
go build -o bin/manager main.go
67+
68+
.PHONY: run
69+
run: manifests generate fmt vet ## Run a controller from your host.
70+
go run ./main.go
71+
72+
.PHONY: docker-build
73+
docker-build: ## Build docker image with the manager.
74+
docker buildx build --platform="linux/amd64,linux/arm64" -t ${IMG} . --push
75+
76+
.PHONY: docker-push
77+
docker-push: ## Push docker image with the manager.
78+
docker push ${IMG}
79+
80+
##@ Deployment
81+
82+
ifndef ignore-not-found
83+
ignore-not-found = false
84+
endif
85+
86+
.PHONY: install
87+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
88+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
89+
90+
.PHONY: uninstall
91+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
92+
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
93+
94+
.PHONY: deploy
95+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
96+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
97+
$(KUSTOMIZE) build config/default | kubectl apply -f -
98+
99+
.PHONY: undeploy
100+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
101+
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
102+
103+
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
104+
.PHONY: controller-gen
105+
controller-gen: ## Download controller-gen locally if necessary.
106+
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0)
107+
108+
KUSTOMIZE = $(shell pwd)/bin/kustomize
109+
.PHONY: kustomize
110+
kustomize: ## Download kustomize locally if necessary.
111+
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v3.8.7)
112+
113+
ENVTEST = $(shell pwd)/bin/setup-envtest
114+
.PHONY: envtest
115+
envtest: ## Download envtest-setup locally if necessary.
116+
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
117+
118+
# go-get-tool will 'go get' any package $2 and install it to $1.
119+
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
120+
define go-get-tool
121+
@[ -f $(1) ] || { \
122+
set -e ;\
123+
TMP_DIR=$$(mktemp -d) ;\
124+
cd $$TMP_DIR ;\
125+
go mod init tmp ;\
126+
echo "Downloading $(2)" ;\
127+
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
128+
rm -rf $$TMP_DIR ;\
129+
}
130+
endef

PROJECT

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
domain: openfeature.dev
2+
layout:
3+
- go.kubebuilder.io/v3
4+
multigroup: true
5+
projectName: open-feature-operator
6+
repo: github.com/open-feature/open-feature-operator
7+
resources:
8+
- api:
9+
crdVersion: v1
10+
namespaced: true
11+
controller: true
12+
domain: openfeature.dev
13+
group: core
14+
kind: FeatureFlagConfiguration
15+
path: github.com/open-feature/open-feature-operator/api/v1alpha1
16+
version: v1alpha1
17+
- api:
18+
crdVersion: v1
19+
namespaced: true
20+
controller: true
21+
domain: openfeature.dev
22+
group: core
23+
kind: Deployment
24+
path: github.com/open-feature/open-feature-operator/api/v1alpha1
25+
version: v1alpha1
26+
webhooks:
27+
defaulting: true
28+
validation: true
29+
webhookVersion: v1
30+
- group: apps
31+
kind: Deployment
32+
path: k8s.io/api/apps/v1
33+
version: v1
34+
webhooks:
35+
defaulting: true
36+
validation: true
37+
webhookVersion: v1
38+
version: "3"

README.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
## open-feature-operator
2+
3+
The open-feature-operator is a Kubernetes native operator that allows you to expose feature flags to your applications. It injects a [flagd](https://github.com/open-feature/flagd) sidecar into your pod and allows you to poll the flagd server for feature flags in a variety of ways.
4+
5+
### Architecture
6+
7+
As per the issue [here](https://github.com/open-feature/research/issues/1)
8+
High level architecture is as follows:
9+
10+
<img src="images/arch-0.png" width="560">
11+
12+
13+
### Installation
14+
0. Active Kubernetes cluster of v1.22 or higher
15+
1. Install cert manager `kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.8.0/cert-manager.yaml`
16+
2. Install components
17+
```
18+
docker buildx build --platform="linux/amd64,linux/arm64" -t tibbar/of-operator:v1.2 . --push
19+
IMG=tibbar/of-operator:v1.2 make generate
20+
IMG=tibbar/of-operator:v1.2 make deploy
21+
```
22+
23+
### Example
24+
25+
When wishing to leverage featureflagging within the local pod, the following steps are required:
26+
27+
1. Create a new feature flag custom resource e.g.
28+
```
29+
apiVersion: core.openfeature.dev/v1alpha1
30+
kind: FeatureFlagConfiguration
31+
metadata:
32+
name: featureflagconfiguration-sample
33+
spec:
34+
featureFlagSpec: |
35+
{
36+
"foo" : "bar"
37+
}
38+
```
39+
40+
2. Reference the CR within the pod spec annotations
41+
```
42+
apiVersion: v1
43+
kind: Pod
44+
metadata:
45+
name: nginx
46+
annotations:
47+
openfeature.dev: "enabled"
48+
openfeature.dev/featureflagconfiguration: "featureflagconfiguration-sample"
49+
spec:
50+
containers:
51+
- name: nginx
52+
image: nginx:1.14.2
53+
ports:
54+
- containerPort: 80
55+
```
56+
57+
3. Example usage from host container
58+
59+
```
60+
root@nginx:/# curl localhost:8080
61+
{
62+
"foo" : "bar"
63+
}
64+
```
65+
66+
### TODO
67+
68+
* [ ] Implement feature flag reconciliation loop
69+
* [ ] Detect and update configmaps on change
70+
* [ ] Finalizers
71+
* [ ] Cleanup on deletion
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Copyright 2022.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
24+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
25+
26+
// FeatureFlagConfigurationSpec defines the desired state of FeatureFlagConfiguration
27+
type FeatureFlagConfigurationSpec struct {
28+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
29+
// Important: Run "make" to regenerate code after modifying this file
30+
31+
// Foo is an example field of FeatureFlagConfiguration. Edit featureflagconfiguration_types.go to remove/update
32+
FeatureFlagSpec string `json:"featureFlagSpec,omitempty"`
33+
}
34+
35+
// FeatureFlagConfigurationStatus defines the observed state of FeatureFlagConfiguration
36+
type FeatureFlagConfigurationStatus struct {
37+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
38+
// Important: Run "make" to regenerate code after modifying this file
39+
}
40+
41+
//+kubebuilder:object:root=true
42+
//+kubebuilder:subresource:status
43+
44+
// FeatureFlagConfiguration is the Schema for the featureflagconfigurations API
45+
type FeatureFlagConfiguration struct {
46+
metav1.TypeMeta `json:",inline"`
47+
metav1.ObjectMeta `json:"metadata,omitempty"`
48+
49+
Spec FeatureFlagConfigurationSpec `json:"spec,omitempty"`
50+
Status FeatureFlagConfigurationStatus `json:"status,omitempty"`
51+
}
52+
53+
//+kubebuilder:object:root=true
54+
55+
// FeatureFlagConfigurationList contains a list of FeatureFlagConfiguration
56+
type FeatureFlagConfigurationList struct {
57+
metav1.TypeMeta `json:",inline"`
58+
metav1.ListMeta `json:"metadata,omitempty"`
59+
Items []FeatureFlagConfiguration `json:"items"`
60+
}
61+
62+
func init() {
63+
SchemeBuilder.Register(&FeatureFlagConfiguration{}, &FeatureFlagConfigurationList{})
64+
}

0 commit comments

Comments
 (0)