Skip to content

Commit

Permalink
Add an imperative API to support rescheduling
Browse files Browse the repository at this point in the history
Signed-off-by: chaosi-zju <chaosi@zju.edu.cn>
  • Loading branch information
chaosi-zju committed Apr 17, 2024
1 parent fdad87e commit 2cd253b
Show file tree
Hide file tree
Showing 38 changed files with 2,984 additions and 9 deletions.
1,005 changes: 1,005 additions & 0 deletions api/openapi-spec/swagger.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,16 @@ spec:
- name
type: object
type: array
rescheduleTriggeredAt:
description: "RescheduleTriggeredAt is a timestamp representing when
the referenced resource is triggered rescheduling. Only when this
timestamp is later than timestamp in status.rescheduledAt will the
rescheduling actually execute. \n It is represented in RFC3339 form
(like '2006-01-02T15:04:05Z') and is in UTC. It is recommended to
be populated by the REST handler of command.karmada.io/Reschedule
API."
format: date-time
type: string
resource:
description: Resource represents the Kubernetes resource to be propagated.
properties:
Expand Down Expand Up @@ -1279,6 +1289,12 @@ spec:
- type
type: object
type: array
lastScheduledTime:
description: LastScheduledTime is a timestamp representing scheduler
successfully finished a scheduling. It is represented in RFC3339
form (like '2006-01-02T15:04:05Z') and is in UTC.
format: date-time
type: string
schedulerObservedGeneration:
description: SchedulerObservedGeneration is the generation(.metadata.generation)
observed by the scheduler. If SchedulerObservedGeneration is less
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,16 @@ spec:
- name
type: object
type: array
rescheduleTriggeredAt:
description: "RescheduleTriggeredAt is a timestamp representing when
the referenced resource is triggered rescheduling. Only when this
timestamp is later than timestamp in status.rescheduledAt will the
rescheduling actually execute. \n It is represented in RFC3339 form
(like '2006-01-02T15:04:05Z') and is in UTC. It is recommended to
be populated by the REST handler of command.karmada.io/Reschedule
API."
format: date-time
type: string
resource:
description: Resource represents the Kubernetes resource to be propagated.
properties:
Expand Down Expand Up @@ -1279,6 +1289,12 @@ spec:
- type
type: object
type: array
lastScheduledTime:
description: LastScheduledTime is a timestamp representing scheduler
successfully finished a scheduling. It is represented in RFC3339
form (like '2006-01-02T15:04:05Z') and is in UTC.
format: date-time
type: string
schedulerObservedGeneration:
description: SchedulerObservedGeneration is the generation(.metadata.generation)
observed by the scheduler. If SchedulerObservedGeneration is less
Expand Down
6 changes: 6 additions & 0 deletions hack/tools/swagger/generateswagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/karmada-io/karmada/hack/tools/swagger/lib"
autoscalingv1alpha1 "github.com/karmada-io/karmada/pkg/apis/autoscaling/v1alpha1"
clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
commandv1alpha1 "github.com/karmada-io/karmada/pkg/apis/command/v1alpha1"
configv1alpha1 "github.com/karmada-io/karmada/pkg/apis/config/v1alpha1"
networkingv1alpha1 "github.com/karmada-io/karmada/pkg/apis/networking/v1alpha1"
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
Expand All @@ -48,6 +49,10 @@ func main() {
clusterv1alpha1.SchemeGroupVersion.WithResource(clusterv1alpha1.ResourcePluralCluster),
clusterv1alpha1.SchemeGroupVersion.WithResource(clusterv1alpha1.ResourceSingularCluster), meta.RESTScopeRoot)

mapper.AddSpecific(commandv1alpha1.SchemeGroupVersion.WithKind(commandv1alpha1.ResourceKindReschedule),
commandv1alpha1.SchemeGroupVersion.WithResource(commandv1alpha1.ResourcePluralReschedule),
commandv1alpha1.SchemeGroupVersion.WithResource(commandv1alpha1.ResourceSingularReschedule), meta.RESTScopeRoot)

