Skip to content

Commit

Permalink
Fix setting defaults. (#299)
Browse files Browse the repository at this point in the history
* Need to register the default functions.
* In setup we need to invoke setting the defaults on the objects.
* This fixes a break introduced when we refactored the code.
* Fix #284
* Fix #297
  • Loading branch information
jlewi authored Jan 12, 2018
1 parent e619ac4 commit 5cf32fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/apis/tensorflow/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ const GroupName = "tensorflow.org"
// SchemeGroupVersion is the group version used to register these objects.
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: CRDVersion}

func init() {
// We only register manually written functions here. The registration of the
// generated functions takes place in the generated files. The separation
// makes the code compile even when the generated files are missing.
SchemeBuilder.Register(addDefaultingFuncs)
}

// Resource takes an unqualified resource and returns a Group-qualified GroupResource.
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
Expand All @@ -29,6 +36,5 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&TfJobList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)

return nil
}
4 changes: 4 additions & 0 deletions pkg/trainer/training.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
tfv1alpha1 "github.com/tensorflow/k8s/pkg/apis/tensorflow/v1alpha1"
"github.com/tensorflow/k8s/pkg/apis/tensorflow/validation"
tfjobclient "github.com/tensorflow/k8s/pkg/client/clientset/versioned"
"github.com/tensorflow/k8s/pkg/client/clientset/versioned/scheme"
"k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"

Expand Down Expand Up @@ -225,6 +226,9 @@ func (j *TrainingJob) setup(config *tfv1alpha1.ControllerConfig) {
return nil
}

// Set defaults.
scheme.Scheme.Default(j.job)

err := validation.ValidateTfJobSpec(&j.job.Spec)
if err != nil {
return fmt.Errorf("invalid job spec: %v", err)
Expand Down

0 comments on commit 5cf32fa

Please sign in to comment.