Skip to content

Commit 9eb83f9

Browse files
authored
Merge pull request litmuschaos#1 from ksatchit/master
(feat)(chaos_operator) initial commit for chaos operator
2 parents 8c98040 + f87c4c6 commit 9eb83f9

File tree

9,170 files changed

+5285751
-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.

9,170 files changed

+5285751
-0
lines changed

Gopkg.lock

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

Gopkg.toml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Force dep to vendor the code generators, which aren't imported just used at dev time.
2+
required = [
3+
"k8s.io/code-generator/cmd/deepcopy-gen",
4+
"k8s.io/code-generator/cmd/conversion-gen",
5+
"k8s.io/code-generator/cmd/client-gen",
6+
"k8s.io/code-generator/cmd/lister-gen",
7+
"k8s.io/code-generator/cmd/informer-gen",
8+
"k8s.io/kube-openapi/cmd/openapi-gen",
9+
"k8s.io/gengo/args",
10+
"sigs.k8s.io/controller-tools/pkg/crd/generator",
11+
]
12+
13+
[[override]]
14+
name = "k8s.io/code-generator"
15+
# revision for tag "kubernetes-1.13.1"
16+
revision = "c2090bec4d9b1fb25de3812f868accc2bc9ecbae"
17+
18+
[[override]]
19+
name = "k8s.io/kube-openapi"
20+
revision = "0cf8f7e6ed1d2e3d47d02e3b6e559369af24d803"
21+
22+
[[override]]
23+
name = "github.com/go-openapi/spec"
24+
branch = "master"
25+
26+
[[override]]
27+
name = "sigs.k8s.io/controller-tools"
28+
version = "=v0.1.8"
29+
30+
[[override]]
31+
name = "k8s.io/api"
32+
# revision for tag "kubernetes-1.13.1"
33+
revision = "05914d821849570fba9eacfb29466f2d8d3cd229"
34+
35+
[[override]]
36+
name = "k8s.io/apiextensions-apiserver"
37+
# revision for tag "kubernetes-1.13.1"
38+
revision = "0fe22c71c47604641d9aa352c785b7912c200562"
39+
40+
[[override]]
41+
name = "k8s.io/apimachinery"
42+
# revision for tag "kubernetes-1.13.1"
43+
revision = "2b1284ed4c93a43499e781493253e2ac5959c4fd"
44+
45+
[[override]]
46+
name = "k8s.io/client-go"
47+
# revision for tag "kubernetes-1.13.1"
48+
revision = "8d9ed539ba3134352c586810e749e58df4e94e4f"
49+
50+
[[override]]
51+
name = "github.com/coreos/prometheus-operator"
52+
version = "=v0.29.0"
53+
54+
[[override]]
55+
name = "sigs.k8s.io/controller-runtime"
56+
version = "=v0.1.10"
57+
58+
[[constraint]]
59+
name = "github.com/operator-framework/operator-sdk"
60+
# The version rule is used for a specific release and the master branch for in between releases.
61+
branch = "master" #osdk_branch_annotation
62+
# version = "=v0.7.0" #osdk_version_annotation
63+
64+
[prune]
65+
go-tests = true
66+
non-go = true
67+
68+
[[prune.project]]
69+
name = "k8s.io/code-generator"
70+
non-go = false
71+
72+
[[prune.project]]
73+
name = "k8s.io/gengo"
74+
non-go = false

build/Dockerfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM registry.access.redhat.com/ubi7-dev-preview/ubi-minimal:7.6
2+
3+
ENV OPERATOR=/usr/local/bin/chaos-operator \
4+
USER_UID=1001 \
5+
USER_NAME=chaos-operator
6+
7+
# install operator binary
8+
COPY build/_output/bin/chaos-operator ${OPERATOR}
9+
10+
COPY build/bin /usr/local/bin
11+
RUN /usr/local/bin/user_setup
12+
13+
ENTRYPOINT ["/usr/local/bin/entrypoint"]
14+
15+
USER ${USER_UID}

build/_output/bin/chaos-operator

46 MB
Binary file not shown.

build/_output/bin/client-gen

9.05 MB
Binary file not shown.

build/_output/bin/deepcopy-gen

8.74 MB
Binary file not shown.

build/_output/bin/informer-gen

8.85 MB
Binary file not shown.

build/_output/bin/lister-gen