mapper.AddSpecific(configv1alpha1.SchemeGroupVersion.WithKind(configv1alpha1.ResourceKindResourceInterpreterWebhookConfiguration),
configv1alpha1.SchemeGroupVersion.WithResource(configv1alpha1.ResourcePluralResourceInterpreterWebhookConfiguration),
configv1alpha1.SchemeGroupVersion.WithResource(configv1alpha1.ResourceSingularResourceInterpreterWebhookConfiguration), meta.RESTScopeRoot)
Expand Down Expand Up @@ -129,6 +134,7 @@ func main() {
},
Resources: []lib.ResourceWithNamespaceScoped{
{GVR: clusterv1alpha1.SchemeGroupVersion.WithResource(clusterv1alpha1.ResourcePluralCluster), NamespaceScoped: clusterv1alpha1.ResourceNamespaceScopedCluster},
{GVR: commandv1alpha1.SchemeGroupVersion.WithResource(commandv1alpha1.ResourcePluralReschedule), NamespaceScoped: commandv1alpha1.ResourceNamespaceScopedReschedule},
{GVR: configv1alpha1.SchemeGroupVersion.WithResource(configv1alpha1.ResourcePluralResourceInterpreterWebhookConfiguration), NamespaceScoped: configv1alpha1.ResourceNamespaceScopedResourceInterpreterWebhookConfiguration},
{GVR: configv1alpha1.SchemeGroupVersion.WithResource(configv1alpha1.ResourcePluralResourceInterpreterCustomization), NamespaceScoped: configv1alpha1.ResourceNamespaceScopedResourceInterpreterCustomization},
{GVR: networkingv1alpha1.SchemeGroupVersion.WithResource(networkingv1alpha1.ResourcePluralMultiClusterIngress), NamespaceScoped: networkingv1alpha1.ResourceNamespaceScopedMultiClusterIngress},
Expand Down
27 changes: 24 additions & 3 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ deepcopy-gen \
--input-dirs=github.com/karmada-io/karmada/pkg/apis/cluster \
--output-package=github.com/karmada-io/karmada/pkg/apis/cluster \
--output-file-base=zz_generated.deepcopy
deepcopy-gen \
--go-header-file hack/boilerplate/boilerplate.go.txt \
--input-dirs=github.com/karmada-io/karmada/pkg/apis/command/v1alpha1 \
--output-package=github.com/karmada-io/karmada/pkg/apis/command/v1alpha1 \
--output-file-base=zz_generated.deepcopy
deepcopy-gen \
--go-header-file hack/boilerplate/boilerplate.go.txt \
--input-dirs=github.com/karmada-io/karmada/pkg/apis/command \
--output-package=github.com/karmada-io/karmada/pkg/apis/command \
--output-file-base=zz_generated.deepcopy
deepcopy-gen \
--go-header-file hack/boilerplate/boilerplate.go.txt \
--input-dirs=github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1 \
Expand Down Expand Up @@ -117,6 +127,11 @@ register-gen \
--input-dirs=github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1 \
--output-package=github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1 \
--output-file-base=zz_generated.register
register-gen \
--go-header-file hack/boilerplate/boilerplate.go.txt \
--input-dirs=github.com/karmada-io/karmada/pkg/apis/command/v1alpha1 \
--output-package=github.com/karmada-io/karmada/pkg/apis/command/v1alpha1 \
--output-file-base=zz_generated.register
register-gen \
--go-header-file hack/boilerplate/boilerplate.go.txt \
--input-dirs=github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1 \
Expand Down Expand Up @@ -174,6 +189,11 @@ conversion-gen \
--input-dirs=github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1 \
--output-package=github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1 \
--output-file-base=zz_generated.conversion
conversion-gen \
--go-header-file hack/boilerplate/boilerplate.go.txt \
--input-dirs=github.com/karmada-io/karmada/pkg/apis/command/v1alpha1 \
--output-package=github.com/karmada-io/karmada/pkg/apis/command/v1alpha1 \
--output-file-base=zz_generated.conversion
conversion-gen \
--go-header-file hack/boilerplate/boilerplate.go.txt \
--input-dirs=github.com/karmada-io/karmada/pkg/apis/search/v1alpha1 \
Expand All @@ -184,7 +204,7 @@ echo "Generating with client-gen"
client-gen \
--go-header-file hack/boilerplate/boilerplate.go.txt \
--input-base="" \
--input=github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1,github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1,github.com/karmada-io/karmada/pkg/apis/work/v1alpha1,github.com/karmada-io/karmada/pkg/apis/work/v1alpha2,github.com/karmada-io/karmada/pkg/apis/config/v1alpha1,github.com/karmada-io/karmada/pkg/apis/networking/v1alpha1,github.com/karmada-io/karmada/pkg/apis/search/v1alpha1,github.com/karmada-io/karmada/pkg/apis/autoscaling/v1alpha1,github.com/karmada-io/karmada/pkg/apis/remedy/v1alpha1 \
--input=github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1,github.com/karmada-io/karmada/pkg/apis/command/v1alpha1,github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1,github.com/karmada-io/karmada/pkg/apis/work/v1alpha1,github.com/karmada-io/karmada/pkg/apis/work/v1alpha2,github.com/karmada-io/karmada/pkg/apis/config/v1alpha1,github.com/karmada-io/karmada/pkg/apis/networking/v1alpha1,github.com/karmada-io/karmada/pkg/apis/search/v1alpha1,github.com/karmada-io/karmada/pkg/apis/autoscaling/v1alpha1,github.com/karmada-io/karmada/pkg/apis/remedy/v1alpha1 \
--output-package=github.com/karmada-io/karmada/pkg/generated/clientset \
--clientset-name=versioned
client-gen \
Expand All @@ -197,7 +217,7 @@ client-gen \
echo "Generating with lister-gen"
lister-gen \
--go-header-file hack/boilerplate/boilerplate.go.txt \
--input-dirs=github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1,github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1,github.com/karmada-io/karmada/pkg/apis/work/v1alpha1,github.com/karmada-io/karmada/pkg/apis/work/v1alpha2,github.com/karmada-io/karmada/pkg/apis/config/v1alpha1,github.com/karmada-io/karmada/pkg/apis/networking/v1alpha1,github.com/karmada-io/karmada/pkg/apis/search/v1alpha1,github.com/karmada-io/karmada/pkg/apis/autoscaling/v1alpha1,github.com/karmada-io/karmada/pkg/apis/remedy/v1alpha1 \
--input-dirs=github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1,github.com/karmada-io/karmada/pkg/apis/command/v1alpha1,github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1,github.com/karmada-io/karmada/pkg/apis/work/v1alpha1,github.com/karmada-io/karmada/pkg/apis/work/v1alpha2,github.com/karmada-io/karmada/pkg/apis/config/v1alpha1,github.com/karmada-io/karmada/pkg/apis/networking/v1alpha1,github.com/karmada-io/karmada/pkg/apis/search/v1alpha1,github.com/karmada-io/karmada/pkg/apis/autoscaling/v1alpha1,github.com/karmada-io/karmada/pkg/apis/remedy/v1alpha1 \
--output-package=github.com/karmada-io/karmada/pkg/generated/listers
lister-gen \
--go-header-file hack/boilerplate/boilerplate.go.txt \
Expand All @@ -207,7 +227,7 @@ lister-gen \
echo "Generating with informer-gen"
informer-gen \
--go-header-file hack/boilerplate/boilerplate.go.txt \
--input-dirs=github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1,github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1,github.com/karmada-io/karmada/pkg/apis/work/v1alpha1,github.com/karmada-io/karmada/pkg/apis/work/v1alpha2,github.com/karmada-io/karmada/pkg/apis/config/v1alpha1,github.com/karmada-io/karmada/pkg/apis/networking/v1alpha1,github.com/karmada-io/karmada/pkg/apis/search/v1alpha1,github.com/karmada-io/karmada/pkg/apis/autoscaling/v1alpha1,github.com/karmada-io/karmada/pkg/apis/remedy/v1alpha1 \
--input-dirs=github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1,github.com/karmada-io/karmada/pkg/apis/command/v1alpha1,github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1,github.com/karmada-io/karmada/pkg/apis/work/v1alpha1,github.com/karmada-io/karmada/pkg/apis/work/v1alpha2,github.com/karmada-io/karmada/pkg/apis/config/v1alpha1,github.com/karmada-io/karmada/pkg/apis/networking/v1alpha1,github.com/karmada-io/karmada/pkg/apis/search/v1alpha1,github.com/karmada-io/karmada/pkg/apis/autoscaling/v1alpha1,github.com/karmada-io/karmada/pkg/apis/remedy/v1alpha1 \
--versioned-clientset-package=github.com/karmada-io/karmada/pkg/generated/clientset/versioned \
--listers-package=github.com/karmada-io/karmada/pkg/generated/listers \
--output-package=github.com/karmada-io/karmada/pkg/generated/informers
Expand All @@ -222,6 +242,7 @@ echo "Generating with openapi-gen"
openapi-gen \
--go-header-file hack/boilerplate/boilerplate.go.txt \
--input-dirs "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1" \
--input-dirs "github.com/karmada-io/karmada/pkg/apis/command/v1alpha1" \
--input-dirs "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1" \
--input-dirs "github.com/karmada-io/karmada/pkg/apis/work/v1alpha1" \
--input-dirs "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2" \
Expand Down
20 changes: 20 additions & 0 deletions pkg/apis/command/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright 2024 The Karmada 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 command is the internal version of the API.
// +k8s:deepcopy-gen=package
// +groupName=command.karmada.io
package command
54 changes: 54 additions & 0 deletions pkg/apis/command/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Copyright 2024 The Karmada 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 command

import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)

