Skip to content
10 changes: 0 additions & 10 deletions apis/placement/v1/clusterresourceplacement_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
)

const (
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Ryan! We are removing these as the values in the v1 pkg are not used, right? Do we want to move onto v1 one day?

Copy link
Contributor

@ryanzhang-oss ryanzhang-oss May 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, I think we can keep it in v1beta1 forever as v1 always follows v1beta1

// ClusterResourcePlacementCleanupFinalizer is a finalizer added by the CRP controller to all CRPs, to make sure
// that the CRP controller can react to CRP deletions if necessary.
ClusterResourcePlacementCleanupFinalizer = fleetPrefix + "crp-cleanup"

// SchedulerCRPCleanupFinalizer is a finalizer added by the scheduler to CRPs, to make sure
// that all bindings derived from a CRP can be cleaned up after the CRP is deleted.
SchedulerCRPCleanupFinalizer = fleetPrefix + "scheduler-cleanup"
)

// +genclient
// +genclient:nonNamespaced
// +kubebuilder:object:root=true
Expand Down
74 changes: 0 additions & 74 deletions apis/placement/v1/commons.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,80 +16,6 @@ limitations under the License.

package v1

const (
ClusterResourcePlacementKind = "ClusterResourcePlacement"
ClusterResourcePlacementResource = "clusterresourceplacements"
ClusterResourceBindingKind = "ClusterResourceBinding"
ClusterResourceSnapshotKind = "ClusterResourceSnapshot"
ClusterSchedulingPolicySnapshotKind = "ClusterSchedulingPolicySnapshot"
WorkKind = "Work"
AppliedWorkKind = "AppliedWork"
)

const (
// Unprefixed labels/annotations are reserved for end-users
// we will add a kubernetes-fleet.io to designate these labels/annotations as official fleet labels/annotations.
// See https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#label-selector-and-annotation-conventions
fleetPrefix = "kubernetes-fleet.io/"

// MemberClusterFinalizer is used to make sure that we handle gc of all the member cluster resources on the hub cluster.
MemberClusterFinalizer = fleetPrefix + "membercluster-finalizer"

// WorkFinalizer is used by the work generator to make sure that the binding is not deleted until the work objects
// it generates are all deleted, or used by the work controller to make sure the work has been deleted in the member
// cluster.
WorkFinalizer = fleetPrefix + "work-cleanup"

// CRPTrackingLabel is the label that points to the cluster resource policy that creates a resource binding.
CRPTrackingLabel = fleetPrefix + "parent-CRP"

// IsLatestSnapshotLabel tells if the snapshot is the latest one.
IsLatestSnapshotLabel = fleetPrefix + "is-latest-snapshot"

// FleetResourceLabelKey is that label that indicates the resource is a fleet resource.
FleetResourceLabelKey = fleetPrefix + "is-fleet-resource"

// FirstWorkNameFmt is the format of the name of the work generated with first resource snapshot .
// The name of the first work is {crpName}-work.
FirstWorkNameFmt = "%s-work"

// WorkNameWithSubindexFmt is the format of the name of a work generated with resource snapshot with subindex.
// The name of the first work is {crpName}-{subindex}.
WorkNameWithSubindexFmt = "%s-%d"

// WorkNameWithConfigEnvelopeFmt is the format of the name of a work generated with config envelop.
// The format is {workPrefix}-configMap-uuid
WorkNameWithConfigEnvelopeFmt = "%s-configmap-%s"

// ParentResourceSnapshotIndexLabel is the label applied to work that contains the index of the resource snapshot that generates the work.
ParentResourceSnapshotIndexLabel = fleetPrefix + "parent-resource-snapshot-index"

// ParentBindingLabel is the label applied to work that contains the name of the binding that generates the work.
ParentBindingLabel = fleetPrefix + "parent-resource-binding"

// CRPGenerationAnnotation is the annotation that indicates the generation of the CRP from
// which an object is derived or last updated.
CRPGenerationAnnotation = fleetPrefix + "CRP-generation"

// EnvelopeConfigMapAnnotation is the annotation that indicates the configmap is an envelope configmap that contains resources
// we need to apply to the member cluster instead of the configMap itself.
EnvelopeConfigMapAnnotation = fleetPrefix + "envelope-configmap"

// EnvelopeTypeLabel is the label that marks the work object as generated from an envelope object.
// The value of the annotation is the type of the envelope object.
EnvelopeTypeLabel = fleetPrefix + "envelope-work"

// EnvelopeNamespaceLabel is the label that contains the namespace of the envelope object that the work is generated from.
EnvelopeNamespaceLabel = fleetPrefix + "envelope-namespace"

// EnvelopeNameLabel is the label that contains the name of the envelope object that the work is generated from.
EnvelopeNameLabel = fleetPrefix + "envelope-name"

// PreviousBindingStateAnnotation is the annotation that records the previous state of a binding.
// This is used to remember if an "unscheduled" binding was moved from a "bound" state or a "scheduled" state.
PreviousBindingStateAnnotation = fleetPrefix + "previous-binding-state"
)

