Skip to content

Commit d19e8cb

Browse files
committed
feat: wip - fill out v1beta1 structs
Signed-off-by: Artur Shad Nik <arturshadnik@gmail.com>
1 parent 7b2a16d commit d19e8cb

File tree

8 files changed

+3387
-38
lines changed

8 files changed

+3387
-38
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
22
# Ignore build and test binaries.
33
bin/
4+
tmp/
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package v1beta1
2+
3+
import (
4+
"fmt"
5+
"time"
6+
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
)
9+
10+
// Kubeconfig is the configuration for a kubeconfig.
11+
type Kubeconfig struct {
12+
// A reference to an existing secret containing a kubeconfig.
13+
// Must be provided for remote clusters.
14+
// For same-cluster, must be provided unless InCluster is set to true.
15+
// +optional
16+
SecretReference *SecretReference `json:"secretReference,omitempty"`
17+
18+
// If set, the kubeconfig will be read from the cluster.
19+
// Only applicable for same-cluster operations.
20+
// Defaults to false.
21+
// +optional
22+
InCluster bool `json:"inCluster,omitempty"`
23+
24+
// The context to use in the kubeconfig file.
25+
// +optional
26+
Context string `json:"context,omitempty"`
27+
}
28+
29+
// SecretReference describes how to retrieve a kubeconfig stored as a secret
30+
type SecretReference struct {
31+
// The name of the secret.
32+
// +required
33+
Name string `json:"name"`
34+
35+
// The namespace the secret is in.
36+
// +required
37+
Namespace string `json:"namespace"`
38+
39+
// The map key to access the kubeconfig. Defaults to 'kubeconfig'.
40+
// +kubebuilder:default:="kubeconfig"
41+
// +optional
42+
KubeconfigKey string `json:"kubeconfigKey,omitempty"`
43+
}
44+
45+
// OCMSource is the configuration for an OCM source.
46+
type OCMSource struct {
47+
// The version of predefined compatible image versions (e.g. v0.6.0). Defaults to the latest released version.
48+
// You can also set "latest" to install the latest development version.
49+
// +kubebuilder:default:="default"
50+
// +optional
51+
BundleVersion string `json:"bundleVersion,omitempty"`
52+
53+
// The name of the image registry serving OCM images, which will be used for all OCM components."
54+
// +kubebuilder:default:="quay.io/open-cluster-management"
55+
// +optional
56+
Registry string `json:"registry,omitempty"`
57+
}
58+
59+
// ResourceSpec defines resource limits and requests for all managed clusters.
60+
type ResourceSpec struct {
61+
// The resource limits of all the containers managed by the Cluster Manager or Klusterlet operators.
62+
// +optional
63+
Limits *ResourceValues `json:"limits,omitempty"`
64+
65+
// The resource requests of all the containers managed by the Cluster Manager or Klusterlet operators.
66+
// +optional
67+
Requests *ResourceValues `json:"requests,omitempty"`
68+
69+
// The resource QoS class of all the containers managed by the Cluster Manager or Klusterlet operators.
70+
// One of Default, BestEffort or ResourceRequirement.
71+
// +kubebuilder:validation:Enum=Default;BestEffort;ResourceRequirement
72+
// +kubebuilder:default:="Default"
73+
// +optional
74+
QosClass string `json:"qosClass,omitempty"`
75+
}
76+
77+
// ResourceValues detail container resource constraints.
78+
type ResourceValues struct {
79+
// The number of CPU units to request, e.g., '800m'.
80+
// +optional
81+
CPU string `json:"cpu,omitempty"`
82+
83+
// The amount of memory to request, e.g., '8Gi'.
84+
// +optional
85+
Memory string `json:"memory,omitempty"`
86+
}
87+
88+
// String returns a string representation of the resource values.
89+
func (r *ResourceValues) String() string {
90+
if r.CPU != "" && r.Memory != "" {
91+
return fmt.Sprintf("cpu=%s,memory=%s", r.CPU, r.Memory)
92+
} else if r.CPU != "" {
93+
return fmt.Sprintf("cpu=%s", r.CPU)
94+
} else if r.Memory != "" {
95+
return fmt.Sprintf("memory=%s", r.Memory)
96+
}
97+
return ""
98+
}
99+
100+
// NewCondition returns a new v1alpha1.Condition.
101+
func NewCondition(msg, cType string, status, wantStatus metav1.ConditionStatus) Condition {
102+
return Condition{
103+
Condition: metav1.Condition{
104+
Status: status,
105+
Message: msg,
106+
Reason: ReconcileSuccess,
107+
Type: cType,
108+
LastTransitionTime: metav1.Time{Time: time.Now()},
109+
},
110+
WantStatus: wantStatus,
111+
}
112+
}
113+
114+
// Condition describes the state of a FleetConfig.
115+
type Condition struct {
116+
metav1.Condition `json:",inline"`
117+
WantStatus metav1.ConditionStatus `json:"wantStatus"`
118+
}
119+
120+
// Equal returns true if the condition is identical to the supplied condition, ignoring the LastTransitionTime.
121+
func (c Condition) Equal(other Condition) bool {
122+
return c.Type == other.Type && c.Status == other.Status && c.WantStatus == other.WantStatus &&
123+
c.Reason == other.Reason && c.Message == other.Message
124+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package v1beta1
2+
3+
import "k8s.io/apimachinery/pkg/labels"
4+
5+
const (
6+
// FleetConfigFinalizer is the finalizer for FleetConfig cleanup.
7+
FleetConfigFinalizer = "fleetconfig.open-cluster-management.io/cleanup"
8+
)
9+
10+
// FleetConfig condition types
11+
const (
12+
// FleetConfigHubInitialized means that the Hub has been initialized.
13+
FleetConfigHubInitialized = "HubInitialized"
14+
15+
// FleetConfigAddonsConfigured means that all addons have been configured on the Hub.
16+
FleetConfigAddonsConfigured = "AddonsConfigured"
17+
18+
// FleetConfigCleanupFailed means that a failure occurred during cleanup.
19+
FleetConfigCleanupFailed = "CleanupFailed"
20+
21+
// FleetConfigAddonsEnabled means that all addons have been enabled for a particular Spoke.
22+
FleetConfigAddonsEnabled = "AddonsEnabled"
23+
)
24+
25+
// FleetConfig condition reasons
26+
const (
27+
ReconcileSuccess = "ReconcileSuccess"
28+
)
29+
30+
// FleetConfig phases
31+
const (
32+
// FleetConfigStarting means that the Hub and Spoke(s) are being initialized / joined.
33+
FleetConfigStarting = "Initializing"
34+
35+
// FleetConfigRunning means that the Hub is initialized and all Spoke(s) have joined successfully.
36+
FleetConfigRunning = "Running"
37+
38+
// FleetConfigUnhealthy means that a failure occurred during Hub initialization and/or Spoke join attempt.
39+
FleetConfigUnhealthy = "Unhealthy"
40+
41+
// FleetConfigDeleting means that the FleetConfig is being deleted.
42+
FleetConfigDeleting = "Deleting"
43+
)
44+
45+
// ManagedClusterType is the type of a managed cluster.
46+
type ManagedClusterType string
47+
48+
const (
49+
// ManagedClusterTypeHub is the type of managed cluster that is a hub.
50+
ManagedClusterTypeHub = "hub"
51+
52+
// ManagedClusterTypeSpoke is the type of managed cluster that is a spoke.
53+
ManagedClusterTypeSpoke = "spoke"
54+
55+
// ManagedClusterTypeHubAsSpoke is the type of managed cluster that is both a hub and a spoke.
56+
ManagedClusterTypeHubAsSpoke = "hub-as-spoke"
57+
)
58+
59+
// FleetConfig labels
60+
const (
61+
// LabelManagedClusterType is the label key for the managed cluster type.
62+
LabelManagedClusterType = "fleetconfig.open-cluster-management.io/managedClusterType"
63+
64+
// LabelAddOnManagedBy is the label key for the lifecycle manager of an add-on resource.
65+
LabelAddOnManagedBy = "addon.open-cluster-management.io/managedBy"
66+
)
67+
68+
// Registration driver types
69+
const (
70+
// CSRRegistrationDriver is the default CSR-based registration driver.
71+
CSRRegistrationDriver = "csr"
72+
73+
// AWSIRSARegistrationDriver is the AWS IAM Role for Service Accounts (IRSA) registration driver.
74+
AWSIRSARegistrationDriver = "awsirsa"
75+
)
76+
77+
// Addon ConfigMap constants
78+
const (
79+
// AddonConfigMapNamePrefix is the common name prefix for all configmaps containing addon configurations.
80+
AddonConfigMapNamePrefix = "fleet-addon"
81+
82+
// AddonConfigMapManifestRawKey is the data key containing raw manifests.
83+
AddonConfigMapManifestRawKey = "manifestsRaw"
84+
85+
// AddonConfigMapManifestRawKey is the data key containing a URL to download manifests.
86+
AddonConfigMapManifestURLKey = "manifestsURL"
87+
)
88+
89+
// AllowedAddonURLSchemes are the URL schemes which can be used to provide manifests for configuring addons.
90+
var AllowedAddonURLSchemes = []string{"http", "https"}
91+
92+
var (
93+
// ManagedByLabels are labeles applies to resources to denote that fleetconfig-controller is managing the lifecycle.
94+
ManagedByLabels = map[string]string{
95+
LabelAddOnManagedBy: "fleetconfig-controller",
96+
}
97+
// ManagedBySelector is a label selector for filtering add-on resources managed fleetconfig-controller.
98+
ManagedBySelector = labels.SelectorFromSet(labels.Set(ManagedByLabels))
99+
)

fleetconfig-controller/api/v1beta1/hub_types.go

Lines changed: 124 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,138 @@ import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121
)
2222

