Skip to content

Commit

Permalink
Add ClusterQueue visibility on-demand (#1251)
Browse files Browse the repository at this point in the history
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
PBundyra committed Nov 23, 2023
1 parent 4d9ad0c commit ec340f2
Show file tree
Hide file tree
Showing 67 changed files with 6,142 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
rbac:roleName=manager-role output:rbac:artifacts:config=config/components/rbac\
crd:generateEmbeddedObjectMeta=true output:crd:artifacts:config=config/components/crd/bases\
webhook output:webhook:artifacts:config=config/components/webhook\
paths="./..."
paths="./apis/..."

.PHONY: update-helm
update-helm: manifests yq
./hack/update-helm.sh

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations and client-go libraries.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./apis/..."
./hack/update-codegen.sh $(GO_CMD)

.PHONY: fmt
Expand Down
91 changes: 91 additions & 0 deletions apis/visibility/v1alpha1/conversion_test.go
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))
}
})
}
}
37 changes: 37 additions & 0 deletions apis/visibility/v1alpha1/defaults.go
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
}
}
23 changes: 23 additions & 0 deletions apis/visibility/v1alpha1/doc.go
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
53 changes: 53 additions & 0 deletions apis/visibility/v1alpha1/groupversion_info.go
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()
}
Loading

0 comments on commit ec340f2

Please sign in to comment.