Skip to content

Commit

Permalink
Deprecate name/namespace labels of pp/cpp
Browse files Browse the repository at this point in the history
Co-authored-by: changzhen <[email protected]>
Signed-off-by: whitewindmills <[email protected]>
  • Loading branch information
whitewindmills and XiShanYongYe-Chang committed Apr 8, 2024
1 parent f369c55 commit 1281d6c
Show file tree
Hide file tree
Showing 15 changed files with 382 additions and 368 deletions.
30 changes: 20 additions & 10 deletions pkg/apis/policy/v1alpha1/well_known_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.

package v1alpha1

// The well-known label key constant.
const (
// PropagationPolicyPermanentIDLabel is the identifier of a PropagationPolicy object.
// Karmada generates a unique identifier, such as metadata.UUID, for each PropagationPolicy object.
Expand All @@ -31,6 +32,19 @@ const (
// In backup scenarios, when applying the backup resource manifest in a new cluster, the UUID may change.
ClusterPropagationPolicyPermanentIDLabel = "clusterpropagationpolicy.karmada.io/permanent-id"

// NamespaceSkipAutoPropagationLabel is added to namespace objects to indicate if
// the namespace should be skipped from propagating by the namespace controller.
// For example, a namespace with the following label will be skipped:
// labels:
// namespace.karmada.io/skip-auto-propagation: "true"
//
// NOTE: If create a ns without this label, then patch it with this label, the ns will not be
// synced to new member clusters, but old member clusters still have it.
NamespaceSkipAutoPropagationLabel = "namespace.karmada.io/skip-auto-propagation"
)

// The well-known annotation key constant.
const (
// PropagationPolicyNamespaceAnnotation is added to objects to specify associated PropagationPolicy namespace.
PropagationPolicyNamespaceAnnotation = "propagationpolicy.karmada.io/namespace"

Expand All @@ -39,23 +53,19 @@ const (

// ClusterPropagationPolicyAnnotation is added to objects to specify associated ClusterPropagationPolicy name.
ClusterPropagationPolicyAnnotation = "clusterpropagationpolicy.karmada.io/name"
)

// TODO(whitewindmills): These deprecated labels will be removed in a future version.
const (
// PropagationPolicyNamespaceLabel is added to objects to specify associated PropagationPolicy namespace.
// Deprecated
PropagationPolicyNamespaceLabel = "propagationpolicy.karmada.io/namespace"

// PropagationPolicyNameLabel is added to objects to specify associated PropagationPolicy's name.
// Deprecated
PropagationPolicyNameLabel = "propagationpolicy.karmada.io/name"

// ClusterPropagationPolicyLabel is added to objects to specify associated ClusterPropagationPolicy.
// Deprecated
ClusterPropagationPolicyLabel = "clusterpropagationpolicy.karmada.io/name"

// NamespaceSkipAutoPropagationLabel is added to namespace objects to indicate if
// the namespace should be skipped from propagating by the namespace controller.
// For example, a namespace with the following label will be skipped:
// labels:
// namespace.karmada.io/skip-auto-propagation: "true"
//
// NOTE: If create a ns without this label, then patch it with this label, the ns will not be
// synced to new member clusters, but old member clusters still have it.
NamespaceSkipAutoPropagationLabel = "namespace.karmada.io/skip-auto-propagation"
)
26 changes: 12 additions & 14 deletions pkg/controllers/federatedhpa/federatedhpa_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,25 +404,23 @@ func (c *FHPAController) reconcileAutoscaler(ctx context.Context, hpa *autoscali

func (c *FHPAController) getBindingByLabel(resourceLabel map[string]string, resourceRef autoscalingv2.CrossVersionObjectReference) (*workv1alpha2.ResourceBinding, error) {
if len(resourceLabel) == 0 {
return nil, fmt.Errorf("Target resource has no label. ")
return nil, errors.New("target resource has no label")
}

var policyName, policyNameSpace string
var policyID string
var selector labels.Selector
if _, ok := resourceLabel[policyv1alpha1.PropagationPolicyNameLabel]; ok {
policyName = resourceLabel[policyv1alpha1.PropagationPolicyNameLabel]
policyNameSpace = resourceLabel[policyv1alpha1.PropagationPolicyNamespaceLabel]
if _, ok := resourceLabel[policyv1alpha1.PropagationPolicyPermanentIDLabel]; ok {
policyID = resourceLabel[policyv1alpha1.PropagationPolicyPermanentIDLabel]
selector = labels.SelectorFromSet(labels.Set{
policyv1alpha1.PropagationPolicyNameLabel: policyName,
policyv1alpha1.PropagationPolicyNamespaceLabel: policyNameSpace,
policyv1alpha1.PropagationPolicyPermanentIDLabel: policyID,
})
} else if _, ok = resourceLabel[policyv1alpha1.ClusterPropagationPolicyLabel]; ok {
policyName = resourceLabel[policyv1alpha1.ClusterPropagationPolicyLabel]
} else if _, ok = resourceLabel[policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel]; ok {
policyID = resourceLabel[policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel]
selector = labels.SelectorFromSet(labels.Set{
policyv1alpha1.ClusterPropagationPolicyLabel: policyName,
policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel: policyID,
})
} else {
return nil, fmt.Errorf("No label of policy found. ")
return nil, errors.New("no label of policy permanent-id found")
}

binding := &workv1alpha2.ResourceBinding{}
Expand All @@ -432,7 +430,7 @@ func (c *FHPAController) getBindingByLabel(resourceLabel map[string]string, reso
return nil, err
}
if len(bindingList.Items) == 0 {
return nil, fmt.Errorf("Length of binding list is zero. ")
return nil, errors.New("length of binding list is zero")
}

found := false
Expand All @@ -444,15 +442,15 @@ func (c *FHPAController) getBindingByLabel(resourceLabel map[string]string, reso
}
}
if !found {
return nil, fmt.Errorf("No binding matches the target resource. ")
return nil, errors.New("no binding matches the target resource")
}

return binding, nil
}

func (c *FHPAController) getTargetCluster(binding *workv1alpha2.ResourceBinding) ([]string, error) {
if len(binding.Spec.Clusters) == 0 {
return nil, fmt.Errorf("Binding has no schedulable clusters. ")
return nil, errors.New("binding has no schedulable clusters")
}

var allClusters []string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (r *HpaScaleTargetMarker) Generic(_ event.GenericEvent) bool {
}

func hasBeenPropagated(hpa *autoscalingv2.HorizontalPodAutoscaler) bool {
_, ppExist := hpa.GetLabels()[policyv1alpha1.PropagationPolicyNameLabel]
_, cppExist := hpa.GetLabels()[policyv1alpha1.ClusterPropagationPolicyLabel]
_, ppExist := hpa.GetLabels()[policyv1alpha1.PropagationPolicyPermanentIDLabel]
_, cppExist := hpa.GetLabels()[policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel]
return ppExist || cppExist
}
Loading

0 comments on commit 1281d6c

Please sign in to comment.