Skip to content

Commit 43f93aa

Browse files
authored
Merge pull request #2 from oranichu/main
Initial release of golang Skydive operator
2 parents b5e6218 + 651bd0e commit 43f93aa

File tree

90 files changed

+5283
-0
lines changed

Some content is hidden

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

90 files changed

+5283
-0
lines changed

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/skydive-golang-operator.iml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

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

Makefile

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
# Image URL to use all building/pushing image targets
3+
IMG ?= controller:latest
4+
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
5+
CRD_OPTIONS ?= "crd:crdVersions=v1"
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+
all: manager
15+
16+
# Run tests
17+
test: generate fmt vet manifests
18+
go test ./... -coverprofile cover.out
19+
20+
# Build manager binary
21+
manager: generate fmt vet
22+
go build -o bin/manager main.go
23+
24+
# Run against the configured Kubernetes cluster in ~/.kube/config
25+
run: generate fmt vet manifests
26+
go run ./main.go
27+
28+
# Install CRDs into a cluster
29+
install: manifests
30+
kustomize build config/crd | kubectl apply -f -
31+
32+
# Uninstall CRDs from a cluster
33+
uninstall: manifests
34+
kustomize build config/crd | kubectl delete -f -
35+
36+
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
37+
deploy: manifests
38+
cd config/manager && kustomize edit set image controller=${IMG}
39+
kustomize build config/default | kubectl apply -f -
40+
41+
# Generate manifests e.g. CRD, RBAC etc.
42+
manifests: controller-gen
43+
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
44+
45+
# Run go fmt against code
46+
fmt:
47+
go fmt ./...
48+
49+
# Run go vet against code
50+
vet:
51+
go vet ./...
52+
53+
# Generate code
54+
generate: controller-gen
55+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
56+
57+
# Build the docker image
58+
docker-build: test
59+
docker build . -t ${IMG}
60+
61+
# Push the docker image
62+
docker-push:
63+
docker push ${IMG}
64+
65+
# find or download controller-gen
66+
# download controller-gen if necessary
67+
controller-gen:
68+
ifeq (, $(shell which controller-gen))
69+
@{ \
70+
set -e ;\
71+
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
72+
cd $$CONTROLLER_GEN_TMP_DIR ;\
73+
go mod init tmp ;\
74+
go get sigs.k8s.io/controller-tools/cmd/[email protected] ;\
75+
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
76+
}
77+
CONTROLLER_GEN=$(GOBIN)/controller-gen
78+
else
79+
CONTROLLER_GEN=$(shell which controller-gen)
80+
endif

PROJECT

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
domain: example.com
2+
repo: skydive
3+
resources:
4+
- group: skydive
5+
kind: SkydiveAgents
6+
version: v1beta1
7+
- group: skydive
8+
kind: SkydiveAnalyzer
9+
version: v1beta1
10+
- group: skydive
11+
kind: Skydive
12+
version: v1
13+
- group: skydive
14+
kind: SkydiveFlowExporter
15+
version: v1
16+
- group: skydive
17+
kind: PrometheusConnector
18+
version: v1
19+
version: "2"

