-
Notifications
You must be signed in to change notification settings - Fork 443
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 Katib Client in v1alpha2 #480
Changes from 1 commit
b9ff3c8
86cac8f
72e0c61
e3b7ffd
2a0ca93
5d7cb04
12a455a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,10 @@ const ( | |
|
||
// Default value of Spec.TemplatePath | ||
DefaultTrialTemplatePath = "defaultTrialTemplate.yaml" | ||
|
||
// Name of the configMap for Trial templates | ||
TrialTemplatesName = "trial-template" | ||
|
||
// Name of the configMap for MetricsCollector templates | ||
MetricsCollectorTemplatesName = "metrics-collector-template" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the default metric config map similar to trial? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I will rename it, like for Trial template |
||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,19 +24,13 @@ import ( | |
apiv1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
cl "sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/client/config" | ||
) | ||
|
||
type katibClient struct { | ||
client client.Client | ||
} | ||
|
||
const ( | ||
trialTemplatesName = "trial-template" | ||
metricsCollectorTemplatesName = "metricscollector-template" | ||
) | ||
|
||
func NewClient(options client.Options) (*katibClient, error) { | ||
cfg, err := config.GetConfig() | ||
if err != nil { | ||
|
@@ -51,7 +45,7 @@ func NewClient(options client.Options) (*katibClient, error) { | |
func (k *katibClient) GetExperimentList(namespace ...string) (*experimentv1alpha2.ExperimentList, error) { | ||
ns := getNamespace(namespace...) | ||
expList := &experimentv1alpha2.ExperimentList{} | ||
listOpt := cl.InNamespace(ns) | ||
listOpt := client.InNamespace(ns) | ||
|
||
if err := k.client.List(context.Background(), listOpt, expList); err != nil { | ||
return expList, err | ||
|
@@ -68,12 +62,21 @@ func (k *katibClient) CreateExperiment(experiment *experimentv1alpha2.Experiment | |
return nil | ||
} | ||
|
||
func (k *katibClient) GetConfigMap(name string, namespace ...string) (map[string]string, error) { | ||
ns := getNamespace(namespace...) | ||
configMap := &apiv1.ConfigMap{} | ||
if err := k.client.Get(context.TODO(), types.NamespacedName{Name: name, Namespace: ns}, configMap); err != nil { | ||
return map[string]string{}, err | ||
} | ||
return configMap.Data, nil | ||
} | ||
|
||
func (k *katibClient) GetTrialTemplates(namespace ...string) (map[string]string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for now, trial template can be stored in any configmap, not just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any way to get Trial templates configmap? |
||
|
||
ns := getNamespace(namespace...) | ||
trialTemplates := &apiv1.ConfigMap{} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest move getConfigMap into this file, too and then please call getConfigMap There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
if err := k.client.Get(context.Background(), types.NamespacedName{Name: trialTemplatesName, Namespace: ns}, trialTemplates); err != nil { | ||
if err := k.client.Get(context.Background(), types.NamespacedName{Name: experimentv1alpha2.TrialTemplatesName, Namespace: ns}, trialTemplates); err != nil { | ||
return nil, err | ||
} | ||
return trialTemplates.Data, nil | ||
|
@@ -84,7 +87,7 @@ func (k *katibClient) UpdateTrialTemplates(newTrialTemplates map[string]string, | |
ns := getNamespace(namespace...) | ||
trialTemplates := &apiv1.ConfigMap{} | ||
|
||
if err := k.client.Get(context.Background(), types.NamespacedName{Name: trialTemplatesName, Namespace: ns}, trialTemplates); err != nil { | ||
if err := k.client.Get(context.Background(), types.NamespacedName{Name: experimentv1alpha2.TrialTemplatesName, Namespace: ns}, trialTemplates); err != nil { | ||
return err | ||
} | ||
trialTemplates.Data = newTrialTemplates | ||
|
@@ -100,7 +103,7 @@ func (k *katibClient) GetMetricsCollectorTemplates(namespace ...string) (map[str | |
ns := getNamespace(namespace...) | ||
metricsCollectorTemplates := &apiv1.ConfigMap{} | ||
|
||
if err := k.client.Get(context.Background(), types.NamespacedName{Name: metricsCollectorTemplatesName, Namespace: ns}, metricsCollectorTemplates); err != nil { | ||
if err := k.client.Get(context.Background(), types.NamespacedName{Name: experimentv1alpha2.MetricsCollectorTemplatesName, Namespace: ns}, metricsCollectorTemplates); err != nil { | ||
return nil, err | ||
} | ||
return metricsCollectorTemplates.Data, nil | ||
|
@@ -112,7 +115,7 @@ func (k *katibClient) UpdateMetricsCollectorTemplates(newMCTemplates map[string] | |
ns := getNamespace(namespace...) | ||
metricsCollectorTemplates := &apiv1.ConfigMap{} | ||
|
||
if err := k.client.Get(context.Background(), types.NamespacedName{Name: metricsCollectorTemplatesName, Namespace: ns}, metricsCollectorTemplates); err != nil { | ||
if err := k.client.Get(context.Background(), types.NamespacedName{Name: experimentv1alpha2.MetricsCollectorTemplatesName, Namespace: ns}, metricsCollectorTemplates); err != nil { | ||
return err | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line no 23 has it added already