Skip to content

Commit 0c7ab51

Browse files
committed
redo project
1 parent 547593a commit 0c7ab51

33 files changed

+576
-869
lines changed

LICENSE

-661
This file was deleted.

Makefile

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# Current Operator version
2+
VERSION ?= 0.0.1
3+
# Default bundle image tag
4+
BUNDLE_IMG ?= controller-bundle:$(VERSION)
5+
# Options for 'bundle-build'
6+
ifneq ($(origin CHANNELS), undefined)
7+
BUNDLE_CHANNELS := --channels=$(CHANNELS)
8+
endif
9+
ifneq ($(origin DEFAULT_CHANNEL), undefined)
10+
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
11+
endif
12+
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
113

214
# Image URL to use all building/pushing image targets
315
IMG ?= controller:latest
@@ -14,8 +26,11 @@ endif
1426
all: manager
1527

1628
# Run tests
29+
ENVTEST_ASSETS_DIR = $(shell pwd)/testbin
1730
test: generate fmt vet manifests
18-
go test ./... -coverprofile cover.out
31+
mkdir -p $(ENVTEST_ASSETS_DIR)
32+
test -f $(ENVTEST_ASSETS_DIR)/setup-envtest.sh || curl -sSLo $(ENVTEST_ASSETS_DIR)/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.6.3/hack/setup-envtest.sh
33+
source $(ENVTEST_ASSETS_DIR)/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
1934

2035
# Build manager binary
2136
manager: generate fmt vet
@@ -93,3 +108,16 @@ KUSTOMIZE=$(GOBIN)/kustomize
93108
else
94109
KUSTOMIZE=$(shell which kustomize)
95110
endif
111+
112+
# Generate bundle manifests and metadata, then validate generated files.
113+
.PHONY: bundle
114+
bundle: manifests
115+
operator-sdk generate kustomize manifests -q
116+
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
117+
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
118+
operator-sdk bundle validate ./bundle
119+
120+
# Build the bundle image.
121+
.PHONY: bundle-build
122+
bundle-build:
123+
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .

PROJECT

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
domain: k6.io
1+
domain: io
2+
layout: go.kubebuilder.io/v2
3+
projectName: operator
24
repo: github.com/k6io/operator
35
resources:
4-
- group: test
6+
- group: k6
57
kind: K6
68
version: v1alpha1
7-
version: "2"
9+
- group: k6
10+
kind: K6Test
11+
version: v1alpha1
12+
version: 3-alpha
13+
plugins:
14+
go.sdk.operatorframework.io/v2-alpha: {}

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
# operator
1+
![data flow](assets/data-flow.png)
2+
3+
# k6 Operator
4+
5+
> ### ⚠️ Experimental
6+
>
7+
> This project is **experimental** and changes a lot
8+
> between commits.
9+

api/v1alpha1/groupversion_info.go

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
1-
// Package v1alpha1 contains API Schema definitions for the test v1alpha1 API group
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 v1alpha1 contains API Schema definitions for the k6 v1alpha1 API group
218
// +kubebuilder:object:generate=true
3-
// +groupName=test.k6.io
19+
// +groupName=k6.io
420
package v1alpha1
521

