Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add crds for continuous benchmark tools #1779

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions internal/k8s/benchmark/job/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Copyright (C) 2019-2022 vdaas.org vald team <[email protected]>
//
// 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
116 changes: 116 additions & 0 deletions internal/k8s/benchmark/job/job.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
//
// Copyright (C) 2019-2022 vdaas.org vald team <[email protected]>
//
// 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 (
"context"

"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/handler"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)

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 {
vankichi marked this conversation as resolved.
Show resolved Hide resolved
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 {
vankichi marked this conversation as resolved.
Show resolved Hide resolved
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add error handling for applying option? 🙏

}
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
vankichi marked this conversation as resolved.
Show resolved Hide resolved
func (r *reconciler) Reconcile(ctx context.Context, req reconcile.Request) (res reconcile.Result, err error) {
vankichi marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
named return "res" with type "reconcile.Result" found (nonamedreturns)

return
}

func (r *reconciler) GetName() string {
return r.name
}

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
}

func (r *reconciler) Owns() (client.Object, []builder.OwnsOption) {
return nil, nil
}

func (r *reconciler) Watches() (*source.Kind, handler.EventHandler, []builder.WatchesOption) {
// return &source.Kind{Type: new(corev1.Pod)}, &handler.EnqueueRequestForObject{}
return nil, nil, nil
}
21 changes: 21 additions & 0 deletions internal/k8s/benchmark/job/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Copyright (C) 2019-2022 vdaas.org vald team <[email protected]>
//
// 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

type Option func(*reconciler) error

var defaultOpts = []Option{}
18 changes: 18 additions & 0 deletions internal/k8s/benchmark/operator/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Copyright (C) 2019-2022 vdaas.org vald team <[email protected]>
//
// 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
85 changes: 85 additions & 0 deletions internal/k8s/benchmark/operator/operator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// Copyright (C) 2019-2022 vdaas.org vald team <[email protected]>
//
// 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 (
"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"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add error handling for applying option? 🙏

}
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
vankichi marked this conversation as resolved.
Show resolved Hide resolved
func (r *reconciler) Reconcile(ctx context.Context, req reconcile.Request) (res reconcile.Result, err error) {
vankichi marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
named return "res" with type "reconcile.Result" found (nonamedreturns)

return
}

func (r *reconciler) GetName() string {
return r.name
}

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
}

func (r *reconciler) Owns() (client.Object, []builder.OwnsOption) {
return nil, nil
}

func (r *reconciler) Watches() (*source.Kind, handler.EventHandler, []builder.WatchesOption) {
// return &source.Kind{Type: new(corev1.Pod)}, &handler.EnqueueRequestForObject{}
return nil, nil, nil
}
21 changes: 21 additions & 0 deletions internal/k8s/benchmark/operator/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Copyright (C) 2019-2022 vdaas.org vald team <[email protected]>
//
// 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

type Option func(*reconciler) error

var defaultOpts = []Option{}
Loading