From 0d347c2fa204f8cfe183988bef32777b757e3bfd Mon Sep 17 00:00:00 2001 From: vankichi Date: Thu, 25 Aug 2022 13:25:29 +0900 Subject: [PATCH] :sparkles: add crds for continuous benchmark operator Signed-off-by: vankichi --- internal/k8s/benchmark/job.go | 62 +++ internal/k8s/benchmark/operator.go | 62 +++ .../k8s/crd/benchmark/valdbenchmarkjob.yaml | 321 ++++++++++++++++ .../crd/benchmark/valdbenchmarkoperator.yaml | 361 ++++++++++++++++++ .../rbac/benchmark/operator/clusterrole.yaml | 51 +++ .../operator/clusterrolebinding.yaml | 27 ++ .../benchmark/operator/serviceaccount.yaml | 20 + internal/k8s/rbac/benchmark/operator/svc.yaml | 0 8 files changed, 904 insertions(+) create mode 100644 internal/k8s/benchmark/job.go create mode 100644 internal/k8s/benchmark/operator.go create mode 100644 internal/k8s/crd/benchmark/valdbenchmarkjob.yaml create mode 100644 internal/k8s/crd/benchmark/valdbenchmarkoperator.yaml create mode 100644 internal/k8s/rbac/benchmark/operator/clusterrole.yaml create mode 100644 internal/k8s/rbac/benchmark/operator/clusterrolebinding.yaml create mode 100644 internal/k8s/rbac/benchmark/operator/serviceaccount.yaml create mode 100644 internal/k8s/rbac/benchmark/operator/svc.yaml diff --git a/internal/k8s/benchmark/job.go b/internal/k8s/benchmark/job.go new file mode 100644 index 00000000000..0ef9f08f458 --- /dev/null +++ b/internal/k8s/benchmark/job.go @@ -0,0 +1,62 @@ +// +// Copyright (C) 2019-2022 vdaas.org vald team +// +// 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 +// +// https://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 benchmark + +import ( + "context" + + "k8s.io/apimachinery/pkg/runtime" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" + + valdvdaasorgv1 "vald.vdaas.org/api/v1" +) + +// ValdBenchmarkJobReconciler reconciles a ValdBenchmarkJob object +type ValdBenchmarkJobReconciler struct { + client.Client + Scheme *runtime.Scheme +} + +//+kubebuilder:rbac:groups=vald.vdaas.org.vald.vdaas.org,resources=valdbenchmarkjobs,verbs=get;list;watch;create;update;patch;delete +//+kubebuilder:rbac:groups=vald.vdaas.org.vald.vdaas.org,resources=valdbenchmarkjobs/status,verbs=get;update;patch +//+kubebuilder:rbac:groups=vald.vdaas.org.vald.vdaas.org,resources=valdbenchmarkjobs/finalizers,verbs=update + +// Reconcile is part of the main kubernetes reconciliation loop which aims to +// move the current state of the cluster closer to the desired state. +// TODO(user): Modify the Reconcile function to compare the state specified by +// the ValdBenchmarkJob object against the actual cluster state, and then +// perform operations to make the cluster state reflect the state specified by +// the user. +// +// For more details, check Reconcile and its Result here: +// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.12.1/pkg/reconcile +func (r *ValdBenchmarkJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + _ = log.FromContext(ctx) + + // TODO(user): your logic here + + return ctrl.Result{}, nil +} + +// SetupWithManager sets up the controller with the Manager. +func (r *ValdBenchmarkJobReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&valdvdaasorgv1.ValdBenchmarkJobRelease{}). + Complete(r) +} diff --git a/internal/k8s/benchmark/operator.go b/internal/k8s/benchmark/operator.go new file mode 100644 index 00000000000..0fbe27eaac8 --- /dev/null +++ b/internal/k8s/benchmark/operator.go @@ -0,0 +1,62 @@ +// +// Copyright (C) 2019-2022 vdaas.org vald team +// +// 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 +// +// https://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 benchmark + +import ( + "context" + + "k8s.io/apimachinery/pkg/runtime" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" + + valdvdaasorgv1 "valdbenchmarkoperator/api/v1" +) + +// ValdBenchmarkOperatorReconciler reconciles a ValdBenchmarkOperator object +type ValdBenchmarkOperatorReconciler struct { + client.Client + Scheme *runtime.Scheme +} + +//+kubebuilder:rbac:groups=vald.vdaas.org.vald.vdaas.org,resources=valdbenchmarkoperators,verbs=get;list;watch;create;update;patch;delete +//+kubebuilder:rbac:groups=vald.vdaas.org.vald.vdaas.org,resources=valdbenchmarkoperators/status,verbs=get;update;patch +//+kubebuilder:rbac:groups=vald.vdaas.org.vald.vdaas.org,resources=valdbenchmarkoperators/finalizers,verbs=update + +// Reconcile is part of the main kubernetes reconciliation loop which aims to +// move the current state of the cluster closer to the desired state. +// TODO(user): Modify the Reconcile function to compare the state specified by +// the ValdBenchmarkOperator object against the actual cluster state, and then +// perform operations to make the cluster state reflect the state specified by +// the user. +// +// For more details, check Reconcile and its Result here: +// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.12.1/pkg/reconcile +func (r *ValdBenchmarkOperatorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + _ = log.FromContext(ctx) + + // TODO(user): your logic here + + return ctrl.Result{}, nil +} + +// SetupWithManager sets up the controller with the Manager. +func (r *ValdBenchmarkOperatorReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&valdvdaasorgv1.ValdBenchmarkOperator{}). + Complete(r) +} diff --git a/internal/k8s/crd/benchmark/valdbenchmarkjob.yaml b/internal/k8s/crd/benchmark/valdbenchmarkjob.yaml new file mode 100644 index 00000000000..fbd36a0ee14 --- /dev/null +++ b/internal/k8s/crd/benchmark/valdbenchmarkjob.yaml @@ -0,0 +1,321 @@ +# +# Copyright (C) 2019-2022 vdaas.org vald team +# +# 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 +# +# https://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. +# +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: valdbenchmarkjobs.vald.vdaas.org +spec: + group: vald.vdaas.org + names: + kind: ValdBenchmarkJob + listKind: ValdBenchmarkJobList + plural: valdbenchmarkjobs + singular: valdbenchmarkjob + shortNames: + - vbj + - vbjs + scope: Namespaced + versions: + - name: v1 + served: true + storage: true + subresources: + status: {} + additionalPrinterColumns: + - jsonPath: .spec.replica + name: REPLICAS + type: integer + - jsonPath: .status + name: STATUS + type: string + schema: + openAPIV3Schema: + description: ValdBenchmarkJob is the Schema for the valdbenchmarkjobs API + type: object + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + status: + description: ValdBenchmarkJobStatus defines the observed state of ValdBenchmarkJob + enum: + - NotReady + - Available + - Healthy + type: string + spec: + description: ValdBenchmarkJobSpec defines the desired state of ValdBenchmarkJob + type: object + properties: + dataset: + description: BenchmarkDatasetSpec defines the desired state of the dataset used for benchmark job + properties: + group: + type: string + indexes: + type: integer + name: + type: string + range: + description: BenchmarkDatasetRangeSpec defines the desired state of range of dataset + properties: + end: + type: integer + start: + type: integer + required: + - end + - start + type: object + required: + - group + - name + type: object + dimension: + type: integer + epsilon: + type: number + iter: + type: integer + job_type: + type: string + min_num: + format: int32 + type: integer + num: + format: int32 + type: integer + radius: + type: number + repetition: + default: 1 + type: integer + replica: + default: 1 + type: integer + rules: + items: + description: BenchmarkOperatorJobRuleSpec defines the desired state of rule of running benchmark job + properties: + name: + type: string + type: + type: string + required: + - name + - type + type: object + type: array + target: + description: BenchmarkTargetSpec defines the desired state of target the Vald cluster + properties: + host: + type: string + port: + type: integer + required: + - host + - port + type: object + timeout: + type: string + gateway_client: + type: object + properties: + addrs: + type: array + items: + type: string + backoff: + type: object + properties: + backoff_factor: + type: number + backoff_time_limit: + type: string + enable_error_log: + type: boolean + initial_duration: + type: string + jitter_limit: + type: string + maximum_duration: + type: string + retry_count: + type: integer + call_option: + type: object + x-kubernetes-preserve-unknown-fields: true + circuit_breaker: + type: object + properties: + closed_error_rate: + type: number + closed_refresh_timeout: + type: string + half_open_error_rate: + type: number + min_samples: + type: integer + open_timeout: + type: string + connection_pool: + type: object + properties: + enable_dns_resolver: + type: boolean + enable_rebalance: + type: boolean + old_conn_close_duration: + type: string + rebalance_duration: + type: string + size: + type: integer + dial_option: + type: object + properties: + backoff_base_delay: + type: string + backoff_jitter: + type: number + backoff_max_delay: + type: string + backoff_multiplier: + type: number + enable_backoff: + type: boolean + initial_connection_window_size: + type: integer + initial_window_size: + type: integer + insecure: + type: boolean + keepalive: + type: object + properties: + permit_without_stream: + type: boolean + time: + type: string + timeout: + type: string + max_msg_size: + type: integer + min_connection_timeout: + type: string + net: + type: object + properties: + dialer: + type: object + properties: + dual_stack_enabled: + type: boolean + keepalive: + type: string + timeout: + type: string + dns: + type: object + properties: + cache_enabled: + type: boolean + cache_expiration: + type: string + refresh_duration: + type: string + socket_option: + type: object + properties: + ip_recover_destination_addr: + type: boolean + ip_transparent: + type: boolean + reuse_addr: + type: boolean + reuse_port: + type: boolean + tcp_cork: + type: boolean + tcp_defer_accept: + type: boolean + tcp_fast_open: + type: boolean + tcp_no_delay: + type: boolean + tcp_quick_ack: + type: boolean + tls: + type: object + properties: + ca: + type: string + cert: + type: string + enabled: + type: boolean + insecure_skip_verify: + type: boolean + key: + type: string + read_buffer_size: + type: integer + timeout: + type: string + write_buffer_size: + type: integer + health_check_duration: + type: string + max_recv_msg_size: + type: integer + max_retry_rpc_buffer_size: + type: integer + max_send_msg_size: + type: integer + tls: + type: object + properties: + ca: + type: string + cert: + type: string + enabled: + type: boolean + insecure_skip_verify: + type: boolean + key: + type: string + wait_for_ready: + type: boolean + required: + - dimension + - epsilon + - iter + - job_type + - min_num + - num + - radius + - timeout diff --git a/internal/k8s/crd/benchmark/valdbenchmarkoperator.yaml b/internal/k8s/crd/benchmark/valdbenchmarkoperator.yaml new file mode 100644 index 00000000000..e5dcca30eb0 --- /dev/null +++ b/internal/k8s/crd/benchmark/valdbenchmarkoperator.yaml @@ -0,0 +1,361 @@ +# +# Copyright (C) 2019-2022 vdaas.org vald team +# +# 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 +# +# https://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. +# +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: valdbenchmarkoperators.vald.vdaas.org +spec: + group: vald.vdaas.org + names: + kind: ValdBenchmarkOperator + listKind: ValdBenchmarkOperatorList + plural: valdbenchmarkoperators + singular: valdbenchmarkoperator + shortNames: + - vbo + - vbos + scope: Namespaced + versions: + - name: v1 + served: true + storage: true + subresources: + status: {} + additionalPrinterColumns: + - jsonPath: .status + name: STATUS + type: string + schema: + openAPIV3Schema: + description: ValdBenchmarkOperator is the Schema for the valdbenchmarkoperators API + type: object + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + status: + description: ValdBenchmarkOperatorStatus defines the observed state of ValdBenchmarkOperator + enum: + - NotReady + - Available + - Healthy + type: string + spec: + description: ValdBenchmarkOperatorSpec defines the desired state of ValdBenchmarkOperator + type: object + properties: + dataset: + description: BenchmarkDatasetSpec defines the desired state of the dataset used for benchmark job + properties: + group: + type: string + indexes: + type: integer + name: + type: string + range: + description: BenchmarkDatasetRangeSpec defines the desired state of range of dataset + properties: + end: + type: integer + start: + type: integer + required: + - end + - start + type: object + required: + - group + - name + type: object + jobs: + type: array + items: + description: BenchmarkJobSpec defines the desired state of ValdBenchmarkJob + type: object + properties: + dataset: + description: BenchmarkDatasetSpec defines the desired state of the dataset used for benchmark job + properties: + group: + type: string + indexes: + type: integer + name: + type: string + range: + description: BenchmarkDatasetRangeSpec defines the desired state of range of dataset + properties: + end: + type: integer + start: + type: integer + required: + - end + - start + type: object + required: + - group + - name + type: object + dimension: + type: integer + epsilon: + type: number + iter: + type: integer + job_type: + type: string + min_num: + format: int32 + type: integer + num: + format: int32 + type: integer + radius: + type: number + repetition: + default: 1 + type: integer + replica: + default: 1 + type: integer + rules: + items: + description: BenchmarkOperatorJobRuleSpec defines the desired state of rule of running benchmark job + properties: + name: + type: string + type: + type: string + required: + - name + - type + type: object + type: array + target: + description: BenchmarkTargetSpec defines the desired state of target the Vald cluster + properties: + host: + type: string + port: + type: integer + required: + - host + - port + type: object + timeout: + type: string + gateway_client: + type: object + properties: + addrs: + type: array + items: + type: string + backoff: + type: object + properties: + backoff_factor: + type: number + backoff_time_limit: + type: string + enable_error_log: + type: boolean + initial_duration: + type: string + jitter_limit: + type: string + maximum_duration: + type: string + retry_count: + type: integer + call_option: + type: object + x-kubernetes-preserve-unknown-fields: true + circuit_breaker: + type: object + properties: + closed_error_rate: + type: number + closed_refresh_timeout: + type: string + half_open_error_rate: + type: number + min_samples: + type: integer + open_timeout: + type: string + connection_pool: + type: object + properties: + enable_dns_resolver: + type: boolean + enable_rebalance: + type: boolean + old_conn_close_duration: + type: string + rebalance_duration: + type: string + size: + type: integer + dial_option: + type: object + properties: + backoff_base_delay: + type: string + backoff_jitter: + type: number + backoff_max_delay: + type: string + backoff_multiplier: + type: number + enable_backoff: + type: boolean + initial_connection_window_size: + type: integer + initial_window_size: + type: integer + insecure: + type: boolean + keepalive: + type: object + properties: + permit_without_stream: + type: boolean + time: + type: string + timeout: + type: string + max_msg_size: + type: integer + min_connection_timeout: + type: string + net: + type: object + properties: + dialer: + type: object + properties: + dual_stack_enabled: + type: boolean + keepalive: + type: string + timeout: + type: string + dns: + type: object + properties: + cache_enabled: + type: boolean + cache_expiration: + type: string + refresh_duration: + type: string + socket_option: + type: object + properties: + ip_recover_destination_addr: + type: boolean + ip_transparent: + type: boolean + reuse_addr: + type: boolean + reuse_port: + type: boolean + tcp_cork: + type: boolean + tcp_defer_accept: + type: boolean + tcp_fast_open: + type: boolean + tcp_no_delay: + type: boolean + tcp_quick_ack: + type: boolean + tls: + type: object + properties: + ca: + type: string + cert: + type: string + enabled: + type: boolean + insecure_skip_verify: + type: boolean + key: + type: string + read_buffer_size: + type: integer + timeout: + type: string + write_buffer_size: + type: integer + health_check_duration: + type: string + max_recv_msg_size: + type: integer + max_retry_rpc_buffer_size: + type: integer + max_send_msg_size: + type: integer + tls: + type: object + properties: + ca: + type: string + cert: + type: string + enabled: + type: boolean + insecure_skip_verify: + type: boolean + key: + type: string + wait_for_ready: + type: boolean + required: + - dimension + - epsilon + - iter + - job_type + - min_num + - num + - radius + - timeout + target: + properties: + host: + type: string + port: + type: integer + required: + - host + - port + type: object + required: + - dataset + - jobs diff --git a/internal/k8s/rbac/benchmark/operator/clusterrole.yaml b/internal/k8s/rbac/benchmark/operator/clusterrole.yaml new file mode 100644 index 00000000000..c53dec93155 --- /dev/null +++ b/internal/k8s/rbac/benchmark/operator/clusterrole.yaml @@ -0,0 +1,51 @@ +# +# Copyright (C) 2019-2022 vdaas.org vald team +# +# 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 +# +# https://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. +# +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + creationTimestamp: null + name: benchmark-operator-role # TODO: fix + namespace: default # TODO: fix +rules: + - apiGroups: + - vald.vdaas.org + resources: + - valdbenchmarkoperators + - valdbenchmarkjobs + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - vald.vdaas.org + resources: + - valdbenchmarkoperators/finalizers + - valdbenchmarkjobs/finalizers + verbs: + - update + - apiGroups: + - vald.vdaas.org + resources: + - valdbenchmarkoperators/status + - valdbenchmarkojobs/status + verbs: + - get + - patch + - update diff --git a/internal/k8s/rbac/benchmark/operator/clusterrolebinding.yaml b/internal/k8s/rbac/benchmark/operator/clusterrolebinding.yaml new file mode 100644 index 00000000000..512c190f900 --- /dev/null +++ b/internal/k8s/rbac/benchmark/operator/clusterrolebinding.yaml @@ -0,0 +1,27 @@ +# +# Copyright (C) 2019-2022 vdaas.org vald team +# +# 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 +# +# https://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. +# +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: benchmark-operator-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: benchmark-operator-role # TODO: fix +subjects: + - kind: ServiceAccount + name: benchmark-operator-service # TODO: fix + namespace: default # TODO: fix diff --git a/internal/k8s/rbac/benchmark/operator/serviceaccount.yaml b/internal/k8s/rbac/benchmark/operator/serviceaccount.yaml new file mode 100644 index 00000000000..9be29c6b355 --- /dev/null +++ b/internal/k8s/rbac/benchmark/operator/serviceaccount.yaml @@ -0,0 +1,20 @@ +# +# Copyright (C) 2019-2022 vdaas.org vald team +# +# 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 +# +# https://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. +# +apiVersoin: v1 +kind: ServiceAccount +metadata: + name: benchmark-operator-service # TODO: fix + namespace: default # TODO: fix diff --git a/internal/k8s/rbac/benchmark/operator/svc.yaml b/internal/k8s/rbac/benchmark/operator/svc.yaml new file mode 100644 index 00000000000..e69de29bb2d