-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: Move all generated strategy to unversioned package (#327)
* move all strategy to unversioned pkg * better naming * generate strategy to unversioned pkg when creatign resource * remove used import in the code template * nit: import order
- Loading branch information
1 parent
6080217
commit 20b540d
Showing
10 changed files
with
196 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Copyright 2017 The Kubernetes 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 kingsport | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/util/validation/field" | ||
) | ||
|
||
func (FestivalStrategy) NamespaceScoped() bool { return false } | ||
|
||
func (FestivalStatusStrategy) NamespaceScoped() bool { return false } | ||
|
||
// Validate checks that an instance of Festival is well formed | ||
func (FestivalStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList { | ||
o := obj.(*Festival) | ||
log.Printf("Validating fields for Festival %s\n", o.Name) | ||
errors := field.ErrorList{} | ||
|
||
if o.Spec.Year < 0 { | ||
errors = append(errors, | ||
field.Invalid(field.NewPath("spec", "year"), o.Spec.Year, "year must be > 0")) | ||
} | ||
|
||
// perform validation here and add to errors using field.Invalid | ||
return errors | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
Copyright 2017 The Kubernetes 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 miskatonic | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/util/validation/field" | ||
) | ||
|
||
// Resource Validation | ||
func (UniversityStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList { | ||
university := obj.(*University) | ||
log.Printf("Validating University %s\n", university.Name) | ||
errors := field.ErrorList{} | ||
if university.Spec.MaxStudents == nil || *university.Spec.MaxStudents < 1 || *university.Spec.MaxStudents > 150 { | ||
errors = append(errors, field.Invalid( | ||
field.NewPath("spec", "MaxStudents"), | ||
*university.Spec.MaxStudents, | ||
"Must be between 1 and 150")) | ||
} | ||
return errors | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
Copyright 2017 The Kubernetes 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 olympus | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/util/validation/field" | ||
"k8s.io/apiserver/pkg/storage" | ||
"k8s.io/apimachinery/pkg/labels" | ||
"k8s.io/apimachinery/pkg/fields" | ||
"k8s.io/apiserver/pkg/registry/generic" | ||
) | ||
|
||
// Validate checks that an instance of Poseidon is well formed | ||
func (PoseidonStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList { | ||
o := obj.(*Poseidon) | ||
log.Printf("Validating fields for Poseidon %s\n", o.Name) | ||
errors := field.ErrorList{} | ||
// perform validation here and add to errors using field.Invalid | ||
return errors | ||
} | ||
|
||
func (b PoseidonStrategy) TriggerFunc(obj runtime.Object) []storage.MatchValue { | ||
// Change this function to override the trigger fn that is used | ||
value := b.DefaultStorageStrategy.TriggerFunc(obj) | ||
return value | ||
} | ||
|
||
func (b PoseidonStrategy) BasicMatch(label labels.Selector, field fields.Selector) storage.SelectionPredicate { | ||
return storage.SelectionPredicate{ | ||
Label: label, | ||
Field: field, | ||
GetAttrs: b.GetAttrs, | ||
IndexFields: []string{"spec.deployment.name"}, | ||
} | ||
} | ||
|
||
// The following functions allow spec.deployment.name to be selected when listing | ||
// or watching resources | ||
func (b PoseidonStrategy) GetAttrs(o runtime.Object) (labels.Set, fields.Set, bool, error) { | ||
// Change this function to override the attributes that are matched | ||
l, _, uninit, e := b.DefaultStorageStrategy.GetAttrs(o) | ||
obj := o.(*Poseidon) | ||
|
||
fs := fields.Set{"spec.deployment.name": obj.Spec.Deployment.Name} | ||
fs = generic.AddObjectMetaFieldsSet(fs, &obj.ObjectMeta, true) | ||
return l, fs, uninit, e | ||
} |
Oops, something went wrong.