From e128f809867107342274b71adb7b89d17c900245 Mon Sep 17 00:00:00 2001 From: vankichi Date: Fri, 2 Sep 2022 11:29:43 +0900 Subject: [PATCH] :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 ++++++++++++ 4 files changed, 389 insertions(+), 47 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 d2cdb257211..a573237ac10 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 00000000000..4e021afa7ce --- /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 fa7c19f1174..08b250fff9c 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 00000000000..1a7a727ffd5 --- /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 +}