Skip to content

Commit

Permalink
Implement webhook validation for the TFJob
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Iwai <[email protected]>
  • Loading branch information
tenzen-y committed Mar 27, 2024
1 parent e85dbf9 commit 6bcb0de
Show file tree
Hide file tree
Showing 10 changed files with 409 additions and 291 deletions.
20 changes: 20 additions & 0 deletions manifests/base/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,23 @@ webhooks:
resources:
- pytorchjobs
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /validate-kubeflow-org-v1-tfjob
failurePolicy: Fail
name: vtfjob.kb.io
rules:
- apiGroups:
- kubeflow.org
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- tfjobs
sideEffects: None
7 changes: 6 additions & 1 deletion pkg/apis/kubeflow.org/v1/tensorflow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,14 @@ const (
TFJobReplicaTypeEval ReplicaType = "Evaluator"
)

// IsChiefOrMaster returns true if the type is Master or Chief.
func IsChiefOrMaster(typ ReplicaType) bool {
return typ == TFJobReplicaTypeChief || typ == TFJobReplicaTypeMaster
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +resource:path=tfjobs
//+kubebuilder:object:root=true
// +kubebuilder:object:root=true

// TFJobList is a list of TFJobs.
type TFJobList struct {
Expand Down
45 changes: 45 additions & 0 deletions pkg/apis/kubeflow.org/v1/tensorflow_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Copyright 2024 The Kubeflow Authors.
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 v1

import "testing"

func TestIsChiefOrMaster(t *testing.T) {
tc := []struct {
Type ReplicaType
Expected bool
}{
{
Type: TFJobReplicaTypeChief,
Expected: true,
},
{
Type: TFJobReplicaTypeMaster,
Expected: true,
},
{
Type: TFJobReplicaTypeWorker,
Expected: false,
},
}
for _, c := range tc {
actual := IsChiefOrMaster(c.Type)
if actual != c.Expected {
t.Errorf("Expected %v; Got %v", c.Expected, actual)
}
}
}
84 changes: 0 additions & 84 deletions pkg/apis/kubeflow.org/v1/tensorflow_validation.go

This file was deleted.

197 changes: 0 additions & 197 deletions pkg/apis/kubeflow.org/v1/tensorflow_validation_test.go

This file was deleted.

Loading

0 comments on commit 6bcb0de

Please sign in to comment.