Skip to content

Commit d9d5a97

Browse files
committed
feat: namespaced hub
Signed-off-by: Artur Shad Nik <arturshadnik@gmail.com>
1 parent 375b21b commit d9d5a97

File tree

7 files changed

+39
-16
lines changed

7 files changed

+39
-16
lines changed

fleetconfig-controller/api/v1beta1/hub_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ type InstalledHubAddOn struct {
222222

223223
// +kubebuilder:object:root=true
224224
// +kubebuilder:subresource:status
225-
// +kubebuilder:resource:scope=Cluster
226225
// +kubebuilder:printcolumn:name="PHASE",type=string,JSONPath=`.status.phase`
227226
// +kubebuilder:printcolumn:name="AGE",type=date,JSONPath=".metadata.creationTimestamp"
228227

fleetconfig-controller/api/v1beta1/spoke_types.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ type SpokeSpec struct {
6969
AddOns []AddOn `json:"addOns,omitempty"`
7070

7171
// Timeout is the timeout in seconds for all clusteradm operations, including init, accept, join, upgrade, etc.
72-
// +kubebuilder:default:=300
72+
// If not set, defaults to the Hub's timeout.
7373
// +optional
7474
Timeout int `json:"timeout,omitempty"`
7575

7676
// LogVerbosity is the verbosity of the logs.
77+
// If not set, defaults to the Hub's logVerbosity.
7778
// +kubebuilder:validation:Enum=0;1;2;3;4;5;6;7;8;9;10
78-
// +kubebuilder:default:=0
7979
// +optional
8080
LogVerbosity int `json:"logVerbosity,omitempty"`
8181
}
@@ -85,6 +85,15 @@ type HubRef struct {
8585
// Name is the name of the Hub that this Spoke is managed by.
8686
// +required
8787
Name string `json:"name"`
88+
89+
// Namespace is namespace of the Hub that this Spoke is managed by.
90+
// +required
91+
Namespace string `json:"namespace"`
92+
}
93+
94+
// IsManagedBy checks whether or not the Spoke is managed by a particular Hub.
95+
func (s *Spoke) IsManagedBy(om metav1.ObjectMeta) bool {
96+
return s.Spec.HubRef.Name == om.Name && s.Spec.HubRef.Namespace == om.Namespace
8897
}
8998

9099
// Klusterlet is the configuration for a klusterlet.

fleetconfig-controller/charts/fleetconfig-controller/crds/fleetconfig.open-cluster-management.io_hubs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ spec:
1212
listKind: HubList
1313
plural: hubs
1414
singular: hub
15-
scope: Cluster
15+
scope: Namespaced
1616
versions:
1717
- additionalPrinterColumns:
1818
- jsonPath: .status.phase

fleetconfig-controller/charts/fleetconfig-controller/crds/fleetconfig.open-cluster-management.io_spokes.yaml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,13 @@ spec:
8787
description: Name is the name of the Hub that this Spoke is managed
8888
by.
8989
type: string
90+
namespace:
91+
description: Namespace is namespace of the Hub that this Spoke
92+
is managed by.
93+
type: string
9094
required:
9195
- name
96+
- namespace
9297
type: object
9398
klusterlet:
9499
default: {}
@@ -2214,9 +2219,11 @@ spec:
22142219
properties:
22152220
key:
22162221
description: Key is the key under which the data is stored.
2222+
minLength: 1
22172223
type: string
22182224
name:
22192225
description: Name is the name of the ConfigMap
2226+
minLength: 1
22202227
type: string
22212228
required:
22222229
- key
@@ -2258,8 +2265,9 @@ spec:
22582265
type: object
22592266
type: object
22602267
logVerbosity:
2261-
default: 0
2262-
description: LogVerbosity is the verbosity of the logs.
2268+
description: |-
2269+
LogVerbosity is the verbosity of the logs.
2270+
If not set, defaults to the Hub's logVerbosity.
22632271
enum:
22642272
- 0
22652273
- 1
@@ -2285,9 +2293,9 @@ spec:
22852293
resources.
22862294
type: boolean
22872295
timeout:
2288-
default: 300
2289-
description: Timeout is the timeout in seconds for all clusteradm
2290-
operations, including init, accept, join, upgrade, etc.
2296+
description: |-
2297+
Timeout is the timeout in seconds for all clusteradm operations, including init, accept, join, upgrade, etc.
2298+
If not set, defaults to the Hub's timeout.
22912299
type: integer
22922300
required:
22932301
- hubRef

fleetconfig-controller/internal/controller/v1beta1/hub_controller.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ func (r *HubReconciler) cleanHub(ctx context.Context, hub *v1beta1.Hub) error {
196196
// Mark all Spokes for deletion if they haven't been deleted yet
197197
for i := range spokes {
198198
spoke := &spokes[i]
199-
if spoke.DeletionTimestamp.IsZero() && spoke.Spec.HubRef.Name == hub.Name {
199+
if spoke.DeletionTimestamp.IsZero() {
200+
if !spoke.IsManagedBy(hub.ObjectMeta) {
201+
continue
202+
}
200203
logger.Info("Marking Spoke for deletion", "spoke", spoke.Name)
201204
if err := r.Delete(ctx, spoke); err != nil && !kerrs.IsNotFound(err) {
202205
return fmt.Errorf("failed to delete spoke %s: %w", spoke.Name, err)
@@ -548,7 +551,8 @@ func (r *HubReconciler) mapSpokeEventToHub(_ context.Context, obj client.Object)
548551
return []reconcile.Request{
549552
{
550553
NamespacedName: types.NamespacedName{
551-
Name: spoke.Spec.HubRef.Name,
554+
Name: spoke.Spec.HubRef.Name,
555+
Namespace: spoke.Spec.HubRef.Namespace,
552556
},
553557
},
554558
}

fleetconfig-controller/internal/controller/v1beta1/spoke_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ func getToken(ctx context.Context, kClient client.Client, hub *v1beta1.Hub) (*to
784784
func (r *SpokeReconciler) getHubMeta(ctx context.Context, hubRef v1beta1.HubRef) (*v1beta1.Hub, []byte, error) {
785785
hub := &v1beta1.Hub{}
786786
var hubKubeconfig []byte
787-
nn := types.NamespacedName{Name: hubRef.Name}
787+
nn := types.NamespacedName{Name: hubRef.Name, Namespace: hubRef.Namespace}
788788

789789
// get Hub using local client
790790
err := r.Get(ctx, nn, hub)
@@ -944,7 +944,7 @@ func (r *SpokeReconciler) mapHubEventToSpoke(ctx context.Context, obj client.Obj
944944
}
945945
req := make([]reconcile.Request, 0)
946946
for _, s := range spokeList.Items {
947-
if s.Spec.HubRef.Name != hub.Name {
947+
if !s.IsManagedBy(hub.ObjectMeta) {
948948
continue
949949
}
950950
req = append(req, reconcile.Request{

fleetconfig-controller/internal/webhook/v1beta1/spoke_webhook.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,14 @@ func (d *SpokeCustomDefaulter) Default(ctx context.Context, obj runtime.Object)
7979
}
8080

8181
// only set these if they are unset, to allow per-resource values
82-
if spoke.Spec.Timeout == 300 { // default value
83-
spoke.Spec.Timeout = hub.Spec.DeepCopy().Timeout
82+
// Note: We can't distinguish between default values and explicitly set values
83+
// since kubebuilder defaults are applied before webhooks run.
84+
// So we only default from Hub if the Spoke has the kubebuilder default values.
85+
if spoke.Spec.Timeout == 0 {
86+
spoke.Spec.Timeout = hub.Spec.Timeout
8487
}
8588
if spoke.Spec.LogVerbosity == 0 {
86-
spoke.Spec.LogVerbosity = hub.Spec.DeepCopy().LogVerbosity
89+
spoke.Spec.LogVerbosity = hub.Spec.LogVerbosity
8790
}
8891
return nil
8992
}

0 commit comments

Comments
 (0)