generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ClusterQueue visibility on-demand (#1251)
Co-authored-by: Yuki Iwai <yuki.iwai.tz@gmail.com> Co-authored-by: Aldo Culquicondor <1299064+alculquicondor@users.noreply.github.com> Co-authored-by: Michał Woźniak <mimowo@users.noreply.github.com>
- Loading branch information
Showing
67 changed files
with
6,142 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
Copyright 2023 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 v1alpha1_test | ||
|
||
import ( | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/util/diff" | ||
|
||
. "sigs.k8s.io/kueue/apis/visibility/v1alpha1" | ||
"sigs.k8s.io/kueue/pkg/visibility/api" | ||
) | ||
|
||
func TestPendingWorkloadsOptions(t *testing.T) { | ||
codec := runtime.NewParameterCodec(api.Scheme) | ||
|
||
cases := map[string]struct { | ||
inputQueryParams url.Values | ||
wantQueryParams url.Values | ||
wantPendingWorkloadOptions PendingWorkloadOptions | ||
}{ | ||
"correct parameters": { | ||
inputQueryParams: url.Values{ | ||
"limit": {"1"}, | ||
"offset": {"2"}, | ||
}, | ||
wantQueryParams: url.Values{ | ||
"limit": {"1"}, | ||
"offset": {"2"}, | ||
}, | ||
wantPendingWorkloadOptions: PendingWorkloadOptions{ | ||
Limit: 1, | ||
Offset: 2, | ||
}, | ||
}, | ||
"default values": { | ||
inputQueryParams: url.Values{ | ||
"limit": {"0"}, | ||
"offset": {"0"}, | ||
}, | ||
wantQueryParams: url.Values{ | ||
"limit": {"1000"}, | ||
"offset": {"0"}, | ||
}, | ||
wantPendingWorkloadOptions: PendingWorkloadOptions{ | ||
Limit: 1000, | ||
Offset: 0, | ||
}, | ||
}, | ||
} | ||
|
||
for name, tc := range cases { | ||
t.Run(name, func(t *testing.T) { | ||
// versioned -> query params | ||
actualParameters, err := codec.EncodeParameters(&tc.wantPendingWorkloadOptions, SchemeGroupVersion) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if d := cmp.Diff(actualParameters, tc.wantQueryParams); d != "" { | ||
t.Fatalf("Unxpected serialization:\n%s", diff.ObjectGoPrintSideBySide(tc.wantQueryParams, actualParameters)) | ||
} | ||
|
||
// query params -> versioned | ||
convertedPendingWorkloadOptions := PendingWorkloadOptions{} | ||
err = codec.DecodeParameters(tc.inputQueryParams, SchemeGroupVersion, &convertedPendingWorkloadOptions) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if d := cmp.Diff(convertedPendingWorkloadOptions, tc.wantPendingWorkloadOptions); d != "" { | ||
t.Fatalf("Unexpected deserialization:\n%s", diff.ObjectGoPrintSideBySide(tc.wantPendingWorkloadOptions, convertedPendingWorkloadOptions)) | ||
} | ||
}) | ||
} | ||
} |
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,37 @@ | ||
/* | ||
Copyright 2023 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 v1alpha1 | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime" | ||
|
||
"sigs.k8s.io/kueue/pkg/constants" | ||
) | ||
|
||
func init() { | ||
localSchemeBuilder.Register(addDefaultingFuncs) | ||
} | ||
|
||
func addDefaultingFuncs(scheme *runtime.Scheme) error { | ||
return RegisterDefaults(scheme) | ||
} | ||
|
||
func SetDefaults_PendingWorkloadOptions(obj *PendingWorkloadOptions) { | ||
if obj.Limit == 0 { | ||
obj.Limit = constants.DefaultPendingWorkloadsLimit | ||
} | ||
} |
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,23 @@ | ||
/* | ||
Copyright 2023 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. | ||
*/ | ||
|
||
// +kubebuilder:object:generate=true | ||
// +kubebuilder:skip | ||
// +groupName=visibility.kueue.x-k8s.io | ||
// +k8s:openapi-gen=true | ||
// +k8s:conversion-gen=false | ||
|
||
package v1alpha1 |
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,53 @@ | ||
/* | ||
Copyright 2023 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 v1alpha1 contains API Schema definitions for the pending workloads kueue v1alpha1 API group | ||
// +kubebuilder:object:generate=true | ||
// +kubebuilder:skip | ||
// +groupName=visibility.kueue.x-k8s.io | ||
// +k8s:openapi-gen=true | ||
// +k8s:conversion-gen=false | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"sigs.k8s.io/controller-runtime/pkg/scheme" | ||
) | ||
|
||
var ( | ||
// GroupVersion is group version used to register these objects. | ||
GroupVersion = schema.GroupVersion{Group: "visibility.kueue.x-k8s.io", Version: "v1alpha1"} | ||
|
||
// SchemeGroupVersion is alias to GroupVersion for client-go libraries. | ||
// It is required by pkg/client/informers/externalversions/... | ||
SchemeGroupVersion = GroupVersion | ||
|
||
// SchemeBuilder is used to add go types to the GroupVersionKind scheme | ||
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} | ||
|
||
// localSchemeBuilder is used to register autogenerated conversion and defaults functions | ||
// It is required by ./zz_generated.conversion.go and ./zz_generated.defaults.go | ||
localSchemeBuilder = &SchemeBuilder.SchemeBuilder | ||
|
||
// AddToScheme adds the types in this group-version to the given scheme. | ||
AddToScheme = SchemeBuilder.AddToScheme | ||
) | ||
|
||
// Resource is required by pkg/client/listers/... | ||
func Resource(resource string) schema.GroupResource { | ||
return GroupVersion.WithResource(resource).GroupResource() | ||
} |
Oops, something went wrong.