README.md

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<!-- ABOUT THE PROJECT -->
2+
3+
# Skydive Operator
4+
5+
This is an operator to deploy skydive analyzer, agents and flow-exporter.
6+
7+
<!-- GETTING STARTED -->
8+
9+
## Getting Started
10+
11+
To set up this operator follow the instructions below:
12+
13+
### Prerequisites
14+
15+
* Make sure you have golang installed on your machine, The go-lang version that this operator was built on is go1.15.7
16+
darwin/amd64
17+
18+
* An openshift cluster
19+
* If you wish to run this locally by using kind please
20+
check [KindInstallationREADME.md](hack/KindInstallationREADME.md)
21+
22+
### Installation - Open-Shift
23+
24+
run the script (make sure you are logged into open shift cluster):
25+
26+
```
27+
./deploy_skydive_operator_on_openshift.sh
28+
```
29+
30+
If for some reason you have changed your KUBECONFIG default location please update the KUBECONFIG environment variable
31+
by using this command:
32+
33+
```bash
34+
export KUBECONFIG=$PATH_TO_YOUR_KUBECONFIG
35+
```
36+
37+
#### Analyzer UI
38+
39+
1a. Check that all the pods, services and routes are running and afterwards run the following command:
40+
41+
```sh
42+
oc get routes
43+
```
44+
45+
2a. post the url into your web-browser (make sure you have got an access to the cluster and are not blocked by it's
46+
firewall)
47+
48+
1b. If routes option doesn't work, run the following command
49+
50+
```sh
51+
oc port-forward service/skydive-analyzer 8082:8082 --namespace=skydive
52+
```
53+
54+
2b. Now open web-browser on localhost:8082
55+
56+
#### Flow Exporter
57+
58+
After a successful deployment of skydive operator run the script:
59+
60+
```
61+
./deploy_skydive_flow_exporter_operator.sh
62+
```
63+
64+
for deployment developing using minio run: (don't forget to kill the old flow_exporter_operator if still running)
65+
66+
```
67+
./hack/deploy_skydive_flow_exporter_dev_operator.sh
68+
```
69+
70+
#### Prometheus Connector
71+
72+
After a successful deployment of skydive operator run the script:
73+
74+
```
75+
./deploy_prometheus_connector.sh
76+
```
77+
78+
### Customize skydive deployment / CRD
79+
80+
Modify the current config/skydive_v1_skydive.yaml and pick what you wish to deploy (insert true or false in the relevant
81+
field), the options are as follows:
82+
83+
* Skydive agents
84+
* Skydive analyzer
85+
* Service route
86+
87+
You can provide the skydive operator with environments variables in order to customize your skydive deployment.
88+
Checkout [this example](config/skydive_v1_skydive_env_example.yaml) of crd to get started with providing environment
89+
variables to the skydive operator, full list of acceptable enviorment variables are
90+
listed [here](https://github.com/skydive-project/skydive/blob/master/etc/skydive.yml.default)
91+
92+
Choose your logging level (defaults to DEBUG)

api/v1/groupversion_info.go

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
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 v1 contains API Schema definitions for the skydive v1 API group
18+
// +kubebuilder:object:generate=true
19+
// +groupName=skydive.example.com
20+
package v1
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "skydive.example.com", Version: "v1"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)

api/v1/prometheusconnector_types.go

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
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 v1
18+
19+
import (
20+
v1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
25+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
26+
27+
// PrometheusConnectorSpec defines the desired state of PrometheusConnector
28+
type PrometheusConnectorSpec struct {
29+
Namespace string `json:"namespace,omitempty"`
30+
31+
Deployment PrometheusConnectorDeploymentSpec `json:"deployment"`
32+
}
33+
34+
type PrometheusConnectorDeploymentSpec struct {
35+
// List of environment variables to set in the container.
36+
// Cannot be updated.
37+
// +optional
38+
// +patchMergeKey=name
39+
// +patchStrategy=merge
40+
Env []v1.EnvVar `json:"env,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,7,rep,name=env"`
41+
}
42+
43+
// PrometheusConnectorStatus defines the observed state of PrometheusConnector
44+
type PrometheusConnectorStatus struct {
45+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
46+
// Important: Run "make" to regenerate code after modifying this file
47+
}
48+
49+
// +kubebuilder:object:root=true
50+
51+
// PrometheusConnector is the Schema for the prometheusconnectors API
52+
type PrometheusConnector struct {
53+
metav1.TypeMeta `json:",inline"`
54+
metav1.ObjectMeta `json:"metadata,omitempty"`
55+
56+
Spec PrometheusConnectorSpec `json:"spec,omitempty"`
57+
Status PrometheusConnectorStatus `json:"status,omitempty"`
58+
}
59+
60+
// +kubebuilder:object:root=true
61+
62+
// PrometheusConnectorList contains a list of PrometheusConnector
63+
type PrometheusConnectorList struct {
64+
metav1.TypeMeta `json:",inline"`
65+
metav1.ListMeta `json:"metadata,omitempty"`
66+
Items []PrometheusConnector `json:"items"`
67+
}
68+
69+
func init() {
70+
SchemeBuilder.Register(&PrometheusConnector{}, &PrometheusConnectorList{})
71+
}

0 commit comments

Comments
 (0)