// GroupName specifies the group name used to register the objects.
const GroupName = "command.karmada.io"

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

// Kind takes an unqualified kind and returns a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

var (
// SchemeBuilder is the scheme builder with scheme init functions to run for this API package
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
// AddToScheme is a common registration function for mapping packaged scoped group & version keys to a scheme
AddToScheme = SchemeBuilder.AddToScheme
)

// Adds the list of known types to Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Reschedule{},
&RescheduleList{},
)
return nil
}
104 changes: 104 additions & 0 deletions pkg/apis/command/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
Copyright 2024 The Karmada 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 command

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

const (
// ResourceKindReschedule is kind name of Reschedule.
ResourceKindReschedule = "Reschedule"
// ResourceSingularReschedule is singular name of Reschedule.
ResourceSingularReschedule = "reschedule"
// ResourcePluralReschedule is plural name of Reschedule.
ResourcePluralReschedule = "reschedules"
// ResourceNamespaceScopedReschedule indicates if Reschedule is NamespaceScoped.
ResourceNamespaceScopedReschedule = false
)

//revive:disable:exported

// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// Reschedule represents the desire state and status of a task which can enforces a rescheduling.
//
// Notes: make sure the clocks of aggregated-apiserver and scheduler are synchronized when using this API.
type Reschedule struct {
metav1.TypeMeta
metav1.ObjectMeta

// Spec represents the specification of the desired behavior of Reschedule.
// +required
Spec RescheduleSpec
}