8.71 MB
Binary file not shown.

build/_output/bin/openapi-gen

14.7 MB
Binary file not shown.

build/bin/entrypoint

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh -e
2+
3+
# This is documented here:
4+
# https://docs.openshift.com/container-platform/3.11/creating_images/guidelines.html#openshift-specific-guidelines
5+
6+
if ! whoami &>/dev/null; then
7+
if [ -w /etc/passwd ]; then
8+
echo "${USER_NAME:-chaos-operator}:x:$(id -u):$(id -g):${USER_NAME:-chaos-operator} user:${HOME}:/sbin/nologin" >> /etc/passwd
9+
fi
10+
fi
11+
12+
exec ${OPERATOR} $@

build/bin/user_setup

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
set -x
3+
4+
# ensure $HOME exists and is accessible by group 0 (we don't know what the runtime UID will be)
5+
mkdir -p ${HOME}
6+
chown ${USER_UID}:0 ${HOME}
7+
chmod ug+rwx ${HOME}
8+
9+
# runtime user will need to be able to self-insert in /etc/passwd
10+
chmod g+rw /etc/passwd
11+
12+
# no need for this script to remain in the image after running
13+
rm $0

cmd/manager/main.go

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"flag"
6+
"fmt"
7+
"os"
8+
"runtime"
9+
10+
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
11+
_ "k8s.io/client-go/plugin/pkg/client/auth"
12+
13+
"github.com/litmuschaos/chaos-operator/pkg/apis"
14+
"github.com/litmuschaos/chaos-operator/pkg/controller"
15+
16+
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
17+
"github.com/operator-framework/operator-sdk/pkg/leader"
18+
"github.com/operator-framework/operator-sdk/pkg/log/zap"
19+
"github.com/operator-framework/operator-sdk/pkg/metrics"
20+
sdkVersion "github.com/operator-framework/operator-sdk/version"
21+
"github.com/spf13/pflag"
22+
"sigs.k8s.io/controller-runtime/pkg/client/config"
23+
"sigs.k8s.io/controller-runtime/pkg/manager"
24+
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
25+
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
26+
)
27+
28+
// Change below variables to serve metrics on different host or port.
29+
var (
30+
metricsHost = "0.0.0.0"
31+
metricsPort int32 = 8383
32+
)
33+
var log = logf.Log.WithName("cmd")
34+
35+
func printVersion() {
36+
log.Info(fmt.Sprintf("Go Version: %s", runtime.Version()))
37+
log.Info(fmt.Sprintf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH))
38+
log.Info(fmt.Sprintf("Version of operator-sdk: %v", sdkVersion.Version))
39+
}
40+
41+
func main() {
42+
// Add the zap logger flag set to the CLI. The flag set must
43+
// be added before calling pflag.Parse().
44+
pflag.CommandLine.AddFlagSet(zap.FlagSet())
45+
46+
// Add flags registered by imported packages (e.g. glog and
47+
// controller-runtime)
48+
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
49+
50+
pflag.Parse()
51+
52+
// Use a zap logr.Logger implementation. If none of the zap
53+
// flags are configured (or if the zap flag set is not being
54+
// used), this defaults to a production zap logger.
55+
//
56+
// The logger instantiated here can be changed to any logger
57+
// implementing the logr.Logger interface. This logger will
58+
// be propagated through the whole operator, generating
59+
// uniform and structured logs.
60+
logf.SetLogger(zap.Logger())
61+
62+
printVersion()
63+
64+
namespace, err := k8sutil.GetWatchNamespace()
65+
if err != nil {
66+
log.Error(err, "Failed to get watch namespace")
67+
os.Exit(1)
68+
}
69+
70+
// Get a config to talk to the apiserver
71+
cfg, err := config.GetConfig()
72+
if err != nil {
73+
log.Error(err, "")
74+
os.Exit(1)
75+
}
76+
77+
ctx := context.TODO()
78+
79+
// Become the leader before proceeding
80+
err = leader.Become(ctx, "chaos-operator-lock")
81+
if err != nil {
82+
log.Error(err, "")
83+
os.Exit(1)
84+
}
85+
86+
// Create a new Cmd to provide shared dependencies and start components
87+
mgr, err := manager.New(cfg, manager.Options{
88+
Namespace: namespace,
89+
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
90+
})
91+
if err != nil {
92+
log.Error(err, "")
93+
os.Exit(1)
94+
}
95+
96+
log.Info("Registering Components.")
97+
98+
// Setup Scheme for all resources
99+
if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
100+
log.Error(err, "")
101+
os.Exit(1)
102+
}
103+
104+
// Setup all Controllers
105+
if err := controller.AddToManager(mgr); err != nil {
106+
log.Error(err, "")
107+
os.Exit(1)
108+
}
109+
110+
// Create Service object to expose the metrics port.
111+
_, err = metrics.ExposeMetricsPort(ctx, metricsPort)
112+
if err != nil {
113+
log.Info(err.Error())
114+
}
115+
116+
log.Info("Starting the Cmd.")
117+
118+
// Start the Cmd
119+
if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
120+
log.Error(err, "Manager exited non-zero")
121+
os.Exit(1)
122+
}
123+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: litmuschaos.io/v1alpha1
2+
kind: ChaosEngine
3+
metadata:
4+
name: example-chaosengine
5+
spec:
6+
# Add fields here
7+
size: 3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: chaosengines.litmuschaos.io
5+
spec:
6+
group: litmuschaos.io
7+
names:
8+
kind: ChaosEngine
9+
listKind: ChaosEngineList
10+
plural: chaosengines
11+
singular: chaosengine
12+
scope: Namespaced
13+
subresources:
14+
status: {}
15+
validation:
16+
openAPIV3Schema:
17+
properties:
18+
apiVersion:
19+
description: 'APIVersion defines the versioned schema of this representation
20+
of an object. Servers should convert recognized schemas to the latest
21+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
22+
type: string
23+
kind:
24+
description: 'Kind is a string value representing the REST resource this
25+
object represents. Servers may infer this from the endpoint the client
26+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
27+
type: string
28+
metadata:
29+
type: object
30+
spec:
31+
type: object
32+
status:
33+
type: object
34+
version: v1alpha1
35+
versions:
36+
- name: v1alpha1
37+
served: true
38+
storage: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: litmuschaos.io/v1alpha1
2+
kind: ChaosExperiment
3+
metadata:
4+
name: example-chaosexperiment
5+
spec:
6+
# Add fields here
7+
size: 3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: chaosexperiments.litmuschaos.io
5+
spec:
6+
group: litmuschaos.io
7+
names:
8+
kind: ChaosExperiment
9+
listKind: ChaosExperimentList
10+
plural: chaosexperiments
11+
singular: chaosexperiment
12+
scope: Namespaced
13+
subresources:
14+
status: {}
15+
validation:
16+
openAPIV3Schema:
17+
properties:
18+
apiVersion:
19+
description: 'APIVersion defines the versioned schema of this representation
20+
of an object. Servers should convert recognized schemas to the latest
21+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
22+
type: string
23+
kind:
24+
description: 'Kind is a string value representing the REST resource this
25+
object represents. Servers may infer this from the endpoint the client
26+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
27+
type: string
28+
metadata:
29+
type: object
30+
spec:
31+
type: object
32+
status:
33+
type: object
34+
version: v1alpha1
35+
versions:
36+
- name: v1alpha1
37+
served: true
38+
storage: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: litmuschaos.io/v1alpha1
2+
kind: ChaosTemplate
3+
metadata:
4+
name: example-chaostemplate
5+
spec:
6+
# Add fields here
7+
size: 3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: chaostemplates.litmuschaos.io
5+
spec:
6+
group: litmuschaos.io
7+
names:
8+
kind: ChaosTemplate
9+
listKind: ChaosTemplateList
10+
plural: chaostemplates
11+
singular: chaostemplate
12+
scope: Namespaced
13+
subresources:
14+
status: {}
15+
validation:
16+
openAPIV3Schema:
17+
properties:
18+
apiVersion:
19+
description: 'APIVersion defines the versioned schema of this representation
20+
of an object. Servers should convert recognized schemas to the latest
21+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
22+
type: string
23+
kind:
24+
description: 'Kind is a string value representing the REST resource this
25+
object represents. Servers may infer this from the endpoint the client
26+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
27+
type: string
28+
metadata:
29+
type: object
30+
spec:
31+
type: object
32+
status:
33+
type: object
34+
version: v1alpha1
35+
versions:
36+
- name: v1alpha1
37+
served: true
38+
storage: true

0 commit comments

Comments
 (0)