From 326e699f62405e5000b80bce6e05056ee6aaa41f Mon Sep 17 00:00:00 2001 From: vankichi Date: Thu, 25 Aug 2022 13:25:29 +0900 Subject: [PATCH 1/6] :sparkles: add crds for continuous benchmark operator Signed-off-by: vankichi --- internal/k8s/benchmark/job/job.go | 62 +++ internal/k8s/benchmark/job/option.go | 22 ++ internal/k8s/benchmark/operator/operator.go | 62 +++ internal/k8s/benchmark/operator/option.go | 22 ++ .../k8s/crd/benchmark/valdbenchmarkjob.yaml | 321 ++++++++++++++++ .../crd/benchmark/valdbenchmarkoperator.yaml | 361 ++++++++++++++++++ .../k8s/rbac/benchmark/job/clusterrole.yaml | 92 +++++ .../benchmark/job/clusterrolebinding.yaml | 27 ++ .../rbac/benchmark/job/serviceaccount.yaml | 20 + internal/k8s/rbac/benchmark/job/svc.yaml | 31 ++ .../rbac/benchmark/operator/clusterrole.yaml | 95 +++++ .../operator/clusterrolebinding.yaml | 27 ++ .../benchmark/operator/serviceaccount.yaml | 20 + 13 files changed, 1162 insertions(+) create mode 100644 internal/k8s/benchmark/job/job.go create mode 100644 internal/k8s/benchmark/job/option.go create mode 100644 internal/k8s/benchmark/operator/operator.go create mode 100644 internal/k8s/benchmark/operator/option.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/job/clusterrole.yaml create mode 100644 internal/k8s/rbac/benchmark/job/clusterrolebinding.yaml create mode 100644 internal/k8s/rbac/benchmark/job/serviceaccount.yaml create mode 100644 internal/k8s/rbac/benchmark/job/svc.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 diff --git a/internal/k8s/benchmark/job/job.go b/internal/k8s/benchmark/job/job.go new file mode 100644 index 0000000000..0ef9f08f45 --- /dev/null +++ b/internal/k8s/benchmark/job/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/job/option.go b/internal/k8s/benchmark/job/option.go new file mode 100644 index 0000000000..803c3a0108 --- /dev/null +++ b/internal/k8s/benchmark/job/option.go @@ -0,0 +1,22 @@ +// +// 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 + +// TODO: Fix +type Option func() error + +var defaultOpts = []Option{} diff --git a/internal/k8s/benchmark/operator/operator.go b/internal/k8s/benchmark/operator/operator.go new file mode 100644 index 0000000000..0fbe27eaac --- /dev/null +++ b/internal/k8s/benchmark/operator/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/benchmark/operator/option.go b/internal/k8s/benchmark/operator/option.go new file mode 100644 index 0000000000..803c3a0108 --- /dev/null +++ b/internal/k8s/benchmark/operator/option.go @@ -0,0 +1,22 @@ +// +// 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 + +// TODO: Fix +type Option func() error + +var defaultOpts = []Option{} diff --git a/internal/k8s/crd/benchmark/valdbenchmarkjob.yaml b/internal/k8s/crd/benchmark/valdbenchmarkjob.yaml new file mode 100644 index 0000000000..fbd36a0ee1 --- /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 0000000000..e5dcca30eb --- /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/job/clusterrole.yaml b/internal/k8s/rbac/benchmark/job/clusterrole.yaml new file mode 100644 index 0000000000..67717ec3a9 --- /dev/null +++ b/internal/k8s/rbac/benchmark/job/clusterrole.yaml @@ -0,0 +1,92 @@ +# +# 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-job-role # TODO: fix + namespace: default # TODO: fix +rules: + - apiGroups: + - vald.vdaas.org + resources: + - valdbenchmarkjobs + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - vald.vdaas.org + resources: + - valdbenchmarkjobs/finalizers + verbs: + - update + - apiGroups: + - vald.vdaas.org + resources: + - valdbenchmarkojobs/status + verbs: + - get + - patch + - update + - apiGroups: + - apps + resources: + - deployments + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - "" + resources: + - configmaps + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - "" + resources: + - events + verbs: + - create + - patch + - update + - apiGroups: + - "" + resources: + - services + verbs: + - create + - delete + - get + - list + - patch + - update + - watch diff --git a/internal/k8s/rbac/benchmark/job/clusterrolebinding.yaml b/internal/k8s/rbac/benchmark/job/clusterrolebinding.yaml new file mode 100644 index 0000000000..f856e1b753 --- /dev/null +++ b/internal/k8s/rbac/benchmark/job/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-job-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: benchmark-job-role # TODO: fix +subjects: + - kind: ServiceAccount + name: benchmark-job-service # TODO: fix + namespace: default # TODO: fix diff --git a/internal/k8s/rbac/benchmark/job/serviceaccount.yaml b/internal/k8s/rbac/benchmark/job/serviceaccount.yaml new file mode 100644 index 0000000000..3bf6b046ca --- /dev/null +++ b/internal/k8s/rbac/benchmark/job/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-job-service # TODO: fix + namespace: default # TODO: fix diff --git a/internal/k8s/rbac/benchmark/job/svc.yaml b/internal/k8s/rbac/benchmark/job/svc.yaml new file mode 100644 index 0000000000..ce79a170e1 --- /dev/null +++ b/internal/k8s/rbac/benchmark/job/svc.yaml @@ -0,0 +1,31 @@ +# +# 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: v1 +kind: Service +metadata: + name: benchmark-job-svc +spec: + ports: + - name: prometheus + port: 4000 # TODO: fix + targetPort: 4000 # TODO: fix + protocol: TCP + selector: + app.kubernetes.io/name: benchmark-job-svc # TODO: fix + app.kubernetes.io/component: benchmark-job + clusterIP: None + type: ClusterIP + externalTrafficPolicy: "" diff --git a/internal/k8s/rbac/benchmark/operator/clusterrole.yaml b/internal/k8s/rbac/benchmark/operator/clusterrole.yaml new file mode 100644 index 0000000000..414f2f6d88 --- /dev/null +++ b/internal/k8s/rbac/benchmark/operator/clusterrole.yaml @@ -0,0 +1,95 @@ +# +# 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 + - apiGroups: + - apps + resources: + - deployments + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - "" + resources: + - configmaps + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - "" + resources: + - events + verbs: + - create + - patch + - update + - apiGroups: + - "" + resources: + - services + verbs: + - create + - delete + - get + - list + - patch + - update + - watch diff --git a/internal/k8s/rbac/benchmark/operator/clusterrolebinding.yaml b/internal/k8s/rbac/benchmark/operator/clusterrolebinding.yaml new file mode 100644 index 0000000000..512c190f90 --- /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 0000000000..9be29c6b35 --- /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 From 1b9300716a13f36b3afecdb0757eb19b1bd7f871 Mon Sep 17 00:00:00 2001 From: vankichi Date: Tue, 30 Aug 2022 16:43:24 +0900 Subject: [PATCH 2/6] :sparkles: add benchmark operator/job scheme Signed-off-by: vankichi --- internal/k8s/benchmark/job/job.go | 108 +++++++++++++++----- internal/k8s/benchmark/job/option.go | 3 +- internal/k8s/benchmark/operator/operator.go | 77 +++++++++----- internal/k8s/benchmark/operator/option.go | 3 +- 4 files changed, 133 insertions(+), 58 deletions(-) diff --git a/internal/k8s/benchmark/job/job.go b/internal/k8s/benchmark/job/job.go index 0ef9f08f45..a741f49eb1 100644 --- a/internal/k8s/benchmark/job/job.go +++ b/internal/k8s/benchmark/job/job.go @@ -19,44 +19,98 @@ package benchmark import ( "context" - "k8s.io/apimachinery/pkg/runtime" - ctrl "sigs.k8s.io/controller-runtime" + "github.com/vdaas/vald/internal/k8s" + "sigs.k8s.io/controller-runtime/pkg/builder" "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/log" - - valdvdaasorgv1 "vald.vdaas.org/api/v1" + "sigs.k8s.io/controller-runtime/pkg/handler" + "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + "sigs.k8s.io/controller-runtime/pkg/source" ) -// ValdBenchmarkJobReconciler reconciles a ValdBenchmarkJob object -type ValdBenchmarkJobReconciler struct { - client.Client - Scheme *runtime.Scheme +type BenchmarkJobWatcher k8s.ResourceController + +type reconciler struct { + mgr manager.Manager + name string + namespace string + onError func(err error) + onReconcile func(jobList map[string][]BenchmarkJob) + lopts []client.ListOption +} + +type BenchmarkJob struct { + Target *BenchmarkTarget + Dataset *BenchmarkDataset + Replica int + Repetition int + JobType string + Dimension int + Epsilon float32 + Radius float32 + Iter int + Num int32 + MinNUm int32 + Timeout string + Rules []*BenchmarkJobRule +} + +type BenchmarkTarget struct { + Host string + Port int } +type BenchmarkDataset struct { + Name string + Group string + Indexes int + Range *BenchmarkDatasetRange +} + +type BenchmarkDatasetRange struct { + Start int + End int +} + +type BenchmarkJobRule struct { + Name string + Type string +} + +func New(opts ...Option) BenchmarkJobWatcher { + r := new(reconciler) + for _, opt := range append(defaultOpts, opts...) { + opt(r) + } + return r +} + +func (r *reconciler) AddListOpts(opt client.ListOption) {} + //+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 +func (r *reconciler) Reconcile(ctx context.Context, req reconcile.Request) (res reconcile.Result, err error) { + return +} -// 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) +func (r *reconciler) GetName() string { + return r.name +} - // TODO(user): your logic here +func (r *reconciler) NewReconciler(ctx context.Context, mgr manager.Manager) reconcile.Reconciler { + return r +} + +func (r *reconciler) For() (client.Object, []builder.ForOption) { + return nil, nil +} - return ctrl.Result{}, nil +func (r *reconciler) Owns() (client.Object, []builder.OwnsOption) { + return nil, 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) +func (r *reconciler) Watches() (*source.Kind, handler.EventHandler, []builder.WatchesOption) { + // return &source.Kind{Type: new(corev1.Pod)}, &handler.EnqueueRequestForObject{} + return nil, nil, nil } diff --git a/internal/k8s/benchmark/job/option.go b/internal/k8s/benchmark/job/option.go index 803c3a0108..d11c738046 100644 --- a/internal/k8s/benchmark/job/option.go +++ b/internal/k8s/benchmark/job/option.go @@ -16,7 +16,6 @@ package benchmark -// TODO: Fix -type Option func() error +type Option func(*reconciler) error var defaultOpts = []Option{} diff --git a/internal/k8s/benchmark/operator/operator.go b/internal/k8s/benchmark/operator/operator.go index 0fbe27eaac..9194268996 100644 --- a/internal/k8s/benchmark/operator/operator.go +++ b/internal/k8s/benchmark/operator/operator.go @@ -19,44 +19,67 @@ package benchmark import ( "context" - "k8s.io/apimachinery/pkg/runtime" - ctrl "sigs.k8s.io/controller-runtime" + "github.com/vdaas/vald/internal/k8s" + job "github.com/vdaas/vald/internal/k8s/benchmark/job" + "sigs.k8s.io/controller-runtime/pkg/builder" "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/log" - - valdvdaasorgv1 "valdbenchmarkoperator/api/v1" + "sigs.k8s.io/controller-runtime/pkg/handler" + "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + "sigs.k8s.io/controller-runtime/pkg/source" ) -// ValdBenchmarkOperatorReconciler reconciles a ValdBenchmarkOperator object -type ValdBenchmarkOperatorReconciler struct { - client.Client - Scheme *runtime.Scheme +type BenchmarkOperatorWatcher k8s.ResourceController + +type BenchmarkOperator struct { + Target *job.BenchmarkTarget + Dataset *job.BenchmarkDataset + Jobs []*job.BenchmarkJob +} + +type reconciler struct { + mgr manager.Manager + name string + namespace string + onError func(err error) + onReconcile func(operatorList map[string][]BenchmarkOperator) + lopts []client.ListOption } +func New(opts ...Option) BenchmarkOperatorWatcher { + r := new(reconciler) + for _, opt := range append(defaultOpts, opts...) { + opt(r) + } + return r +} + +func (r *reconciler) AddListOpts(opt client.ListOption) {} + //+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 +func (r *reconciler) Reconcile(ctx context.Context, req reconcile.Request) (res reconcile.Result, err error) { + return +} -// 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) +func (r *reconciler) GetName() string { + return r.name +} - // TODO(user): your logic here +func (r *reconciler) NewReconciler(ctx context.Context, mgr manager.Manager) reconcile.Reconciler { + return r +} + +func (r *reconciler) For() (client.Object, []builder.ForOption) { + return nil, nil +} - return ctrl.Result{}, nil +func (r *reconciler) Owns() (client.Object, []builder.OwnsOption) { + return nil, 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) +func (r *reconciler) Watches() (*source.Kind, handler.EventHandler, []builder.WatchesOption) { + // return &source.Kind{Type: new(corev1.Pod)}, &handler.EnqueueRequestForObject{} + return nil, nil, nil } diff --git a/internal/k8s/benchmark/operator/option.go b/internal/k8s/benchmark/operator/option.go index 803c3a0108..d11c738046 100644 --- a/internal/k8s/benchmark/operator/option.go +++ b/internal/k8s/benchmark/operator/option.go @@ -16,7 +16,6 @@ package benchmark -// TODO: Fix -type Option func() error +type Option func(*reconciler) error var defaultOpts = []Option{} From 0f95f1d4e78a539d7ec271daecdb471ee5cbf069 Mon Sep 17 00:00:00 2001 From: vankichi Date: Wed, 31 Aug 2022 09:42:19 +0900 Subject: [PATCH 3/6] :sparkles: rename package names and add doc.go Signed-off-by: vankichi --- internal/k8s/benchmark/job/doc.go | 18 ++++++++++++++++++ internal/k8s/benchmark/job/job.go | 2 +- internal/k8s/benchmark/job/option.go | 2 +- internal/k8s/benchmark/operator/doc.go | 18 ++++++++++++++++++ internal/k8s/benchmark/operator/operator.go | 2 +- internal/k8s/benchmark/operator/option.go | 2 +- 6 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 internal/k8s/benchmark/job/doc.go create mode 100644 internal/k8s/benchmark/operator/doc.go diff --git a/internal/k8s/benchmark/job/doc.go b/internal/k8s/benchmark/job/doc.go new file mode 100644 index 0000000000..678bce94ab --- /dev/null +++ b/internal/k8s/benchmark/job/doc.go @@ -0,0 +1,18 @@ +// +// 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 job provides benchmark job crd information and preriodically update +package job diff --git a/internal/k8s/benchmark/job/job.go b/internal/k8s/benchmark/job/job.go index a741f49eb1..d2cdb25721 100644 --- a/internal/k8s/benchmark/job/job.go +++ b/internal/k8s/benchmark/job/job.go @@ -14,7 +14,7 @@ // limitations under the License. // -package benchmark +package job import ( "context" diff --git a/internal/k8s/benchmark/job/option.go b/internal/k8s/benchmark/job/option.go index d11c738046..a7fe8b6b80 100644 --- a/internal/k8s/benchmark/job/option.go +++ b/internal/k8s/benchmark/job/option.go @@ -14,7 +14,7 @@ // limitations under the License. // -package benchmark +package job type Option func(*reconciler) error diff --git a/internal/k8s/benchmark/operator/doc.go b/internal/k8s/benchmark/operator/doc.go new file mode 100644 index 0000000000..e9a3f31044 --- /dev/null +++ b/internal/k8s/benchmark/operator/doc.go @@ -0,0 +1,18 @@ +// +// 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 operator provides benchmark operator crd information and preriodically update +package operator diff --git a/internal/k8s/benchmark/operator/operator.go b/internal/k8s/benchmark/operator/operator.go index 9194268996..fa7c19f117 100644 --- a/internal/k8s/benchmark/operator/operator.go +++ b/internal/k8s/benchmark/operator/operator.go @@ -14,7 +14,7 @@ // limitations under the License. // -package benchmark +package operator import ( "context" diff --git a/internal/k8s/benchmark/operator/option.go b/internal/k8s/benchmark/operator/option.go index d11c738046..d4abeb0f3e 100644 --- a/internal/k8s/benchmark/operator/option.go +++ b/internal/k8s/benchmark/operator/option.go @@ -14,7 +14,7 @@ // limitations under the License. // -package benchmark +package operator type Option func(*reconciler) error From 9747e30a3daaccb5e9a544b94a0a54401cdd4269 Mon Sep 17 00:00:00 2001 From: vankichi Date: Fri, 2 Sep 2022 11:29:43 +0900 Subject: [PATCH 4/6] :sparkles: create runtime object Signed-off-by: vankichi --- internal/k8s/benchmark/job/job.go | 40 +-- internal/k8s/benchmark/job/types.go | 242 ++++++++++++++++++ internal/k8s/benchmark/operator/operator.go | 9 +- internal/k8s/benchmark/operator/types.go | 145 +++++++++++ .../k8s/rbac/benchmark/job/clusterrole.yaml | 72 +++--- .../rbac/benchmark/operator/clusterrole.yaml | 73 +++--- 6 files changed, 460 insertions(+), 121 deletions(-) create mode 100644 internal/k8s/benchmark/job/types.go create mode 100644 internal/k8s/benchmark/operator/types.go diff --git a/internal/k8s/benchmark/job/job.go b/internal/k8s/benchmark/job/job.go index d2cdb25721..a573237ac1 100644 --- a/internal/k8s/benchmark/job/job.go +++ b/internal/k8s/benchmark/job/job.go @@ -35,48 +35,10 @@ type reconciler struct { name string namespace string onError func(err error) - onReconcile func(jobList map[string][]BenchmarkJob) + onReconcile func(jobList map[string][]BenchmarkJobSpec) lopts []client.ListOption } -type BenchmarkJob struct { - Target *BenchmarkTarget - Dataset *BenchmarkDataset - Replica int - Repetition int - JobType string - Dimension int - Epsilon float32 - Radius float32 - Iter int - Num int32 - MinNUm int32 - Timeout string - Rules []*BenchmarkJobRule -} - -type BenchmarkTarget struct { - Host string - Port int -} - -type BenchmarkDataset struct { - Name string - Group string - Indexes int - Range *BenchmarkDatasetRange -} - -type BenchmarkDatasetRange struct { - Start int - End int -} - -type BenchmarkJobRule struct { - Name string - Type string -} - func New(opts ...Option) BenchmarkJobWatcher { r := new(reconciler) for _, opt := range append(defaultOpts, opts...) { diff --git a/internal/k8s/benchmark/job/types.go b/internal/k8s/benchmark/job/types.go new file mode 100644 index 0000000000..4e021afa7c --- /dev/null +++ b/internal/k8s/benchmark/job/types.go @@ -0,0 +1,242 @@ +// +// 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 job + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +type BenchmarkJobSpec struct { + Target *BenchmarkTarget + Dataset *BenchmarkDataset + Replica int + Repetition int + JobType string + Dimension int + Epsilon float32 + Radius float32 + Iter int + Num int32 + MinNum int32 + Timeout string + Rules []*BenchmarkJobRule +} + +type BenchmarkJobStatus string + +const ( + BenchmarkJobNotReady = BenchmarkJobStatus("NotReady") + BenchmarkJobAvailable = BenchmarkJobStatus("Available") + BenchmarkJobHealthy = BenchmarkJobStatus("Healthy") +) + +type BenchmarkTarget struct { + Host string + Port int +} + +type BenchmarkDataset struct { + Name string + Group string + Indexes int + Range *BenchmarkDatasetRange +} + +type BenchmarkDatasetRange struct { + Start int + End int +} + +type BenchmarkJobRule struct { + Name string + Type string +} + +type BenchmarkJob struct { + metav1.TypeMeta + metav1.ObjectMeta + + Spec BenchmarkJobSpec + Status BenchmarkJobStatus +} + +type BenchmarkJobList struct { + metav1.TypeMeta + metav1.ListMeta + + Items []BenchmarkJob +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BenchmarkDataset) DeepCopyInto(out *BenchmarkDataset) { + *out = *in + if in.Range != nil { + in, out := &in.Range, &out.Range + *out = new(BenchmarkDatasetRange) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BenchmarkDataset. +func (in *BenchmarkDataset) DeepCopy() *BenchmarkDataset { + if in == nil { + return nil + } + out := new(BenchmarkDataset) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BenchmarkDatasetRange) DeepCopyInto(out *BenchmarkDatasetRange) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BenchmarkDatasetRange. +func (in *BenchmarkDatasetRange) DeepCopy() *BenchmarkDatasetRange { + if in == nil { + return nil + } + out := new(BenchmarkDatasetRange) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BenchmarkJobRule) DeepCopyInto(out *BenchmarkJobRule) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BenchmarkJobRule. +func (in *BenchmarkJobRule) DeepCopy() *BenchmarkJobRule { + if in == nil { + return nil + } + out := new(BenchmarkJobRule) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BenchmarkJobSpec) DeepCopyInto(out *BenchmarkJobSpec) { + *out = *in + if in.Target != nil { + in, out := &in.Target, &out.Target + *out = new(BenchmarkTarget) + **out = **in + } + if in.Dataset != nil { + in, out := &in.Dataset, &out.Dataset + *out = new(BenchmarkDataset) + (*in).DeepCopyInto(*out) + } + if in.Rules != nil { + in, out := &in.Rules, &out.Rules + *out = make([]*BenchmarkJobRule, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(BenchmarkJobRule) + **out = **in + } + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BenchmarkJobSpec. +func (in *BenchmarkJobSpec) DeepCopy() *BenchmarkJobSpec { + if in == nil { + return nil + } + out := new(BenchmarkJobSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BenchmarkTarget) DeepCopyInto(out *BenchmarkTarget) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BenchmarkTarget. +func (in *BenchmarkTarget) DeepCopy() *BenchmarkTarget { + if in == nil { + return nil + } + out := new(BenchmarkTarget) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BenchmarkJob) DeepCopyInto(out *BenchmarkJob) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BenchmarkOperator. +func (in *BenchmarkJob) DeepCopy() *BenchmarkJob { + if in == nil { + return nil + } + out := new(BenchmarkJob) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *BenchmarkJob) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BenchmarkJobList) DeepCopyInto(out *BenchmarkJobList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]BenchmarkJob, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BenchmarkOperatorList. +func (in *BenchmarkJobList) DeepCopy() *BenchmarkJobList { + if in == nil { + return nil + } + out := new(BenchmarkJobList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *BenchmarkJobList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} diff --git a/internal/k8s/benchmark/operator/operator.go b/internal/k8s/benchmark/operator/operator.go index fa7c19f117..08b250fff9 100644 --- a/internal/k8s/benchmark/operator/operator.go +++ b/internal/k8s/benchmark/operator/operator.go @@ -20,7 +20,6 @@ import ( "context" "github.com/vdaas/vald/internal/k8s" - job "github.com/vdaas/vald/internal/k8s/benchmark/job" "sigs.k8s.io/controller-runtime/pkg/builder" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/handler" @@ -31,18 +30,12 @@ import ( type BenchmarkOperatorWatcher k8s.ResourceController -type BenchmarkOperator struct { - Target *job.BenchmarkTarget - Dataset *job.BenchmarkDataset - Jobs []*job.BenchmarkJob -} - type reconciler struct { mgr manager.Manager name string namespace string onError func(err error) - onReconcile func(operatorList map[string][]BenchmarkOperator) + onReconcile func(operatorList map[string][]BenchmarkOperatorSpec) lopts []client.ListOption } diff --git a/internal/k8s/benchmark/operator/types.go b/internal/k8s/benchmark/operator/types.go new file mode 100644 index 0000000000..1a7a727ffd --- /dev/null +++ b/internal/k8s/benchmark/operator/types.go @@ -0,0 +1,145 @@ +// +// 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 operator + +import ( + job "github.com/vdaas/vald/internal/k8s/benchmark/job" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +type BenchmarkOperatorSpec struct { + Target *job.BenchmarkTarget + Dataset *job.BenchmarkDataset + Jobs []*job.BenchmarkJobSpec +} + +type BenchmarkOperatorStatus string + +const ( + BenchmarkOperatorNotReady = BenchmarkOperatorStatus("NotReady") + BenchmarkOperatorAvailable = BenchmarkOperatorStatus("Available") + BenchmarkOperatorHealthy = BenchmarkOperatorStatus("Healthy") +) + +type BenchmarkOperator struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec BenchmarkOperatorSpec `json:"spec,omitempty"` + Status BenchmarkOperatorStatus `json:"status,omitempty"` +} + +type BenchmarkOperatorList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []BenchmarkOperator `json:"items"` +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BenchmarkOperator) DeepCopyInto(out *BenchmarkOperator) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BenchmarkOperator. +func (in *BenchmarkOperator) DeepCopy() *BenchmarkOperator { + if in == nil { + return nil + } + out := new(BenchmarkOperator) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *BenchmarkOperator) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BenchmarkOperatorList) DeepCopyInto(out *BenchmarkOperatorList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]BenchmarkOperator, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BenchmarkOperatorList. +func (in *BenchmarkOperatorList) DeepCopy() *BenchmarkOperatorList { + if in == nil { + return nil + } + out := new(BenchmarkOperatorList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *BenchmarkOperatorList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BenchmarkOperatorSpec) DeepCopyInto(out *BenchmarkOperatorSpec) { + *out = *in + if in.Target != nil { + in, out := &in.Target, &out.Target + *out = new(job.BenchmarkTarget) + **out = **in + } + if in.Dataset != nil { + in, out := &in.Dataset, &out.Dataset + *out = new(job.BenchmarkDataset) + (*in).DeepCopyInto(*out) + } + if in.Jobs != nil { + in, out := &in.Jobs, &out.Jobs + *out = make([]*job.BenchmarkJobSpec, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(job.BenchmarkJobSpec) + (*in).DeepCopyInto(*out) + } + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BenchmarkOperatorSpec. +func (in *BenchmarkOperatorSpec) DeepCopy() *BenchmarkOperatorSpec { + if in == nil { + return nil + } + out := new(BenchmarkOperatorSpec) + in.DeepCopyInto(out) + return out +} diff --git a/internal/k8s/rbac/benchmark/job/clusterrole.yaml b/internal/k8s/rbac/benchmark/job/clusterrole.yaml index 67717ec3a9..4cdc233ec4 100644 --- a/internal/k8s/rbac/benchmark/job/clusterrole.yaml +++ b/internal/k8s/rbac/benchmark/job/clusterrole.yaml @@ -20,6 +20,18 @@ metadata: name: benchmark-job-role # TODO: fix namespace: default # TODO: fix rules: + - apiGroups: + - apps + resources: + - deployments + verbs: + - create + - delete + - get + - list + - patch + - update + - watch - apiGroups: - vald.vdaas.org resources: @@ -41,52 +53,40 @@ rules: - apiGroups: - vald.vdaas.org resources: - - valdbenchmarkojobs/status + - valdbenchmarkjobs/status verbs: - get - patch - update - apiGroups: - - apps + - "" resources: - - deployments + - configmaps verbs: - - create - - delete - - get - - list - - patch - - update - - watch - - apiGroups: - - "" - resources: - - configmaps - verbs: - - create - - delete - - get - - list - - patch - - update - - watch + - create + - delete + - get + - list + - patch + - update + - watch - apiGroups: - - "" + - "" resources: - - events + - events verbs: - - create - - patch - - update + - create + - patch + - update - apiGroups: - - "" + - "" resources: - - services + - services verbs: - - create - - delete - - get - - list - - patch - - update - - watch + - create + - delete + - get + - list + - patch + - update + - watch diff --git a/internal/k8s/rbac/benchmark/operator/clusterrole.yaml b/internal/k8s/rbac/benchmark/operator/clusterrole.yaml index 414f2f6d88..044120cf3b 100644 --- a/internal/k8s/rbac/benchmark/operator/clusterrole.yaml +++ b/internal/k8s/rbac/benchmark/operator/clusterrole.yaml @@ -20,11 +20,22 @@ metadata: name: benchmark-operator-role # TODO: fix namespace: default # TODO: fix rules: + - apiGroups: + - apps + resources: + - deployments + verbs: + - create + - delete + - get + - list + - patch + - update + - watch - apiGroups: - vald.vdaas.org resources: - valdbenchmarkoperators - - valdbenchmarkjobs verbs: - create - delete @@ -37,59 +48,45 @@ rules: - vald.vdaas.org resources: - valdbenchmarkoperators/finalizers - - valdbenchmarkjobs/finalizers verbs: - update - apiGroups: - vald.vdaas.org resources: - valdbenchmarkoperators/status - - valdbenchmarkojobs/status verbs: - get - patch - update - apiGroups: - - apps + - "" resources: - - deployments + - configmaps verbs: - - create - - delete - - get - - list - - patch - - update - - watch - - apiGroups: - - "" - resources: - - configmaps - verbs: - - create - - delete - - get - - list - - patch - - update - - watch + - create + - delete + - get + - list + - patch + - update + - watch - apiGroups: - - "" + - "" resources: - - events + - events verbs: - - create - - patch - - update + - create + - patch + - update - apiGroups: - - "" + - "" resources: - - services + - services verbs: - - create - - delete - - get - - list - - patch - - update - - watch + - create + - delete + - get + - list + - patch + - update + - watch From b115100586f95caaf8899f08a740faf40cc8216b Mon Sep 17 00:00:00 2001 From: Kiichiro YUKAWA Date: Thu, 8 Sep 2022 17:34:07 +0900 Subject: [PATCH 5/6] Apply suggestions from code review Co-authored-by: Yusuke Kato --- internal/k8s/benchmark/job/job.go | 3 --- internal/k8s/benchmark/operator/operator.go | 3 --- 2 files changed, 6 deletions(-) diff --git a/internal/k8s/benchmark/job/job.go b/internal/k8s/benchmark/job/job.go index a573237ac1..81550c2c91 100644 --- a/internal/k8s/benchmark/job/job.go +++ b/internal/k8s/benchmark/job/job.go @@ -49,9 +49,6 @@ func New(opts ...Option) BenchmarkJobWatcher { func (r *reconciler) AddListOpts(opt client.ListOption) {} -//+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 func (r *reconciler) Reconcile(ctx context.Context, req reconcile.Request) (res reconcile.Result, err error) { return } diff --git a/internal/k8s/benchmark/operator/operator.go b/internal/k8s/benchmark/operator/operator.go index 08b250fff9..ded56e2a44 100644 --- a/internal/k8s/benchmark/operator/operator.go +++ b/internal/k8s/benchmark/operator/operator.go @@ -49,9 +49,6 @@ func New(opts ...Option) BenchmarkOperatorWatcher { func (r *reconciler) AddListOpts(opt client.ListOption) {} -//+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 func (r *reconciler) Reconcile(ctx context.Context, req reconcile.Request) (res reconcile.Result, err error) { return } From efbfd1357aa73d3a8aecee9296940cbdca0b142f Mon Sep 17 00:00:00 2001 From: vankichi Date: Thu, 8 Sep 2022 17:51:39 +0900 Subject: [PATCH 6/6] :recycle: apply feedback Signed-off-by: vankichi --- internal/k8s/benchmark/job/job.go | 1 + internal/k8s/benchmark/operator/operator.go | 1 + internal/k8s/benchmark/operator/types.go | 6 +++--- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/k8s/benchmark/job/job.go b/internal/k8s/benchmark/job/job.go index 81550c2c91..6cdfaf6b2e 100644 --- a/internal/k8s/benchmark/job/job.go +++ b/internal/k8s/benchmark/job/job.go @@ -42,6 +42,7 @@ type reconciler struct { func New(opts ...Option) BenchmarkJobWatcher { r := new(reconciler) for _, opt := range append(defaultOpts, opts...) { + // TODO: impl error handling after implement functional option opt(r) } return r diff --git a/internal/k8s/benchmark/operator/operator.go b/internal/k8s/benchmark/operator/operator.go index ded56e2a44..9a2cba099f 100644 --- a/internal/k8s/benchmark/operator/operator.go +++ b/internal/k8s/benchmark/operator/operator.go @@ -42,6 +42,7 @@ type reconciler struct { func New(opts ...Option) BenchmarkOperatorWatcher { r := new(reconciler) for _, opt := range append(defaultOpts, opts...) { + // TODO: impl error handling after implement functional option opt(r) } return r diff --git a/internal/k8s/benchmark/operator/types.go b/internal/k8s/benchmark/operator/types.go index 1a7a727ffd..378b8facec 100644 --- a/internal/k8s/benchmark/operator/types.go +++ b/internal/k8s/benchmark/operator/types.go @@ -31,9 +31,9 @@ type BenchmarkOperatorSpec struct { type BenchmarkOperatorStatus string const ( - BenchmarkOperatorNotReady = BenchmarkOperatorStatus("NotReady") - BenchmarkOperatorAvailable = BenchmarkOperatorStatus("Available") - BenchmarkOperatorHealthy = BenchmarkOperatorStatus("Healthy") + BenchmarkOperatorNotReady BenchmarkOperatorStatus = "NotReady" + BenchmarkOperatorAvailable BenchmarkOperatorStatus = "Available" + BenchmarkOperatorHealthy BenchmarkOperatorStatus = "Healthy" ) type BenchmarkOperator struct {