Skip to content

Commit cc61b56

Browse files
authored
🐛 ignore hub apiserver override when forcing internal endpoint lookup (#34)
* fix: ignore hub apiserver when force-internal-endpoint-lookup is set; move hub CA to spec.hub * feat: add timeout, verbosity to API; modernize applicable omitemptys * feat: add timeout, verbosity args to all clusteradm commands * fix: handle stdout & stderr separately * chore: fix 'make test' * ci: fix E2E artifact paths * fix: handle approval of duplicate CSRs --------- Signed-off-by: Tyler Gillson <[email protected]>
1 parent f90ab55 commit cc61b56

File tree

14 files changed

+301
-138
lines changed

14 files changed

+301
-138
lines changed

.github/repositories.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"fleetconfig-controller": {
3-
"e2e-artifacts": ["hub-bundle.tar.gz", "spoke-bundle.tar.gz"]
3+
"e2e-artifacts": ["test/e2e/hub-bundle.tar.gz", "test/e2e/spoke-bundle.tar.gz"]
44
}
55
}

fleetconfig-controller/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ test-unit: manifests generate fmt vet envtest ## Run unit tests.
115115
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" \
116116
go test -v \
117117
-coverpkg=./... \
118-
-coverprofile=cover.out \
118+
-coverprofile=$(COVER_DIR)/unit/cover.out \
119119
$(shell go list ./... | grep -v '/test/e2e')
120120

121121
.PHONY: test-e2e

fleetconfig-controller/api/v1alpha1/fleetconfig_types.go

