Skip to content

Commit

Permalink
wip: using pvc definitions from cm; added deploymentspec to common types
Browse files Browse the repository at this point in the history
  • Loading branch information
a9p committed Jun 3, 2023
1 parent ec7b5ad commit 916ffe7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
10 changes: 7 additions & 3 deletions pkg/apis/controller/common/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ limitations under the License.
package v1beta1

import (
v1 "k8s.io/api/core/v1"
corev1 "k8s.io/api/core/v1"
appsv1 "k8s.io/api/apps/v1"
)

// AlgorithmSpec is the specification for a HP or NAS algorithm.
Expand All @@ -28,6 +29,9 @@ type AlgorithmSpec struct {

// Key-value pairs representing settings for suggestion algorithms.
AlgorithmSettings []AlgorithmSetting `json:"algorithmSettings,omitempty"`

// Suggestion service Deployment spec
SuggestionSpec appsv1.DeploymentSpec `json:suggestionSpec,omitempty`
}

// AlgorithmSetting represents key-value pair for HP or NAS algorithm settings.
Expand Down Expand Up @@ -163,7 +167,7 @@ type MetricsCollectorSpec struct {
type SourceSpec struct {
// Model-train source code can expose metrics by http, such as HTTP endpoint in
// prometheus metric format
HttpGet *v1.HTTPGetAction `json:"httpGet,omitempty"`
HttpGet *corev1.HTTPGetAction `json:"httpGet,omitempty"`
// During training model, metrics may be persisted into local file in source
// code, such as tfEvent use case
FileSystemPath *FileSystemPath `json:"fileSystemPath,omitempty"`
Expand Down Expand Up @@ -230,5 +234,5 @@ const (
type CollectorSpec struct {
Kind CollectorKind `json:"kind,omitempty"`
// When kind is "customCollector", this field will be used
CustomCollector *v1.Container `json:"customCollector,omitempty"`
CustomCollector *corev1.Container `json:"customCollector,omitempty"`
}
4 changes: 2 additions & 2 deletions pkg/controller.v1beta1/suggestion/composer/composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ func (g *General) DesiredDeployment(s *suggestionsv1beta1.Suggestion) (*appsv1.D
d.Spec.Template.Spec.ServiceAccountName = suggestionConfigData.ServiceAccountName
}

// Attach volume to the suggestion pod spec if ResumePolicy = FromVolume
if s.Spec.ResumePolicy == experimentsv1beta1.FromVolume {
// Attach volume to the suggestion pod spec if ResumePolicy = FromVolume or persistentVolumeClaimSpec provided
if !equality.Semantic.DeepEqual(suggestionConfigData.PersistentVolumeSpec, corev1.PersistentVolumeSpec{}) || s.Spec.ResumePolicy == experimentsv1beta1.FromVolume {
d.Spec.Template.Spec.Volumes = []corev1.Volume{
{
Name: consts.ContainerSuggestionVolumeName,
Expand Down
31 changes: 27 additions & 4 deletions pkg/controller.v1beta1/suggestion/suggestion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ package suggestion

import (
"context"
"encoding/json"
"fmt"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -192,13 +194,32 @@ func (r *ReconcileSuggestion) ReconcileSuggestion(instance *suggestionsv1beta1.S
suggestionNsName := types.NamespacedName{Name: instance.GetName(), Namespace: instance.GetNamespace()}
logger := log.WithValues("Suggestion", suggestionNsName)

suggestionConfigData, err := katibconfig.GetSuggestionConfigData(instance.Spec.Algorithm.AlgorithmName, r.Client)
// TODO(a9p): the next few blocks are from config.go::GetSuggestionConfigData,
// this should be pulled out into a utility function if correct
// Get katib config map
configMap := &corev1.ConfigMap{}
suggestionConfigData := katibconfig.SuggestionConfig{}
err := r.Get(
context.TODO(),
types.NamespacedName{Name: consts.KatibConfigMapName, Namespace: consts.DefaultKatibNamespace},
configMap)
if err != nil {
return err
}
// Try to find suggestion data in config map
config, ok := configMap.Data[consts.LabelSuggestionTag]
if ok {
// Parse suggestion data to map where key = algorithm name, value = SuggestionConfig
suggestionsConfig := map[string]katibconfig.SuggestionConfig{}
if err := json.Unmarshal([]byte(config), &suggestionsConfig); err != nil {
return err
}
// Try to find SuggestionConfig for the algorithm
suggestionConfigData, _ = suggestionsConfig[instance.Spec.Algorithm.AlgorithmName]
}

// If ResumePolicy is FromVolume or persistentVolumeClaimSpec provided, volume is reconciled for suggestion
if suggestionConfigData.persistentVolumeClaimSpec != nil || instance.Spec.ResumePolicy == experimentsv1beta1.FromVolume {
// If ResumePolicy is FromVolume or PersistentVolumeClaimSpec provided, volume is reconciled for suggestion
if !equality.Semantic.DeepEqual(suggestionConfigData.PersistentVolumeSpec, corev1.PersistentVolumeSpec{}) || instance.Spec.ResumePolicy == experimentsv1beta1.FromVolume {
pvc, pv, err := r.DesiredVolume(instance)
if err != nil {
return err
Expand Down Expand Up @@ -254,8 +275,10 @@ func (r *ReconcileSuggestion) ReconcileSuggestion(instance *suggestionsv1beta1.S
} else {
msg := "Deployment is ready"
instance.MarkSuggestionStatusDeploymentReady(corev1.ConditionTrue, SuggestionDeploymentReady, msg)
// TODO (a9p) this should be in utils, but breaks import due to it being fully-qualified
// instance.setSuggestionSpec(foundDeploy)
instance.Spec.Algorithm.SuggestionSpec = foundDeploy.Spec
}

}
experiment := &experimentsv1beta1.Experiment{}
trials := &trialsv1beta1.TrialList{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (g *General) SyncAssignments(
instance.Status.AlgorithmSettings)

requestSuggestion := &suggestionapi.GetSuggestionsRequest{
Experiment: g.ConvertExperiment(filledE),
Experiment: g.ConvertExperiment(instance, filledE),
Trials: g.ConvertTrials(ts),
CurrentRequestNumber: int32(currentRequestNum),
TotalRequestNumber: int32(instance.Spec.Requests),
Expand Down Expand Up @@ -143,7 +143,7 @@ func (g *General) SyncAssignments(
defer cancelEarlyStopping()

requestEarlyStopping := &suggestionapi.GetEarlyStoppingRulesRequest{
Experiment: g.ConvertExperiment(filledE),
Experiment: g.ConvertExperiment(instance, filledE),
Trials: g.ConvertTrials(ts),
DbManagerAddress: katibmanagerv1beta1.GetDBManagerAddr(),
}
Expand Down Expand Up @@ -216,7 +216,7 @@ func (g *General) ValidateAlgorithmSettings(instance *suggestionsv1beta1.Suggest
defer cancel()

request := &suggestionapi.ValidateAlgorithmSettingsRequest{
Experiment: g.ConvertExperiment(e),
Experiment: g.ConvertExperiment(instance, e),
}

// See https://github.com/grpc/grpc-go/issues/2636
Expand Down Expand Up @@ -264,7 +264,7 @@ func (g *General) ValidateEarlyStoppingSettings(instance *suggestionsv1beta1.Sug
defer cancel()

request := &suggestionapi.ValidateEarlyStoppingSettingsRequest{
EarlyStopping: g.ConvertExperiment(e).Spec.EarlyStopping,
EarlyStopping: g.ConvertExperiment(instance, e).Spec.EarlyStopping,
}

// See https://github.com/grpc/grpc-go/issues/2636
Expand Down Expand Up @@ -294,13 +294,14 @@ func (g *General) ValidateEarlyStoppingSettings(instance *suggestionsv1beta1.Sug
}

// ConvertExperiment converts CRD to the GRPC definition.
func (g *General) ConvertExperiment(e *experimentsv1beta1.Experiment) *suggestionapi.Experiment {
func (g *General) ConvertExperiment(s *suggestionsv1beta1.Suggestion, e *experimentsv1beta1.Experiment) *suggestionapi.Experiment {
res := &suggestionapi.Experiment{}
res.Name = e.Name
res.Spec = &suggestionapi.ExperimentSpec{
Algorithm: &suggestionapi.AlgorithmSpec{
AlgorithmName: e.Spec.Algorithm.AlgorithmName,
AlgorithmSettings: convertAlgorithmSettings(e.Spec.Algorithm.AlgorithmSettings),
SuggestionSpec: s.Spec.Algorithm.SuggestionSpec.DeepCopy(),
},
Objective: &suggestionapi.ObjectiveSpec{
Type: convertObjectiveType(e.Spec.Objective.Type),
Expand Down

0 comments on commit 916ffe7

Please sign in to comment.