@@ -11,6 +11,7 @@ import (
11
11
"k8s.io/apimachinery/pkg/labels"
12
12
"k8s.io/apimachinery/pkg/selection"
13
13
"k8s.io/apimachinery/pkg/util/sets"
14
+ aboutv1alpha1listers "sigs.k8s.io/about-api/pkg/generated/listers/apis/v1alpha1"
14
15
15
16
clusterv1alpha1listers "open-cluster-management.io/api/client/cluster/listers/cluster/v1alpha1"
16
17
clusterv1 "open-cluster-management.io/api/cluster/v1"
@@ -25,14 +26,12 @@ const labelCustomizedOnly = "open-cluster-management.io/spoke-only"
25
26
type claimReconcile struct {
26
27
recorder events.Recorder
27
28
claimLister clusterv1alpha1listers.ClusterClaimLister
29
+ aboutLister aboutv1alpha1listers.ClusterPropertyLister
28
30
maxCustomClusterClaims int
29
31
reservedClusterClaimSuffixes []string
30
32
}
31
33
32
34
func (r * claimReconcile ) reconcile (ctx context.Context , cluster * clusterv1.ManagedCluster ) (* clusterv1.ManagedCluster , reconcileState , error ) {
33
- if ! features .SpokeMutableFeatureGate .Enabled (ocmfeature .ClusterClaim ) {
34
- return cluster , reconcileContinue , nil
35
- }
36
35
// current managed cluster has not joined the hub yet, do nothing.
37
36
if ! meta .IsStatusConditionTrue (cluster .Status .Conditions , clusterv1 .ManagedClusterConditionJoined ) {
38
37
r .recorder .Eventf ("ManagedClusterIsNotAccepted" , "Managed cluster %q does not join the hub yet" , cluster .Name )
@@ -46,31 +45,61 @@ func (r *claimReconcile) reconcile(ctx context.Context, cluster *clusterv1.Manag
46
45
// exposeClaims saves cluster claims fetched on managed cluster into status of the
47
46
// managed cluster on hub. Some of the customized claims might not be exposed once
48
47
// the total number of the claims exceeds the value of `cluster-claims-max`.
49
- func (r * claimReconcile ) exposeClaims (ctx context.Context , cluster * clusterv1.ManagedCluster ) error {
48
+ func (r * claimReconcile ) exposeClaims (_ context.Context , cluster * clusterv1.ManagedCluster ) error {
50
49
var reservedClaims , customClaims []clusterv1.ManagedClusterClaim
50
+ var clusterClaims []* clusterv1alpha1.ClusterClaim
51
+ claimsMap := map [string ]clusterv1.ManagedClusterClaim {}
51
52
52
53
// clusterClaim with label `open-cluster-management.io/spoke-only` will not be synced to managedCluster.Status at hub.
53
- requirement , _ := labels .NewRequirement (labelCustomizedOnly , selection .DoesNotExist , []string {})
54
- selector := labels .NewSelector ().Add (* requirement )
55
- clusterClaims , err := r .claimLister .List (selector )
54
+ requirement , err := labels .NewRequirement (labelCustomizedOnly , selection .DoesNotExist , []string {})
56
55
if err != nil {
57
- return fmt .Errorf ("unable to list cluster claims: %w" , err )
56
+ return err
57
+ }
58
+ selector := labels .NewSelector ().Add (* requirement )
59
+
60
+ if features .SpokeMutableFeatureGate .Enabled (ocmfeature .ClusterProperty ) {
61
+ clusterProperties , err := r .aboutLister .List (selector )
62
+ if err != nil {
63
+ return fmt .Errorf ("unable to list cluster properties: %w" , err )
64
+ }
65
+
66
+ for _ , property := range clusterProperties {
67
+ claimsMap [property .Name ] = clusterv1.ManagedClusterClaim {
68
+ Name : property .Name ,
69
+ Value : property .Spec .Value ,
70
+ }
71
+ }
72
+ }
73
+
74
+ if features .SpokeMutableFeatureGate .Enabled (ocmfeature .ClusterClaim ) {
75
+ clusterClaims , err = r .claimLister .List (selector )
76
+ if err != nil {
77
+ return fmt .Errorf ("unable to list cluster claims: %w" , err )
78
+ }
79
+
80
+ for _ , claim := range clusterClaims {
81
+ // if the claim has the same name with the property, ignore it.
82
+ if _ , ok := claimsMap [claim .Name ]; ! ok {
83
+ claimsMap [claim .Name ] = clusterv1.ManagedClusterClaim {
84
+ Name : claim .Name ,
85
+ Value : claim .Spec .Value ,
86
+ }
87
+ }
88
+ }
58
89
}
59
90
60
91
// check if the cluster claim is one of the reserved claims or has a reserved suffix.
61
92
// if so, it will be treated as a reserved claim and will always be exposed.
62
93
reservedClaimNames := sets .New (clusterv1alpha1 .ReservedClusterClaimNames [:]... )
63
94
reservedClaimSuffixes := sets .New (r .reservedClusterClaimSuffixes ... )
64
- for _ , clusterClaim := range clusterClaims {
65
- managedClusterClaim := clusterv1.ManagedClusterClaim {
66
- Name : clusterClaim .Name ,
67
- Value : clusterClaim .Spec .Value ,
68
- }
69
95
96
+ for _ , managedClusterClaim := range claimsMap {
70
97
if matchReservedClaims (reservedClaimNames , reservedClaimSuffixes , managedClusterClaim ) {
71
98
reservedClaims = append (reservedClaims , managedClusterClaim )
99
+ // reservedClaimNames.Insert(managedClusterClaim.Name)
72
100
continue
73
101
}
102
+
74
103
customClaims = append (customClaims , managedClusterClaim )
75
104
}
76
105
0 commit comments