Lines changed: 94 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,27 @@ import (
2828
type FleetConfigSpec struct {
2929
// +required
3030
Hub Hub `json:"hub"`
31+
3132
// +required
3233
Spokes []Spoke `json:"spokes"`
34+
3335
// +kubebuilder:default:={}
3436
// +optional
35-
RegistrationAuth RegistrationAuth `json:"registrationAuth,omitempty"`
37+
RegistrationAuth RegistrationAuth `json:"registrationAuth,omitzero"`
38+
3639
// +optional
3740
AddOnConfigs []AddOnConfig `json:"addOnConfigs,omitempty"`
41+
42+
// Timeout is the timeout in seconds for all clusteradm operations, including init, accept, join, upgrade, etc.
43+
// +kubebuilder:default:=300
44+
// +optional
45+
Timeout int `json:"timeout,omitempty"`
46+
47+
// LogVerbosity is the verbosity of the logs.
48+
// +kubebuilder:validation:Enum=0;1;2;3;4;5;6;7;8;9;10
49+
// +kubebuilder:default:=0
50+
// +optional
51+
LogVerbosity int `json:"logVerbosity,omitempty"`
3852
}
3953

4054
// FleetConfigStatus defines the observed state of FleetConfig.
@@ -147,6 +161,16 @@ func (c Condition) Equal(other Condition) bool {
147161

148162
// Hub provides specifications for an OCM hub cluster.
149163
type Hub struct {
164+
// APIServer is the API server URL for the Hub cluster. If provided, spokes clusters will
165+
// join the hub using this API server instead of the one in the bootstrap kubeconfig.
166+
// Spoke clusters with ForceInternalEndpointLookup set to true will ignore this field.
167+
// +optional
168+
APIServer string `json:"apiServer,omitempty"`
169+
170+
// Hub cluster CA certificate, optional
171+
// +optional
172+
Ca string `json:"ca,omitempty"`
173+
150174
// ClusterManager configuration.
151175
// +optional
152176
ClusterManager *ClusterManager `json:"clusterManager,omitempty"`
@@ -168,12 +192,6 @@ type Hub struct {
168192
// This is an alpha stage flag.
169193
// +optional
170194
SingletonControlPlane *SingletonControlPlane `json:"singleton,omitempty"`
171-
172-
// APIServer is the API server URL for the Hub cluster. If provided, the hub will be joined
173-
// using this API server instead of the one in the obtained kubeconfig. This is useful when
174-
// using in-cluster kubeconfig when that kubeconfig would return an incorrect API server URL.
175-
// +optional
176-
APIServer string `json:"apiServer,omitempty"`
177195
}
178196

179197
// SingletonControlPlane is the configuration for a singleton control plane
@@ -240,12 +258,12 @@ type ClusterManager struct {
240258
// Resource specifications for all clustermanager-managed containers.
241259
// +kubebuilder:default:={}
242260
// +optional
243-
Resources ResourceSpec `json:"resources,omitempty"`
261+
Resources ResourceSpec `json:"resources,omitzero"`
244262

245263
// Version and image registry details for the cluster manager.
246264
// +kubebuilder:default:={}
247265
// +optional
248-
Source OCMSource `json:"source,omitempty"`
266+
Source OCMSource `json:"source,omitzero"`
249267

250268
// If set, the bootstrap token will used instead of a service account token.
251269
// +optional
@@ -301,6 +319,17 @@ type SecretReference struct {
301319
KubeconfigKey string `json:"kubeconfigKey,omitempty"`
302320
}
303321

322+
// ISpoke is an interface that both Spoke and JoinedSpoke implement.
323+
// +kubebuilder:object:generate=false
324+
type ISpoke interface {
325+
GetName() string
326+
GetKubeconfig() Kubeconfig
327+
GetPurgeKlusterletOperator() bool
328+
}
329+
330+
var _ ISpoke = &Spoke{}
331+
var _ ISpoke = &JoinedSpoke{}
332+
304333
// Spoke provides specifications for joining and potentially upgrading spokes.
305334
type Spoke struct {
306335
// The name of the spoke cluster.
@@ -323,10 +352,6 @@ type Spoke struct {
323352
// +required
324353
Kubeconfig Kubeconfig `json:"kubeconfig"`
325354

326-
// Hub cluster CA certificate, optional
327-
// +optional
328-
Ca string `json:"ca,omitempty"`
329-
330355
// Proxy CA certificate, optional
331356
// +optional
332357
ProxyCa string `json:"proxyCa,omitempty"`
@@ -338,7 +363,7 @@ type Spoke struct {
338363
// Klusterlet configuration.
339364
// +kubebuilder:default:={}
340365
// +optional
341-
Klusterlet Klusterlet `json:"klusterlet,omitempty"`
366+
Klusterlet Klusterlet `json:"klusterlet,omitzero"`
342367

343368
// ClusterARN is the ARN of the spoke cluster.
344369
// This field is optionally used for AWS IRSA registration authentication.
@@ -350,19 +375,19 @@ type Spoke struct {
350375
AddOns []AddOn `json:"addOns,omitempty"`
351376
}
352377

353-
// AddOn enables add-on installation on the cluster.
354-
type AddOn struct {
355-
// The name of the add-on being enabled. Must match one of the default or manually configured add-on names.
356-
// +required
357-
ConfigName string `json:"configName"`
378+
// GetName returns the name of the spoke cluster.
379+
func (s *Spoke) GetName() string {
380+
return s.Name
381+
}
358382

359-
// The namespace to install the add-on in. If left empty, installs into the "open-cluster-management-addon" namespace.
360-
// +optional
361-
InstallNamespace string `json:"installNamespace,omitempty"`
383+
// GetKubeconfig returns the kubeconfig for the spoke cluster.
384+
func (s *Spoke) GetKubeconfig() Kubeconfig {
385+
return s.Kubeconfig
386+
}
362387

363-
// Annotations to apply to the add-on.
364-
// +optional
365-
Annotations map[string]string `json:"annotations,omitempty"`
388+
// GetPurgeKlusterletOperator returns the purge klusterlet operator flag.
389+
func (s *Spoke) GetPurgeKlusterletOperator() bool {
390+
return s.Klusterlet.PurgeOperator
366391
}
367392

368393
// JoinType returns a status condition type indicating that a particular Spoke cluster has joined the Hub.
@@ -378,6 +403,21 @@ func (s *Spoke) conditionName() string {
378403
return name
379404
}
380405

406+
// AddOn enables add-on installation on the cluster.
407+
type AddOn struct {
408+
// The name of the add-on being enabled. Must match one of the default or manually configured add-on names.
409+
// +required
410+
ConfigName string `json:"configName"`
411+
412+
// The namespace to install the add-on in. If left empty, installs into the "open-cluster-management-addon" namespace.
413+
// +optional
414+
InstallNamespace string `json:"installNamespace,omitempty"`
415+
416+
// Annotations to apply to the add-on.
417+
// +optional
418+
Annotations map[string]string `json:"annotations,omitempty"`
419+
}
420+
381421
// JoinedSpoke represents a spoke that has been joined to a hub.
382422
type JoinedSpoke struct {
383423
// The name of the spoke cluster.
@@ -393,6 +433,21 @@ type JoinedSpoke struct {
393433
PurgeKlusterletOperator bool `json:"purgeKlusterletOperator,omitempty"`
394434
}
395435

436+
// GetName returns the name of the joined spoke cluster.
437+
func (j *JoinedSpoke) GetName() string {
438+
return j.Name
439+
}
440+
441+
// GetKubeconfig returns the kubeconfig for the joined spoke cluster.
442+
func (j *JoinedSpoke) GetKubeconfig() Kubeconfig {
443+
return j.Kubeconfig
444+
}
445+
446+
// GetPurgeKlusterletOperator returns the purge klusterlet operator flag for the joined spoke cluster.
447+
func (j *JoinedSpoke) GetPurgeKlusterletOperator() bool {
448+
return j.PurgeKlusterletOperator
449+
}
450+
396451
// UnjoinType returns a status condition type indicating that a particular Spoke cluster has been removed from the Hub.
397452
func (j *JoinedSpoke) UnjoinType() string {
398453
return fmt.Sprintf("spoke-cluster-%s-unjoined", j.conditionName())
@@ -445,7 +500,7 @@ type Klusterlet struct {
445500

446501
// External managed cluster kubeconfig, required if using hosted mode.
447502
// +optional
448-
ManagedClusterKubeconfig Kubeconfig `json:"managedClusterKubeconfig,omitempty"`
503+
ManagedClusterKubeconfig Kubeconfig `json:"managedClusterKubeconfig,omitzero"`
449504

450505
// If true, the klusterlet accesses the managed cluster using the internal endpoint from the public
451506
// cluster-info in the managed cluster instead of using managedClusterKubeconfig.
@@ -455,7 +510,7 @@ type Klusterlet struct {
455510
// Resource specifications for all klusterlet-managed containers.
456511
// +kubebuilder:default:={}
457512
// +optional
458-
Resources ResourceSpec `json:"resources,omitempty"`
513+
Resources ResourceSpec `json:"resources,omitzero"`
459514

460515
// If true, deploy klusterlet in singleton mode, with registration and work agents running in a single pod.
461516
// This is an alpha stage flag.
@@ -465,7 +520,7 @@ type Klusterlet struct {
465520
// Version and image registry details for the klusterlet.
466521
// +kubebuilder:default:={}
467522
// +optional
468-
Source OCMSource `json:"source,omitempty"`
523+
Source OCMSource `json:"source,omitzero"`
469524
}
470525

471526
// ResourceSpec defines resource limits and requests for all managed clusters.
@@ -565,12 +620,20 @@ type AddOnConfig struct {
565620
// FleetConfig is the Schema for the fleetconfigs API.
566621
type FleetConfig struct {
567622
metav1.TypeMeta `json:",inline"`
568-
metav1.ObjectMeta `json:"metadata,omitempty"`
623+
metav1.ObjectMeta `json:"metadata,omitzero"`
569624

570-
Spec FleetConfigSpec `json:"spec,omitempty"`
625+
Spec FleetConfigSpec `json:"spec,omitzero"`
571626
Status FleetConfigStatus `json:"status,omitempty"`
572627
}
573628

629+
// BaseArgs returns the base arguments for all clusteradm commands.
630+
func (m *FleetConfig) BaseArgs() []string {
631+
return []string{
632+
fmt.Sprintf("--timeout=%d", m.Spec.Timeout),
633+
fmt.Sprintf("--v=%d", m.Spec.LogVerbosity),
634+
}
635+
}
636+
574637
// GetCondition gets the condition with the supplied type, if it exists.
575638
func (m *FleetConfig) GetCondition(cType string) *Condition {
576639
return m.Status.GetCondition(cType)
@@ -586,7 +649,7 @@ func (m *FleetConfig) SetConditions(cover bool, c ...Condition) {
586649
// FleetConfigList contains a list of FleetConfig.
587650
type FleetConfigList struct {
588651
metav1.TypeMeta `json:",inline"`
589-
metav1.ListMeta `json:"metadata,omitempty"`
652+
metav1.ListMeta `json:"metadata,omitzero"`
590653
Items []FleetConfig `json:"items"`
591654
}
592655

0 commit comments

Comments
 (0)