// NamespacedName comprises a resource name, with a mandatory namespace.
type NamespacedName struct {
// Name is the name of the namespaced scope resource.
Expand Down
11 changes: 0 additions & 11 deletions apis/placement/v1/policysnapshot_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
// PolicyIndexLabel is the label that indicate the policy snapshot index of a cluster policy.
PolicyIndexLabel = fleetPrefix + "policy-index"

// PolicySnapshotNameFmt is clusterPolicySnapshot name format: {CRPName}-{PolicySnapshotIndex}.
PolicySnapshotNameFmt = "%s-%d"

// NumberOfClustersAnnotation is the annotation that indicates how many clusters should be selected for selectN placement type.
NumberOfClustersAnnotation = fleetPrefix + "number-of-clusters"
)

// +genclient
// +genclient:nonNamespaced
// +kubebuilder:object:root=true
Expand Down
24 changes: 0 additions & 24 deletions apis/placement/v1/resourcesnapshot_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
)

const (
// ResourceIndexLabel is the label that indicate the resource snapshot index of a cluster resource snapshot.
ResourceIndexLabel = fleetPrefix + "resource-index"

// ResourceGroupHashAnnotation is the annotation that contains the value of the sha-256 hash
// value of all the snapshots belong to the same snapshot index.
ResourceGroupHashAnnotation = fleetPrefix + "resource-hash"

// NumberOfEnvelopedObjectsAnnotation is the annotation that contains the number of the enveloped objects in the resource snapshot group.
NumberOfEnvelopedObjectsAnnotation = fleetPrefix + "number-of-enveloped-object"

// NumberOfResourceSnapshotsAnnotation is the annotation that contains the total number of resource snapshots.
NumberOfResourceSnapshotsAnnotation = fleetPrefix + "number-of-resource-snapshots"

// SubindexOfResourceSnapshotAnnotation is the annotation to store the subindex of resource snapshot in the group.
SubindexOfResourceSnapshotAnnotation = fleetPrefix + "subindex-of-resource-snapshot"

// ResourceSnapshotNameFmt is resourcePolicySnapshot name format: {CRPName}-{resourceIndex}-snapshot.
ResourceSnapshotNameFmt = "%s-%d-snapshot"

// ResourceSnapshotNameWithSubindexFmt is resourcePolicySnapshot name with subindex format: {CRPName}-{resourceIndex}-{subindex}.
ResourceSnapshotNameWithSubindexFmt = "%s-%d-%d"
)

// +genclient
// +genclient:nonNamespaced
// +kubebuilder:object:root=true
Expand Down
15 changes: 0 additions & 15 deletions apis/placement/v1/work_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
)

// The following definitions are originally declared in the controllers/workv1alpha1/manager.go file.
const (
// ManifestHashAnnotation is the annotation that indicates whether the spec of the object has been changed or not.
ManifestHashAnnotation = fleetPrefix + "spec-hash"

// LastAppliedConfigAnnotation is to record the last applied configuration on the object.
LastAppliedConfigAnnotation = fleetPrefix + "last-applied-configuration"

// WorkConditionTypeApplied represents workload in Work is applied successfully on the spoke cluster.
WorkConditionTypeApplied = "Applied"

// WorkConditionTypeAvailable represents workload in Work is available on the spoke cluster.
WorkConditionTypeAvailable = "Available"
)