// RescheduleSpec represents the specification of the desired behavior of Reschedule.
type RescheduleSpec struct {
// TargetRefPolicy used to select batch of resources managed by certain policies.
// +optional
TargetRefPolicy []PolicySelector

// TargetRefResource used to select resources.
// +optional
TargetRefResource []ResourceSelector
}

// PolicySelector the resources bound policy will be selected.
type PolicySelector struct {
// Name of the target policy.
// +required
Name string

// Namespace of the target policy.
// Default is empty, which means it is a cluster propagation policy.
// +optional
Namespace string
}

// ResourceSelector the resource will be selected.
type ResourceSelector struct {
// APIVersion represents the API version of the target resource.
// +required
APIVersion string

// Kind represents the Kind of the target resource.
// +required
Kind string

// Name of the target resource.
// +required
Name string

// Namespace of the target resource.
// Default is empty, which means it is a non-namespacescoped resource.
// +optional
Namespace string
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// RescheduleList contains a list of Reschedule
type RescheduleList struct {
metav1.TypeMeta
metav1.ListMeta

// Items holds a list of Reschedule.
Items []Reschedule
}

//revive:enable:exported
22 changes: 22 additions & 0 deletions pkg/apis/command/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Copyright 2024 The Karmada 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 is the v1alpha1 version of the API.
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=package,register
// +k8s:conversion-gen=github.com/karmada-io/karmada/pkg/apis/command
// +groupName=command.karmada.io
package v1alpha1
Loading

0 comments on commit 2cd253b

Please sign in to comment.