Skip to content

Commit 491abff

Browse files
michaelawyuRyan Zhang
andauthored
feat: enable new CR-based envelope experience (#38)
Signed-off-by: michaelawyu <[email protected]> Signed-off-by: Ryan Zhang <[email protected]> Co-authored-by: Ryan Zhang <[email protected]>
1 parent 0000172 commit 491abff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2137
-797
lines changed

apis/placement/v1/clusterresourceplacement_types.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@ import (
2323
"k8s.io/apimachinery/pkg/util/intstr"
2424
)
2525

26-
const (
27-
// ClusterResourcePlacementCleanupFinalizer is a finalizer added by the CRP controller to all CRPs, to make sure
28-
// that the CRP controller can react to CRP deletions if necessary.
29-
ClusterResourcePlacementCleanupFinalizer = fleetPrefix + "crp-cleanup"
30-
31-
// SchedulerCRPCleanupFinalizer is a finalizer added by the scheduler to CRPs, to make sure
32-
// that all bindings derived from a CRP can be cleaned up after the CRP is deleted.
33-
SchedulerCRPCleanupFinalizer = fleetPrefix + "scheduler-cleanup"
34-
)
35-
3626
// +genclient
3727
// +genclient:nonNamespaced
3828
// +kubebuilder:object:root=true

apis/placement/v1/commons.go

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -16,80 +16,6 @@ limitations under the License.
1616

1717
package v1
1818

19-
const (
20-
ClusterResourcePlacementKind = "ClusterResourcePlacement"
21-
ClusterResourcePlacementResource = "clusterresourceplacements"
22-
ClusterResourceBindingKind = "ClusterResourceBinding"
23-
ClusterResourceSnapshotKind = "ClusterResourceSnapshot"
24-
ClusterSchedulingPolicySnapshotKind = "ClusterSchedulingPolicySnapshot"
25-
WorkKind = "Work"
26-
AppliedWorkKind = "AppliedWork"
27-
)
28-
29-
const (
30-
// Unprefixed labels/annotations are reserved for end-users
31-
// we will add a kubernetes-fleet.io to designate these labels/annotations as official fleet labels/annotations.
32-
// See https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#label-selector-and-annotation-conventions
33-
fleetPrefix = "kubernetes-fleet.io/"
34-
35-
// MemberClusterFinalizer is used to make sure that we handle gc of all the member cluster resources on the hub cluster.
36-
MemberClusterFinalizer = fleetPrefix + "membercluster-finalizer"
37-
38-
// WorkFinalizer is used by the work generator to make sure that the binding is not deleted until the work objects
39-
// it generates are all deleted, or used by the work controller to make sure the work has been deleted in the member
40-
// cluster.
41-
WorkFinalizer = fleetPrefix + "work-cleanup"
42-
43-
// CRPTrackingLabel is the label that points to the cluster resource policy that creates a resource binding.
44-
CRPTrackingLabel = fleetPrefix + "parent-CRP"
45-
46-
// IsLatestSnapshotLabel tells if the snapshot is the latest one.
47-
IsLatestSnapshotLabel = fleetPrefix + "is-latest-snapshot"
48-
49-
// FleetResourceLabelKey is that label that indicates the resource is a fleet resource.
50-
FleetResourceLabelKey = fleetPrefix + "is-fleet-resource"
51-
52-
// FirstWorkNameFmt is the format of the name of the work generated with first resource snapshot .
53-
// The name of the first work is {crpName}-work.
54-
FirstWorkNameFmt = "%s-work"
55-
56-
// WorkNameWithSubindexFmt is the format of the name of a work generated with resource snapshot with subindex.
57-
// The name of the first work is {crpName}-{subindex}.
58-
WorkNameWithSubindexFmt = "%s-%d"
59-
60-
// WorkNameWithConfigEnvelopeFmt is the format of the name of a work generated with config envelop.
61-
// The format is {workPrefix}-configMap-uuid
62-
WorkNameWithConfigEnvelopeFmt = "%s-configmap-%s"
63-
64-
// ParentResourceSnapshotIndexLabel is the label applied to work that contains the index of the resource snapshot that generates the work.
65-
ParentResourceSnapshotIndexLabel = fleetPrefix + "parent-resource-snapshot-index"
66-
67-
// ParentBindingLabel is the label applied to work that contains the name of the binding that generates the work.
68-
ParentBindingLabel = fleetPrefix + "parent-resource-binding"
69-
70-
// CRPGenerationAnnotation is the annotation that indicates the generation of the CRP from
71-
// which an object is derived or last updated.
72-
CRPGenerationAnnotation = fleetPrefix + "CRP-generation"
73-
74-
// EnvelopeConfigMapAnnotation is the annotation that indicates the configmap is an envelope configmap that contains resources
75-
// we need to apply to the member cluster instead of the configMap itself.
76-
EnvelopeConfigMapAnnotation = fleetPrefix + "envelope-configmap"
77-
78-
// EnvelopeTypeLabel is the label that marks the work object as generated from an envelope object.
79-
// The value of the annotation is the type of the envelope object.
80-
EnvelopeTypeLabel = fleetPrefix + "envelope-work"
81-
82-
// EnvelopeNamespaceLabel is the label that contains the namespace of the envelope object that the work is generated from.
83-
EnvelopeNamespaceLabel = fleetPrefix + "envelope-namespace"
84-
85-
// EnvelopeNameLabel is the label that contains the name of the envelope object that the work is generated from.
86-
EnvelopeNameLabel = fleetPrefix + "envelope-name"
87-
88-
// PreviousBindingStateAnnotation is the annotation that records the previous state of a binding.
89-
// This is used to remember if an "unscheduled" binding was moved from a "bound" state or a "scheduled" state.
90-
PreviousBindingStateAnnotation = fleetPrefix + "previous-binding-state"
91-
)
92-
9319
// NamespacedName comprises a resource name, with a mandatory namespace.
9420
type NamespacedName struct {
9521
// Name is the name of the namespaced scope resource.

apis/placement/v1/policysnapshot_types.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,6 @@ import (
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222
)
2323

24-
const (
25-
// PolicyIndexLabel is the label that indicate the policy snapshot index of a cluster policy.
26-
PolicyIndexLabel = fleetPrefix + "policy-index"
27-
28-
// PolicySnapshotNameFmt is clusterPolicySnapshot name format: {CRPName}-{PolicySnapshotIndex}.
29-
PolicySnapshotNameFmt = "%s-%d"
30-
31-
// NumberOfClustersAnnotation is the annotation that indicates how many clusters should be selected for selectN placement type.
32-
NumberOfClustersAnnotation = fleetPrefix + "number-of-clusters"
33-
)
34-
3524
// +genclient
3625
// +genclient:nonNamespaced
3726
// +kubebuilder:object:root=true

apis/placement/v1/resourcesnapshot_types.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,6 @@ import (
2222
"k8s.io/apimachinery/pkg/runtime"
2323
)
2424

25-
const (
26-
// ResourceIndexLabel is the label that indicate the resource snapshot index of a cluster resource snapshot.
27-
ResourceIndexLabel = fleetPrefix + "resource-index"
28-
29-
// ResourceGroupHashAnnotation is the annotation that contains the value of the sha-256 hash
30-
// value of all the snapshots belong to the same snapshot index.
31-
ResourceGroupHashAnnotation = fleetPrefix + "resource-hash"
32-
33-
// NumberOfEnvelopedObjectsAnnotation is the annotation that contains the number of the enveloped objects in the resource snapshot group.
34-
NumberOfEnvelopedObjectsAnnotation = fleetPrefix + "number-of-enveloped-object"
35-
36-
// NumberOfResourceSnapshotsAnnotation is the annotation that contains the total number of resource snapshots.
37-
NumberOfResourceSnapshotsAnnotation = fleetPrefix + "number-of-resource-snapshots"
38-
39-
// SubindexOfResourceSnapshotAnnotation is the annotation to store the subindex of resource snapshot in the group.
40-
SubindexOfResourceSnapshotAnnotation = fleetPrefix + "subindex-of-resource-snapshot"
41-
42-
// ResourceSnapshotNameFmt is resourcePolicySnapshot name format: {CRPName}-{resourceIndex}-snapshot.
43-
ResourceSnapshotNameFmt = "%s-%d-snapshot"
44-
45-
// ResourceSnapshotNameWithSubindexFmt is resourcePolicySnapshot name with subindex format: {CRPName}-{resourceIndex}-{subindex}.
46-
ResourceSnapshotNameWithSubindexFmt = "%s-%d-%d"
47-
)
48-
4925
// +genclient
5026
// +genclient:nonNamespaced
5127
// +kubebuilder:object:root=true

apis/placement/v1/work_types.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,6 @@ import (
3737
"k8s.io/apimachinery/pkg/runtime"
3838
)
3939

40-
// The following definitions are originally declared in the controllers/workv1alpha1/manager.go file.
41-
const (
42-
// ManifestHashAnnotation is the annotation that indicates whether the spec of the object has been changed or not.
43-
ManifestHashAnnotation = fleetPrefix + "spec-hash"
44-
45-
// LastAppliedConfigAnnotation is to record the last applied configuration on the object.
46-
LastAppliedConfigAnnotation = fleetPrefix + "last-applied-configuration"
47-
48-
// WorkConditionTypeApplied represents workload in Work is applied successfully on the spoke cluster.
49-
WorkConditionTypeApplied = "Applied"
50-
51-
// WorkConditionTypeAvailable represents workload in Work is available on the spoke cluster.
52-
WorkConditionTypeAvailable = "Available"
53-
)
54-
5540
// This api is copied from https://github.com/kubernetes-sigs/work-api/blob/master/pkg/apis/v1alpha1/work_types.go.
5641
// Renamed original "ResourceIdentifier" so that it won't conflict with ResourceIdentifier defined in the clusterresourceplacement_types.go.
5742

apis/placement/v1beta1/clusterresourceplacement_types.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,8 +890,10 @@ type EnvelopeIdentifier struct {
890890
// +kubebuilder:validation:Optional
891891
Namespace string `json:"namespace,omitempty"`
892892

893+
// TO-DO (chenyu1): drop the enum value ConfigMap after the new envelope forms become fully available.
894+
893895
// Type of the envelope object.
894-
// +kubebuilder:validation:Enum=ConfigMap
896+
// +kubebuilder:validation:Enum=ConfigMap;ClusterResourceEnvelope;ResourceEnvelope
895897
// +kubebuilder:default=ConfigMap
896898
// +kubebuilder:validation:Optional
897899
Type EnvelopeType `json:"type"`
@@ -903,7 +905,14 @@ type EnvelopeType string
903905

904906
const (
905907
// ConfigMapEnvelopeType means the envelope object is of type `ConfigMap`.
908+
// TO-DO (chenyu1): drop this type after the configMap-based envelopes become obsolete.
906909
ConfigMapEnvelopeType EnvelopeType = "ConfigMap"
910+
911+
// ClusterResourceEnvelopeType is the envelope type that represents the ClusterResourceEnvelope custom resource.
912+
ClusterResourceEnvelopeType EnvelopeType = "ClusterResourceEnvelope"
913+
914+
// ResourceEnvelopeType is the envelope type that represents the ResourceEnvelope custom resource.
915+
ResourceEnvelopeType EnvelopeType = "ResourceEnvelope"
907916
)
908917

909918
// ResourcePlacementStatus represents the placement status of selected resources for one target cluster.

apis/placement/v1beta1/commons.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ const (
4141
ClusterResourcePlacementEvictionKind = "ClusterResourcePlacementEviction"
4242
// ClusterResourcePlacementDisruptionBudgetKind is the kind of the ClusterResourcePlacementDisruptionBudget.
4343
ClusterResourcePlacementDisruptionBudgetKind = "ClusterResourcePlacementDisruptionBudget"
44+
// ResourceEnvelopeKind is the kind of the ResourceEnvelope.
45+
ResourceEnvelopeKind = "ResourceEnvelope"
46+
// ClusterResourceEnvelopeKind is the kind of the ClusterResourceEnvelope.
47+
ClusterResourceEnvelopeKind = "ClusterResourceEnvelope"
4448
)
4549

4650
const (
@@ -78,6 +82,10 @@ const (
7882
// The format is {workPrefix}-configMap-uuid.
7983
WorkNameWithConfigEnvelopeFmt = "%s-configmap-%s"
8084

85+
// WorkNameWithEnvelopeCRFmt is the format of the name of a work generated with an envelope CR.
86+
// The format is [WORK-PREFIX]-envelope-[UUID].
87+
WorkNameWithEnvelopeCRFmt = "%s-envelope-%s"
88+
8189
// ParentClusterResourceOverrideSnapshotHashAnnotation is the annotation to work that contains the hash of the parent cluster resource override snapshot list.
8290
ParentClusterResourceOverrideSnapshotHashAnnotation = fleetPrefix + "parent-cluster-resource-override-snapshot-hash"
8391

apis/placement/v1beta1/envelope_types.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1beta1
1919
import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121
"k8s.io/apimachinery/pkg/runtime"
22+
"k8s.io/klog/v2"
2223
)
2324

2425
// +genclient
@@ -43,6 +44,17 @@ type ClusterResourceEnvelope struct {
4344
Data map[string]runtime.RawExtension `json:"data"`
4445
}
4546

47+
// ClusterResourceEnvelopeList contains a list of ClusterResourceEnvelope objects.
48+
// +kubebuilder:resource:scope=Cluster
49+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
50+
type ClusterResourceEnvelopeList struct {
51+
metav1.TypeMeta `json:",inline"`
52+
metav1.ListMeta `json:"metadata,omitempty"`
53+
54+
// Items is the list of ClusterResourceEnvelope objects.
55+
Items []ClusterResourceEnvelope `json:"items"`
56+
}
57+
4658
// +genclient
4759
// +genclient:Namespaced
4860
// +kubebuilder:object:root=true
@@ -64,3 +76,76 @@ type ResourceEnvelope struct {
6476
// +kubebuilder:validation:MaxProperties=50
6577
Data map[string]runtime.RawExtension `json:"data"`
6678
}
79+
80+
// ResourceEnvelopeList contains a list of ResourceEnvelope objects.
81+
// +kubebuilder:resource:scope=Namespaced
82+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
83+
type ResourceEnvelopeList struct {
84+
metav1.TypeMeta `json:",inline"`
85+
metav1.ListMeta `json:"metadata,omitempty"`
86+
87+
// Items is the list of ResourceEnvelope objects.
88+
Items []ResourceEnvelope `json:"items"`
89+
}
90+
91+
func init() {
92+
SchemeBuilder.Register(
93+
&ClusterResourceEnvelope{},
94+
&ClusterResourceEnvelopeList{},
95+
&ResourceEnvelope{},
96+
&ResourceEnvelopeList{})
97+
}
98+
99+
// +kubebuilder:object:generate=false
100+
// EnvelopeReader is an interface that allows retrieval of common information across all envelope CRs.
101+
type EnvelopeReader interface {
102+
// GetData returns the raw data in the envelope.
103+
GetData() map[string]runtime.RawExtension
104+
105+
// GetEnvelopeObjRef returns a klog object reference to the envelope.
106+
GetEnvelopeObjRef() klog.ObjectRef
107+
108+
// GetNamespace returns the namespace of the envelope.
109+
GetNamespace() string
110+
111+
// GetName returns the name of the envelope.
112+
GetName() string
113+
114+
// GetEnvelopeType returns the type of the envelope.
115+
GetEnvelopeType() string
116+
}
117+
118+
// Ensure that both ClusterResourceEnvelope and ResourceEnvelope implement the
119+
// EnvelopeReader interface at compile time.
120+
var (
121+
_ EnvelopeReader = &ClusterResourceEnvelope{}
122+
_ EnvelopeReader = &ResourceEnvelope{}
123+
)
124+
125+
// Implements the EnvelopeReader interface for ClusterResourceEnvelope.
126+
127+
func (e *ClusterResourceEnvelope) GetData() map[string]runtime.RawExtension {
128+
return e.Data
129+
}
130+
131+
func (e *ClusterResourceEnvelope) GetEnvelopeObjRef() klog.ObjectRef {
132+
return klog.KObj(e)
133+
}
134+
135+
func (e *ClusterResourceEnvelope) GetEnvelopeType() string {
136+
return string(ClusterResourceEnvelopeType)
137+
}
138+
139+
// Implements the EnvelopeReader interface for ResourceEnvelope.
140+
141+
func (e *ResourceEnvelope) GetData() map[string]runtime.RawExtension {
142+
return e.Data
143+
}
144+
145+
func (e *ResourceEnvelope) GetEnvelopeObjRef() klog.ObjectRef {
146+
return klog.KObj(e)
147+
}
148+
149+
func (e *ResourceEnvelope) GetEnvelopeType() string {
150+
return string(ResourceEnvelopeType)
151+
}

apis/placement/v1beta1/zz_generated.deepcopy.go

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)