// This api is copied from https://github.com/kubernetes-sigs/work-api/blob/master/pkg/apis/v1alpha1/work_types.go.
// Renamed original "ResourceIdentifier" so that it won't conflict with ResourceIdentifier defined in the clusterresourceplacement_types.go.

Expand Down
11 changes: 10 additions & 1 deletion apis/placement/v1beta1/clusterresourceplacement_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,8 +890,10 @@ type EnvelopeIdentifier struct {
// +kubebuilder:validation:Optional
Namespace string `json:"namespace,omitempty"`

// TO-DO (chenyu1): drop the enum value ConfigMap after the new envelope forms become fully available.

// Type of the envelope object.
// +kubebuilder:validation:Enum=ConfigMap
// +kubebuilder:validation:Enum=ConfigMap;ClusterResourceEnvelope;ResourceEnvelope
// +kubebuilder:default=ConfigMap
// +kubebuilder:validation:Optional
Type EnvelopeType `json:"type"`
Expand All @@ -903,7 +905,14 @@ type EnvelopeType string

const (
// ConfigMapEnvelopeType means the envelope object is of type `ConfigMap`.
// TO-DO (chenyu1): drop this type after the configMap-based envelopes become obsolete.
ConfigMapEnvelopeType EnvelopeType = "ConfigMap"

// ClusterResourceEnvelopeType is the envelope type that represents the ClusterResourceEnvelope custom resource.
ClusterResourceEnvelopeType EnvelopeType = "ClusterResourceEnvelope"

// ResourceEnvelopeType is the envelope type that represents the ResourceEnvelope custom resource.
ResourceEnvelopeType EnvelopeType = "ResourceEnvelope"
)

// ResourcePlacementStatus represents the placement status of selected resources for one target cluster.
Expand Down
8 changes: 8 additions & 0 deletions apis/placement/v1beta1/commons.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const (
ClusterResourcePlacementEvictionKind = "ClusterResourcePlacementEviction"
// ClusterResourcePlacementDisruptionBudgetKind is the kind of the ClusterResourcePlacementDisruptionBudget.
ClusterResourcePlacementDisruptionBudgetKind = "ClusterResourcePlacementDisruptionBudget"
// ResourceEnvelopeKind is the kind of the ResourceEnvelope.
ResourceEnvelopeKind = "ResourceEnvelope"
// ClusterResourceEnvelopeKind is the kind of the ClusterResourceEnvelope.
ClusterResourceEnvelopeKind = "ClusterResourceEnvelope"
)

const (
Expand Down Expand Up @@ -78,6 +82,10 @@ const (
// The format is {workPrefix}-configMap-uuid.
WorkNameWithConfigEnvelopeFmt = "%s-configmap-%s"

// WorkNameWithEnvelopeCRFmt is the format of the name of a work generated with an envelope CR.
// The format is [WORK-PREFIX]-envelope-[UUID].
WorkNameWithEnvelopeCRFmt = "%s-envelope-%s"

// ParentClusterResourceOverrideSnapshotHashAnnotation is the annotation to work that contains the hash of the parent cluster resource override snapshot list.
ParentClusterResourceOverrideSnapshotHashAnnotation = fleetPrefix + "parent-cluster-resource-override-snapshot-hash"

Expand Down
85 changes: 85 additions & 0 deletions apis/placement/v1beta1/envelope_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/klog/v2"
)

// +genclient
Expand All @@ -43,6 +44,17 @@
Data map[string]runtime.RawExtension `json:"data"`
}

// ClusterResourceEnvelopeList contains a list of ClusterResourceEnvelope objects.
// +kubebuilder:resource:scope=Cluster
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type ClusterResourceEnvelopeList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`

// Items is the list of ClusterResourceEnvelope objects.
Items []ClusterResourceEnvelope `json:"items"`
}

// +genclient
// +genclient:Namespaced
// +kubebuilder:object:root=true
Expand All @@ -64,3 +76,76 @@
// +kubebuilder:validation:MaxProperties=50
Data map[string]runtime.RawExtension `json:"data"`
}

// ResourceEnvelopeList contains a list of ResourceEnvelope objects.
// +kubebuilder:resource:scope=Namespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type ResourceEnvelopeList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`

// Items is the list of ResourceEnvelope objects.
Items []ResourceEnvelope `json:"items"`
}