622
import (
@@ -10,7 +26,7 @@ import (
1026

1127
var (
1228
// GroupVersion is group version used to register these objects
13-
GroupVersion = schema.GroupVersion{Group: "test.k6.io", Version: "v1alpha1"}
29+
GroupVersion = schema.GroupVersion{Group: "k6.io", Version: "v1alpha1"}
1430

1531
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
1632
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

api/v1alpha1/k6_types.go

+23-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/*
2+
Licensed under the Apache License, Version 2.0 (the "License");
3+
you may not use this file except in compliance with the License.
4+
You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
*/
14+
115
package v1alpha1
216

317
import (
@@ -6,29 +20,27 @@ import (
620

721
// K6Spec defines the desired state of K6
822
type K6Spec struct {
9-
Script string `json:"script"`
10-
Options string `json:"options,omitempty"`
11-
Nodes int32 `json:"Parallelism"`
23+
Script string `json:"script"`
24+
Parallelism int32 `json:"parallelism"`
25+
Separate bool `json:"separate,omitempty"`
1226
}
1327

1428
// K6Status defines the observed state of K6
15-
type K6Status struct {
16-
}
29+
type K6Status struct{}
1730

31+
// K6 is the Schema for the k6s API
1832
// +kubebuilder:object:root=true
1933
// +kubebuilder:subresource:status
20-
21-
// K6 is the Schema for the k6s API
2234
type K6 struct {
2335
metav1.TypeMeta `json:",inline"`
2436
metav1.ObjectMeta `json:"metadata,omitempty"`
25-
Spec K6Spec `json:"spec,omitempty"`
26-
Status K6Status `json:"status,omitempty"`
27-
}
2837

29-
// +kubebuilder:object:root=true
38+
Spec K6Spec `json:"spec,omitempty"`
39+
Status K6Status `json:"status,omitempty"`
40+
}
3041

3142
// K6List contains a list of K6
43+
// +kubebuilder:object:root=true
3244
type K6List struct {
3345
metav1.TypeMeta `json:",inline"`
3446
metav1.ListMeta `json:"metadata,omitempty"`

api/v1alpha1/zz_generated.deepcopy.go

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

assets/data-flow.png

408 KB
Loading

config/crd/bases/test.k6.io_k6s.yaml config/crd/bases/k6.io_k6s.yaml

+6-13
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ metadata:
66
annotations:
77
controller-gen.kubebuilder.io/version: v0.3.0
88
creationTimestamp: null
9-
name: k6s.test.k6.io
9+
name: k6s.k6.io
1010
spec:
11-
group: test.k6.io
11+
group: k6.io
1212
names:
1313
kind: K6
1414
listKind: K6List
@@ -36,22 +36,15 @@ spec:
3636
spec:
3737
description: K6Spec defines the desired state of K6
3838
properties:
39-
backoff:
39+
parallelism:
4040
format: int32
4141
type: integer
42-
cleanup:
43-
type: boolean
44-
nodes:
45-
format: int32
46-
type: integer
47-
options:
48-
type: string
4942
script:
5043
type: string
44+
separate:
45+
type: boolean
5146
required:
52-
- backoff
53-
- cleanup
54-
- nodes
47+
- parallelism
5548
- script
5649
type: object
5750
status:

config/crd/kustomization.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22
# since it depends on service name and namespace that are out of this kustomize package.
33
# It should be run by config/default
44
resources:
5-
- bases/test.k6.io_k6s.yaml
5+
- bases/k6.io_k6s.yaml
66
# +kubebuilder:scaffold:crdkustomizeresource
77

88
patchesStrategicMerge:
99
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
1010
# patches here are for enabling the conversion webhook for each CRD
1111
#- patches/webhook_in_k6s.yaml
12+
#- patches/webhook_in_k6tests.yaml
1213
# +kubebuilder:scaffold:crdkustomizewebhookpatch
1314

1415
# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
1516
# patches here are for enabling the CA injection for each CRD
1617
#- patches/cainjection_in_k6s.yaml
18+
#- patches/cainjection_in_k6tests.yaml
1719
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
1820

1921
# the following config is for teaching kustomize how to do kustomization for CRDs.

config/crd/patches/cainjection_in_k6s.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ kind: CustomResourceDefinition
55
metadata:
66
annotations:
77
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
8-
name: k6s.test.k6.io
8+
name: k6s.k6.io

config/crd/patches/webhook_in_k6s.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
apiVersion: apiextensions.k8s.io/v1beta1
44
kind: CustomResourceDefinition
55
metadata:
6-
name: k6s.test.k6.io
6+
name: k6s.k6.io
77
spec:
88
conversion:
99
strategy: Webhook

config/manager/kustomization.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
resources:
22
- manager.yaml
3+
images:
4+
- name: controller
5+
newName: ghcr.io/k6io/operator
6+
newTag: latest
7+
apiVersion: kustomize.config.k8s.io/v1beta1
8+
kind: Kustomization

config/manager/manager.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ apiVersion: v1
22
kind: Namespace
33
metadata:
44
labels:
5+
app.kubernetes.io/name: k6-operator
56
control-plane: controller-manager
67
name: system
78
---

config/rbac/k6_editor_role.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
name: k6-editor-role
66
rules:
77
- apiGroups:
8-
- test.k6.io
8+
- k6.io
99
resources:
1010
- k6s
1111
verbs:
@@ -17,7 +17,7 @@ rules:
1717
- update
1818
- watch
1919
- apiGroups:
20-
- test.k6.io
20+
- k6.io
2121
resources:
2222
- k6s/status
2323
verbs:

config/rbac/k6_viewer_role.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ metadata:
55
name: k6-viewer-role
66
rules:
77
- apiGroups:
8-
- test.k6.io
8+
- k6.io
99
resources:
1010
- k6s
1111
verbs:
1212
- get
1313
- list
1414
- watch
1515
- apiGroups:
16-
- test.k6.io
16+
- k6.io
1717
resources:
1818
- k6s/status
1919
verbs:

config/rbac/role.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ metadata:
77
name: manager-role
88
rules:
99
- apiGroups:
10-
- test.k6.io
10+
- k6.io
1111
resources:
1212
- k6s
1313
verbs:
@@ -19,7 +19,7 @@ rules:
1919
- update
2020
- watch
2121
- apiGroups:
22-
- test.k6.io
22+
- k6.io
2323
resources:
2424
- k6s/status
2525
verbs:
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
namespace: k6
5+
name: k6-test
6+
data:
7+
test.js: |
8+
import http from 'k6/http';
9+
import { Rate } from 'k6/metrics';
10+
import { check, sleep } from 'k6';
11+
12+
import {
13+
getExecutionSegments,
14+
logSegment,
15+
} from 'https://jslib.k6.io/k8s-distributed-execution/0.0.1/index.js';
16+
17+
const failRate = new Rate('failed_requests');
18+
19+
export function setup() {
20+
logSegment();
21+
}
22+
23+
export let options = Object.assign({
24+
stages: [
25+
{ target: 200, duration: '30s' },
26+
{ target: 0, duration: '30s' },
27+
],
28+
threshold: {
29+
failed_requests: ['rate<=0'],
30+
http_req_duration: ['p(95)<500'],
31+
},
32+
}, getExecutionSegments());
33+
34+
export default function () {
35+
const result = http.get('https://test-api.k6.io/public/crocodiles/');
36+
check(result, {
37+
'http response status code is 200': result.status === 200,
38+
});
39+
failRate.add(result.status !== 200);
40+
sleep(1);
41+
}
42+

config/samples/k6_v1alpha1_k6.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: k6.io/v1alpha1
2+
kind: K6
3+
metadata:
4+
namespace: k6
5+
name: k6-sample
6+
spec:
7+
parallelism: 4
8+
script: k6-test
9+
separate: false

config/samples/kustomization.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Append samples you want in your CSV to this file as resources ##
2+
resources:
3+
- k6_v1alpha1_configmap.yaml
4+
- k6_v1alpha1_k6.yaml
5+
# +kubebuilder:scaffold:manifestskustomizesamples

0 commit comments

Comments
 (0)