23-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
24-
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
25-
2623
// HubSpec defines the desired state of Hub
2724
type HubSpec struct {
28-
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
29-
// Important: Run "make" to regenerate code after modifying this file
30-
// The following markers will use OpenAPI v3 schema to validate the value
31-
// More info: https://book.kubebuilder.io/reference/markers/crd-validation.html
25+
// APIServer is the API server URL for the Hub cluster. If provided, spokes clusters will
26+
// join the hub using this API server instead of the one in the bootstrap kubeconfig.
27+
// Spoke clusters with ForceInternalEndpointLookup set to true will ignore this field.
28+
// +optional
29+
APIServer string `json:"apiServer,omitempty"`
30+
31+
// Hub cluster CA certificate, optional
32+
// +optional
33+
Ca string `json:"ca,omitempty"`
34+
35+
// ClusterManager configuration.
36+
// +optional
37+
ClusterManager *ClusterManager `json:"clusterManager,omitempty"`
38+
39+
// If true, create open-cluster-management namespace, otherwise use existing one.
40+
// +kubebuilder:default:=true
41+
// +optional
42+
CreateNamespace bool `json:"createNamespace,omitempty"`
43+
44+
// If set, the hub will be reinitialized.
45+
// +optional
46+
Force bool `json:"force,omitempty"`
47+
48+
// Kubeconfig details for the Hub cluster.
49+
// +required
50+
Kubeconfig Kubeconfig `json:"kubeconfig"`
3251

33-
// foo is an example field of Hub. Edit hub_types.go to remove/update
52+
// Singleton control plane configuration. If provided, deploy a singleton control plane instead of clustermanager.
53+
// This is an alpha stage flag.
3454
// +optional
35-
Foo *string `json:"foo,omitempty"`
55+
SingletonControlPlane *SingletonControlPlane `json:"singleton,omitempty"`
56+
}
57+
58+
// SingletonControlPlane is the configuration for a singleton control plane
59+
type SingletonControlPlane struct {
60+
// The name of the singleton control plane.
61+
// +kubebuilder:default:="singleton-controlplane"
62+
// +optional
63+
Name string `json:"name,omitempty"`
64+
65+
// Helm configuration for the multicluster-controlplane Helm chart.
66+
// For now https://open-cluster-management.io/helm-charts/ocm/multicluster-controlplane is always used - no private registry support.
67+
// See: https://github.com/open-cluster-management-io/multicluster-controlplane/blob/main/charts/multicluster-controlplane/values.yaml
68+
// +optional
69+
Helm *Helm `json:"helm,omitempty"`
70+
}
71+
72+
// Helm is the configuration for helm.
73+
type Helm struct {
74+
// Raw, YAML-formatted Helm values.
75+
// +optional
76+
Values string `json:"values,omitempty"`
77+
78+
// Comma-separated Helm values, e.g., key1=val1,key2=val2.
79+
// +optional
80+
Set []string `json:"set,omitempty"`
81+
82+
// Comma-separated Helm JSON values, e.g., key1=jsonval1,key2=jsonval2.
83+
// +optional
84+
SetJSON []string `json:"setJson,omitempty"`
85+
86+
// Comma-separated Helm literal STRING values.
87+
// +optional
88+
SetLiteral []string `json:"setLiteral,omitempty"`
89+
90+
// Comma-separated Helm STRING values, e.g., key1=val1,key2=val2.
91+
// +optional
92+
SetString []string `json:"setString,omitempty"`
93+
}
94+
95+
// ClusterManager is the configuration for a cluster manager.
96+
type ClusterManager struct {
97+
// A set of comma-separated pairs of the form 'key1=value1,key2=value2' that describe feature gates for alpha/experimental features.
98+
// Options are:
99+
// - AddonManagement (ALPHA - default=true)
100+
// - AllAlpha (ALPHA - default=false)
101+
// - AllBeta (BETA - default=false)
102+
// - CloudEventsDrivers (ALPHA - default=false)
103+
// - DefaultClusterSet (ALPHA - default=false)
104+
// - ManagedClusterAutoApproval (ALPHA - default=false)
105+
// - ManifestWorkReplicaSet (ALPHA - default=false)
106+
// - NilExecutorValidating (ALPHA - default=false)
107+
// - ResourceCleanup (BETA - default=true)
108+
// - V1beta1CSRAPICompatibility (ALPHA - default=false)
109+
// +kubebuilder:default:="AddonManagement=true"
110+
// +optional
111+
FeatureGates string `json:"featureGates,omitempty"`
112+
113+
// If set, the cluster manager operator will be purged and the open-cluster-management namespace deleted
114+
// when the FleetConfig CR is deleted.
115+
// +kubebuilder:default:=true
116+
// +optional
117+
PurgeOperator bool `json:"purgeOperator,omitempty"`
118+
119+
// Resource specifications for all clustermanager-managed containers.
120+
// +kubebuilder:default:={}
121+
// +optional
122+
Resources ResourceSpec `json:"resources,omitzero"`
123+
124+
// Version and image registry details for the cluster manager.
125+
// +kubebuilder:default:={}
126+
// +optional
127+
Source OCMSource `json:"source,omitzero"`
128+
129+
// If set, the bootstrap token will used instead of a service account token.
130+
// +optional
131+
UseBootstrapToken bool `json:"useBootstrapToken,omitempty"`
36132
}
37133

38134
// HubStatus defines the observed state of Hub.
39135
type HubStatus struct {
40-
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
41-
// Important: Run "make" to regenerate code after modifying this file
136+
// Phase is the current phase of the Hub reconcile.
137+
Phase string `json:"phase,omitempty"`
138+
139+
// Conditions are the current conditions of the Hub.
140+
Conditions []Condition `json:"conditions,omitempty"`
141+
142+
InstalledHubAddOns []InstalledHubAddOn `json:"installedHubAddOns,omitempty"`
143+
}
144+
145+
// InstalledHubAddOn tracks metadata for each hubAddon that is successfully installed on the hub.
146+
type InstalledHubAddOn struct {
147+
// BundleVersion is the bundle version used when installing the addon.
148+
BundleVersion string `json:"bundleVersion"`
149+
150+
// Name is the name of the addon.
151+
Name string `json:"name"`
152+
153+
// Namespace is the namespace that the addon was installed into.
154+
Namespace string `json:"namespace,omitempty"`
42155
}
43156

44157
// +kubebuilder:object:root=true

0 commit comments

Comments
 (0)