Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: kubeflow/katib
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d37e8e3805525c15e1d2c72dca9b0618bbd9ea9f
Choose a base ref
..
head repository: kubeflow/katib
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4c2ae63792f4404eb6075160564a13407e52125b
Choose a head ref
86 changes: 85 additions & 1 deletion Gopkg.lock

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

55 changes: 38 additions & 17 deletions cmd/katib-controller/v1alpha2/main.go
Original file line number Diff line number Diff line change
@@ -20,49 +20,70 @@ limitations under the License.
package main

import (
"log"
"flag"
"os"

"github.com/kubeflow/katib/pkg/api/operators/apis"
controller "github.com/kubeflow/katib/pkg/controller/v1alpha2"
"github.com/spf13/viper"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"

"github.com/kubeflow/katib/pkg/api/operators/apis"
controller "github.com/kubeflow/katib/pkg/controller/v1alpha2"
"github.com/kubeflow/katib/pkg/controller/v1alpha2/consts"
)

func main() {
logf.SetLogger(logf.ZapLogger(false))
log := logf.Log.WithName("entrypoint")

var experimentSuggestionName string

flag.StringVar(&experimentSuggestionName, "experiment-suggestion-name",
"default", "The implementation of suggestion interface in experiment controller (default|fake)")

flag.Parse()

viper.Set(consts.ConfigExperimentSuggestionName, experimentSuggestionName)
log.Info("Config:",
consts.ConfigExperimentSuggestionName,
viper.GetString(consts.ConfigExperimentSuggestionName))

// Get a config to talk to the apiserver
cfg, err := config.GetConfig()
if err != nil {
log.Printf("config.GetConfig()")
log.Fatal(err)
log.Error(err, "Fail to get the config")
os.Exit(1)
}

// Create a new katib controller to provide shared dependencies and start components
mgr, err := manager.New(cfg, manager.Options{})
if err != nil {
log.Printf("manager.New")
log.Fatal(err)
log.Error(err, "unable add APIs to scheme")
os.Exit(1)
}

log.Printf("Registering Components.")
log.Info("Registering Components.")

// Setup Scheme for all resources
if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
log.Printf("apis.AddToScheme")
log.Fatal(err)
log.Error(err, "Fail to create the manager")
os.Exit(1)
}

// Setup katib controller
// Setup all Controllers
log.Info("Setting up controller")
if err := controller.AddToManager(mgr); err != nil {
log.Printf("controller.AddToManager(mgr)")
log.Fatal(err)
log.Error(err, "unable to register controllers to the manager")
os.Exit(1)
}

log.Printf("Starting the Cmd.")

// Starting the katib controller
log.Fatal(mgr.Start(signals.SetupSignalHandler()))
// Start the Cmd
log.Info("Starting the Cmd.")
if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
log.Error(err, "unable to run the manager")
os.Exit(1)
}
}
28 changes: 0 additions & 28 deletions pkg/common/v1alpha2/common.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,9 @@
package v1alpha2

import (
"os"

"k8s.io/apimachinery/pkg/runtime/schema"

experimentsv1alpha2 "github.com/kubeflow/katib/pkg/api/operators/apis/experiment/v1alpha2"
)

const (
KatibManagerServiceIPEnvName = "KATIB_MANAGER_PORT_6789_TCP_ADDR"
KatibManagerServicePortEnvName = "KATIB_MANAGER_PORT_6789_TCP_PORT"
KatibManagerServiceNamespaceEnvName = "KATIB_MANAGER_NAMESPACE"
KatibManagerService = "katib-manager"
KatibManagerPort = "6789"
ManagerAddr = KatibManagerService + ":" + KatibManagerPort
)

func GetManagerAddr() string {
ns := os.Getenv(experimentsv1alpha2.DefaultKatibNamespaceEnvName)
if len(ns) == 0 {
addr := os.Getenv(KatibManagerServiceIPEnvName)
port := os.Getenv(KatibManagerServicePortEnvName)
if len(addr) > 0 && len(port) > 0 {
return addr + ":" + port
} else {
return ManagerAddr
}
} else {
return KatibManagerService + "." + ns + ":" + KatibManagerPort
}
}

func GetSupportedJobList() []schema.GroupVersionKind {
supportedJobList := []schema.GroupVersionKind{
schema.GroupVersionKind{
78 changes: 78 additions & 0 deletions pkg/common/v1alpha2/katib_manager_util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha2

import (
"os"
"context"

experimentsv1alpha2 "github.com/kubeflow/katib/pkg/api/operators/apis/experiment/v1alpha2"
api_pb "github.com/kubeflow/katib/pkg/api/v1alpha2"
"google.golang.org/grpc"
)

const (
KatibManagerServiceIPEnvName = "KATIB_MANAGER_PORT_6789_TCP_ADDR"
KatibManagerServicePortEnvName = "KATIB_MANAGER_PORT_6789_TCP_PORT"
KatibManagerServiceNamespaceEnvName = "KATIB_MANAGER_NAMESPACE"
KatibManagerService = "katib-manager"
KatibManagerPort = "6789"
ManagerAddr = KatibManagerService + ":" + KatibManagerPort
)

type katibManagerClientAndConn struct {
Conn *grpc.ClientConn
KatibManagerClient api_pb.ManagerClient
}

func GetManagerAddr() string {
ns := os.Getenv(experimentsv1alpha2.DefaultKatibNamespaceEnvName)
if len(ns) == 0 {
addr := os.Getenv(KatibManagerServiceIPEnvName)
port := os.Getenv(KatibManagerServicePortEnvName)
if len(addr) > 0 && len(port) > 0 {
return addr + ":" + port
} else {
return ManagerAddr
}
} else {
return KatibManagerService + "." + ns + ":" + KatibManagerPort
}
}

func getKatibManagerClientAndConn() (*katibManagerClientAndConn, error) {
addr := GetManagerAddr()
conn, err := grpc.Dial(addr, grpc.WithInsecure())
if err != nil {
return nil, err
}
kcc := &katibManagerClientAndConn {
Conn: conn,
KatibManagerClient: api_pb.NewManagerClient(conn),
}
return kcc, nil
}

func RegisterExperiment(request *api_pb.RegisterExperimentRequest) (*api_pb.RegisterExperimentReply, error) {
ctx := context.Background()
kcc, err := getKatibManagerClientAndConn()
if err != nil {
return nil, err
}
defer kcc.Conn.Close()
kc := kcc.KatibManagerClient
return kc.RegisterExperiment(ctx, request)
}
5 changes: 5 additions & 0 deletions pkg/controller/v1alpha2/consts/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package consts

const (
ConfigExperimentSuggestionName string = "experiment-suggestion-name"
)
Loading