func init() {
SchemeBuilder.Register(
&ClusterResourceEnvelope{},
&ClusterResourceEnvelopeList{},
&ResourceEnvelope{},
&ResourceEnvelopeList{})
}

// +kubebuilder:object:generate=false
// EnvelopeReader is an interface that allows retrieval of common information across all envelope CRs.
type EnvelopeReader interface {
// GetData returns the raw data in the envelope.
GetData() map[string]runtime.RawExtension

// GetEnvelopeObjRef returns a klog object reference to the envelope.
GetEnvelopeObjRef() klog.ObjectRef

// GetNamespace returns the namespace of the envelope.
GetNamespace() string

// GetName returns the name of the envelope.
GetName() string

// GetEnvelopeType returns the type of the envelope.
GetEnvelopeType() string
}

// Ensure that both ClusterResourceEnvelope and ResourceEnvelope implement the
// EnvelopeReader interface at compile time.
var (
_ EnvelopeReader = &ClusterResourceEnvelope{}
_ EnvelopeReader = &ResourceEnvelope{}
)

// Implements the EnvelopeReader interface for ClusterResourceEnvelope.

func (e *ClusterResourceEnvelope) GetData() map[string]runtime.RawExtension {
return e.Data

Check warning on line 128 in apis/placement/v1beta1/envelope_types.go

View check run for this annotation

Codecov / codecov/patch

apis/placement/v1beta1/envelope_types.go#L127-L128

Added lines #L127 - L128 were not covered by tests
}

func (e *ClusterResourceEnvelope) GetEnvelopeObjRef() klog.ObjectRef {
return klog.KObj(e)

Check warning on line 132 in apis/placement/v1beta1/envelope_types.go

View check run for this annotation

Codecov / codecov/patch

apis/placement/v1beta1/envelope_types.go#L131-L132

Added lines #L131 - L132 were not covered by tests
}

func (e *ClusterResourceEnvelope) GetEnvelopeType() string {
return string(ClusterResourceEnvelopeType)

Check warning on line 136 in apis/placement/v1beta1/envelope_types.go

View check run for this annotation

Codecov / codecov/patch

apis/placement/v1beta1/envelope_types.go#L135-L136

Added lines #L135 - L136 were not covered by tests
}

// Implements the EnvelopeReader interface for ResourceEnvelope.

func (e *ResourceEnvelope) GetData() map[string]runtime.RawExtension {
return e.Data

Check warning on line 142 in apis/placement/v1beta1/envelope_types.go

View check run for this annotation

Codecov / codecov/patch

apis/placement/v1beta1/envelope_types.go#L141-L142

Added lines #L141 - L142 were not covered by tests
}

func (e *ResourceEnvelope) GetEnvelopeObjRef() klog.ObjectRef {
return klog.KObj(e)

Check warning on line 146 in apis/placement/v1beta1/envelope_types.go

View check run for this annotation

Codecov / codecov/patch

apis/placement/v1beta1/envelope_types.go#L145-L146

Added lines #L145 - L146 were not covered by tests
}

func (e *ResourceEnvelope) GetEnvelopeType() string {
return string(ResourceEnvelopeType)

Check warning on line 150 in apis/placement/v1beta1/envelope_types.go

View check run for this annotation

Codecov / codecov/patch

apis/placement/v1beta1/envelope_types.go#L149-L150

Added lines #L149 - L150 were not covered by tests
}
64 changes: 64 additions & 0 deletions apis/placement/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading