Skip to content

Commit

Permalink
redo project
Browse files Browse the repository at this point in the history
  • Loading branch information
simskij committed Oct 20, 2020
1 parent 547593a commit 0c7ab51
Show file tree
Hide file tree
Showing 33 changed files with 576 additions and 869 deletions.
661 changes: 0 additions & 661 deletions LICENSE

This file was deleted.

30 changes: 29 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Current Operator version
VERSION ?= 0.0.1
# Default bundle image tag
BUNDLE_IMG ?= controller-bundle:$(VERSION)
# Options for 'bundle-build'
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS := --channels=$(CHANNELS)
endif
ifneq ($(origin DEFAULT_CHANNEL), undefined)
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

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

# Run tests
ENVTEST_ASSETS_DIR = $(shell pwd)/testbin
test: generate fmt vet manifests
go test ./... -coverprofile cover.out
mkdir -p $(ENVTEST_ASSETS_DIR)
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
source $(ENVTEST_ASSETS_DIR)/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out

# Build manager binary
manager: generate fmt vet
Expand Down Expand Up @@ -93,3 +108,16 @@ KUSTOMIZE=$(GOBIN)/kustomize
else
KUSTOMIZE=$(shell which kustomize)
endif

# Generate bundle manifests and metadata, then validate generated files.
.PHONY: bundle
bundle: manifests
operator-sdk generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
operator-sdk bundle validate ./bundle

# Build the bundle image.
.PHONY: bundle-build
bundle-build:
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
13 changes: 10 additions & 3 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
domain: k6.io
domain: io
layout: go.kubebuilder.io/v2
projectName: operator
repo: github.com/k6io/operator
resources:
- group: test
- group: k6
kind: K6
version: v1alpha1
version: "2"
- group: k6
kind: K6Test
version: v1alpha1
version: 3-alpha
plugins:
go.sdk.operatorframework.io/v2-alpha: {}
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# operator
![data flow](assets/data-flow.png)

# k6 Operator

> ### ⚠️ Experimental
>
> This project is **experimental** and changes a lot
> between commits.
22 changes: 19 additions & 3 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
// Package v1alpha1 contains API Schema definitions for the test v1alpha1 API group
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the k6 v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=test.k6.io
// +groupName=k6.io
package v1alpha1

import (
Expand All @@ -10,7 +26,7 @@ import (

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "test.k6.io", Version: "v1alpha1"}
GroupVersion = schema.GroupVersion{Group: "k6.io", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
Expand Down
34 changes: 23 additions & 11 deletions api/v1alpha1/k6_types.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
Expand All @@ -6,29 +20,27 @@ import (

// K6Spec defines the desired state of K6
type K6Spec struct {
Script string `json:"script"`
Options string `json:"options,omitempty"`
Nodes int32 `json:"Parallelism"`
Script string `json:"script"`
Parallelism int32 `json:"parallelism"`
Separate bool `json:"separate,omitempty"`
}

// K6Status defines the observed state of K6
type K6Status struct {
}
type K6Status struct{}

// K6 is the Schema for the k6s API
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// K6 is the Schema for the k6s API
type K6 struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec K6Spec `json:"spec,omitempty"`
Status K6Status `json:"status,omitempty"`
}

// +kubebuilder:object:root=true
Spec K6Spec `json:"spec,omitempty"`
Status K6Status `json:"status,omitempty"`
}

// K6List contains a list of K6
// +kubebuilder:object:root=true
type K6List struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
16 changes: 16 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added assets/data-flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
creationTimestamp: null
name: k6s.test.k6.io
name: k6s.k6.io
spec:
group: test.k6.io
group: k6.io
names:
kind: K6
listKind: K6List
Expand Down Expand Up @@ -36,22 +36,15 @@ spec:
spec:
description: K6Spec defines the desired state of K6
properties:
backoff:
parallelism:
format: int32
type: integer
cleanup:
type: boolean
nodes:
format: int32
type: integer
options:
type: string
script:
type: string
separate:
type: boolean
required:
- backoff
- cleanup
- nodes
- parallelism
- script
type: object
status:
Expand Down
4 changes: 3 additions & 1 deletion config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
# since it depends on service name and namespace that are out of this kustomize package.
# It should be run by config/default
resources:
- bases/test.k6.io_k6s.yaml
- bases/k6.io_k6s.yaml
# +kubebuilder:scaffold:crdkustomizeresource

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

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

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
2 changes: 1 addition & 1 deletion config/crd/patches/cainjection_in_k6s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: k6s.test.k6.io
name: k6s.k6.io
2 changes: 1 addition & 1 deletion config/crd/patches/webhook_in_k6s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: k6s.test.k6.io
name: k6s.k6.io
spec:
conversion:
strategy: Webhook
Expand Down
6 changes: 6 additions & 0 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
resources:
- manager.yaml
images:
- name: controller
newName: ghcr.io/k6io/operator
newTag: latest
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
1 change: 1 addition & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: v1
kind: Namespace
metadata:
labels:
app.kubernetes.io/name: k6-operator
control-plane: controller-manager
name: system
---
Expand Down
4 changes: 2 additions & 2 deletions config/rbac/k6_editor_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
name: k6-editor-role
rules:
- apiGroups:
- test.k6.io
- k6.io
resources:
- k6s
verbs:
Expand All @@ -17,7 +17,7 @@ rules:
- update
- watch
- apiGroups:
- test.k6.io
- k6.io
resources:
- k6s/status
verbs:
Expand Down
4 changes: 2 additions & 2 deletions config/rbac/k6_viewer_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ metadata:
name: k6-viewer-role
rules:
- apiGroups:
- test.k6.io
- k6.io
resources:
- k6s
verbs:
- get
- list
- watch
- apiGroups:
- test.k6.io
- k6.io
resources:
- k6s/status
verbs:
Expand Down
4 changes: 2 additions & 2 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
name: manager-role
rules:
- apiGroups:
- test.k6.io
- k6.io
resources:
- k6s
verbs:
Expand All @@ -19,7 +19,7 @@ rules:
- update
- watch
- apiGroups:
- test.k6.io
- k6.io
resources:
- k6s/status
verbs:
Expand Down
42 changes: 42 additions & 0 deletions config/samples/k6_v1alpha1_configmap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: v1
kind: ConfigMap
metadata:
namespace: k6
name: k6-test
data:
test.js: |
import http from 'k6/http';
import { Rate } from 'k6/metrics';
import { check, sleep } from 'k6';
import {
getExecutionSegments,
logSegment,
} from 'https://jslib.k6.io/k8s-distributed-execution/0.0.1/index.js';
const failRate = new Rate('failed_requests');
export function setup() {
logSegment();
}
export let options = Object.assign({
stages: [
{ target: 200, duration: '30s' },
{ target: 0, duration: '30s' },
],
threshold: {
failed_requests: ['rate<=0'],
http_req_duration: ['p(95)<500'],
},
}, getExecutionSegments());
export default function () {
const result = http.get('https://test-api.k6.io/public/crocodiles/');
check(result, {
'http response status code is 200': result.status === 200,
});
failRate.add(result.status !== 200);
sleep(1);
}
9 changes: 9 additions & 0 deletions config/samples/k6_v1alpha1_k6.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: k6.io/v1alpha1
kind: K6
metadata:
namespace: k6
name: k6-sample
spec:
parallelism: 4
script: k6-test
separate: false
5 changes: 5 additions & 0 deletions config/samples/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Append samples you want in your CSV to this file as resources ##
resources:
- k6_v1alpha1_configmap.yaml
- k6_v1alpha1_k6.yaml
# +kubebuilder:scaffold:manifestskustomizesamples
Loading

0 comments on commit 0c7ab51

Please sign in to comment.