diff --git a/fleetconfig-controller/api/v1alpha1/fleetconfig_types.go b/fleetconfig-controller/api/v1alpha1/fleetconfig_types.go index 887328a4..8584d005 100644 --- a/fleetconfig-controller/api/v1alpha1/fleetconfig_types.go +++ b/fleetconfig-controller/api/v1alpha1/fleetconfig_types.go @@ -29,6 +29,7 @@ type FleetConfigSpec struct { Hub Hub `json:"hub"` Spokes []Spoke `json:"spokes"` RegistrationAuth *RegistrationAuth `json:"registrationAuth,omitempty"` + AddOnConfigs []*AddOnConfig `json:"addOnConfigs,omitempty"` } // FleetConfigStatus defines the observed state of FleetConfig. @@ -306,6 +307,21 @@ type Spoke struct { // ClusterARN is the ARN of the spoke cluster. // This field is optionally used for AWS IRSA registration authentication. ClusterARN string `json:"clusterARN,omitempty"` + + // AddOns are the add-ons to enable for the spoke cluster. + AddOns []AddOn `json:"addOns,omitempty"` +} + +// AddOn enables add-on installation on the cluster. +type AddOn struct { + // The name of the add-on being enabled. Must match one of the default or manually configured add-on names. + ConfigName string `json:"configName"` + + // The namespace to install the add-on in. If left empty, installs into the "open-cluster-management-addon" namespace. + InstallNamespace string `json:"installNamespace,omitempty"` + + // Optional annotations to apply to the add-on. + Annotations map[string]string `json:"annotations,omitempty"` } // JoinType returns a status condition type indicating that a particular Spoke cluster has joined the Hub. @@ -450,6 +466,31 @@ type RegistrationAuth struct { AutoApprovedARNPatterns []string `json:"autoApprovedARNPatterns,omitempty"` } +// AddOnConfig is the configuration of a custom AddOn that can be installed on a cluster. +type AddOnConfig struct { + // The name of the add-on. + Name string `json:"name"` + + // The add-on version. Optional, defaults to "v0.0.1" + // +optional + // +kubebuilder:default:="v0.0.1" + Version string `json:"version,omitempty"` + + // The rolebinding to the clusterrole in the cluster namespace for the addon agent + // +optional + ClusterRoleBinding string `json:"clusterRoleBinding,omitempty"` + + // Enable the agent to register to the hub cluster. Optional, defaults to false. + // +optional + // +kubebuilder:default:=false + HubRegistration bool `json:"hubRegistration,omitempty"` + + // Whether to overwrite the add-on if it already exists. Optional, defaults to false. + // +optional + // +kubebuilder:default:=false + Overwrite bool `json:"overwrite,omitempty"` +} + // +kubebuilder:object:root=true // +kubebuilder:subresource:status // +kubebuilder:printcolumn:name="PHASE",type=string,JSONPath=`.status.phase` diff --git a/fleetconfig-controller/api/v1alpha1/zz_generated.deepcopy.go b/fleetconfig-controller/api/v1alpha1/zz_generated.deepcopy.go index e6141432..8cb8345d 100644 --- a/fleetconfig-controller/api/v1alpha1/zz_generated.deepcopy.go +++ b/fleetconfig-controller/api/v1alpha1/zz_generated.deepcopy.go @@ -24,6 +24,43 @@ import ( "k8s.io/apimachinery/pkg/runtime" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AddOn) DeepCopyInto(out *AddOn) { + *out = *in + if in.Annotations != nil { + in, out := &in.Annotations, &out.Annotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AddOn. +func (in *AddOn) DeepCopy() *AddOn { + if in == nil { + return nil + } + out := new(AddOn) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AddOnConfig) DeepCopyInto(out *AddOnConfig) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AddOnConfig. +func (in *AddOnConfig) DeepCopy() *AddOnConfig { + if in == nil { + return nil + } + out := new(AddOnConfig) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterManager) DeepCopyInto(out *ClusterManager) { *out = *in @@ -170,6 +207,17 @@ func (in *FleetConfigSpec) DeepCopyInto(out *FleetConfigSpec) { *out = new(RegistrationAuth) (*in).DeepCopyInto(*out) } + if in.AddOnConfigs != nil { + in, out := &in.AddOnConfigs, &out.AddOnConfigs + *out = make([]*AddOnConfig, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(AddOnConfig) + **out = **in + } + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FleetConfigSpec. @@ -463,6 +511,13 @@ func (in *Spoke) DeepCopyInto(out *Spoke) { (*in).DeepCopyInto(*out) } in.Klusterlet.DeepCopyInto(&out.Klusterlet) + if in.AddOns != nil { + in, out := &in.AddOns, &out.AddOns + *out = make([]AddOn, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Spoke. diff --git a/fleetconfig-controller/charts/fleetconfig-controller/crds/fleetconfig.open-cluster-management.io-crds.yaml b/fleetconfig-controller/charts/fleetconfig-controller/crds/fleetconfig.open-cluster-management.io-crds.yaml index 5b5322c3..30de3a5c 100644 --- a/fleetconfig-controller/charts/fleetconfig-controller/crds/fleetconfig.open-cluster-management.io-crds.yaml +++ b/fleetconfig-controller/charts/fleetconfig-controller/crds/fleetconfig.open-cluster-management.io-crds.yaml @@ -56,6 +56,36 @@ spec: spec: description: FleetConfigSpec defines the desired state of FleetConfig. properties: + addOnConfigs: + items: + description: AddOnConfig is the configuration of a custom AddOn + that can be installed on a cluster. + properties: + clusterRoleBinding: + description: The rolebinding to the clusterrole in the cluster + namespace for the addon agent + type: string + hubRegistration: + default: false + description: Enable the agent to register to the hub cluster. + Optional, defaults to false. + type: boolean + name: + description: The name of the add-on. + type: string + overwrite: + default: false + description: Whether to overwrite the add-on if it already exists. + Optional, defaults to false. + type: boolean + version: + default: v0.0.1 + description: The add-on version. Optional, defaults to "v0.0.1" + type: string + required: + - name + type: object + type: array hub: description: Hub provides specifications for an OCM hub cluster. properties: @@ -281,6 +311,31 @@ spec: description: Spoke provides specifications for joining and potentially upgrading spokes. properties: + addOns: + description: AddOns are the add-ons to enable for the spoke + cluster. + items: + description: AddOn enables add-on installation on the cluster. + properties: + annotations: + additionalProperties: + type: string + description: Optional annotations to apply to the add-on. + type: object + configName: + description: The name of the add-on being enabled. Must + match one of the default or manually configured add-on + names. + type: string + installNamespace: + description: The namespace to install the add-on in. If + left empty, installs into the "open-cluster-management-addon" + namespace. + type: string + required: + - configName + type: object + type: array ca: description: Hub cluster CA certificate, optional type: string diff --git a/fleetconfig-controller/charts/fleetconfig-controller/templates/fleetconfig.yaml b/fleetconfig-controller/charts/fleetconfig-controller/templates/fleetconfig.yaml index 0c1cfc9f..20672067 100644 --- a/fleetconfig-controller/charts/fleetconfig-controller/templates/fleetconfig.yaml +++ b/fleetconfig-controller/charts/fleetconfig-controller/templates/fleetconfig.yaml @@ -60,5 +60,7 @@ spec: source: bundleVersion: {{ $.Values.fleetConfig.source.bundleVersion }} registry: {{ $.Values.fleetConfig.source.registry }} + addOns: {{- toYaml .addOns | nindent 8 }} {{- end }} + addOnConfigs: {{- toYaml .Values.fleetConfig.addOnConfigs | nindent 4 }} {{- end }} diff --git a/fleetconfig-controller/charts/fleetconfig-controller/templates/ocm/add-ons.yaml b/fleetconfig-controller/charts/fleetconfig-controller/templates/ocm/add-ons.yaml new file mode 100644 index 00000000..bd0c0a25 --- /dev/null +++ b/fleetconfig-controller/charts/fleetconfig-controller/templates/ocm/add-ons.yaml @@ -0,0 +1,17 @@ +{{- if .Values.fleetConfig.addOns }} +{{ $addOns := .Values.fleetConfig.addOns }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: fleet-add-ons + namespace: {{ .Release.Namespace }} +data: + {{- range $addOns }} + {{- if or (hasPrefix "http://" .manifests) (hasPrefix "https://" .manifests) (hasPrefix "oci://" .manifests) }} + {{ .name }}: {{ .manifests }} + {{- else }} + {{ .name }}: |- + {{- .manifests | nindent 4 }} + {{- end }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/fleetconfig-controller/charts/fleetconfig-controller/values.yaml b/fleetconfig-controller/charts/fleetconfig-controller/values.yaml index 6ceb8f02..338fcf8f 100644 --- a/fleetconfig-controller/charts/fleetconfig-controller/values.yaml +++ b/fleetconfig-controller/charts/fleetconfig-controller/values.yaml @@ -224,6 +224,29 @@ fleetConfig: # # Options: [ Default | BestEffort | ResourceRequirement ]. # qosClass: "Default" singleton: false + # Add-on configuration for the spoke cluster. + # ## @param fleetConfig.spokes[0].addOns[0].name Name of the add-on. + # ## @param fleetConfig.spokes[0].addOns[0].installNamespace Namespace to install the add-on. + # ## @param fleetConfig.spokes[0].addOns[0].annotations Annotations to apply to the add-on. + # addOns: + # - name: "" + # installNamespace: "" + # annotations: {} + + # Global add-on configuration for the hub cluster. + # ## @param fleetConfig.addOnConfigs[0].name Name of the add-on. + # ## @param fleetConfig.addOnConfigs[0].manifests Manifests to install. Can either be inline or a URL. + # ## @param fleetConfig.addOnConfigs[0].version Version of the add-on. + # ## @param fleetConfig.addOnConfigs[0].clusterRoleBinding Cluster role binding to apply to the add-on. + # ## @param fleetConfig.addOnConfigs[0].hubRegistration Enable the agent to register to the hub cluster. + # ## @param fleetConfig.addOnConfigs[0].overwrite Whether to overwrite the add-on if it already exists. + # addOnConfigs: + # - name: "" + # manifests: "" + # version: "v0.0.1" + # clusterRoleBinding: "" + # hubRegistration: false + # overwrite: false ## @section Topology Resources diff --git a/fleetconfig-controller/config/crd/bases/fleetconfig.open-cluster-management.io_fleetconfigs.yaml b/fleetconfig-controller/config/crd/bases/fleetconfig.open-cluster-management.io_fleetconfigs.yaml index 8f0f64a6..c3292688 100644 --- a/fleetconfig-controller/config/crd/bases/fleetconfig.open-cluster-management.io_fleetconfigs.yaml +++ b/fleetconfig-controller/config/crd/bases/fleetconfig.open-cluster-management.io_fleetconfigs.yaml @@ -46,6 +46,36 @@ spec: spec: description: FleetConfigSpec defines the desired state of FleetConfig. properties: + addOnConfigs: + items: + description: AddOnConfig is the configuration of a custom AddOn + that can be installed on a cluster. + properties: + clusterRoleBinding: + description: The rolebinding to the clusterrole in the cluster + namespace for the addon agent + type: string + hubRegistration: + default: false + description: Enable the agent to register to the hub cluster. + Optional, defaults to false. + type: boolean + name: + description: The name of the add-on. + type: string + overwrite: + default: false + description: Whether to overwrite the add-on if it already exists. + Optional, defaults to false. + type: boolean + version: + default: v0.0.1 + description: The add-on version. Optional, defaults to "v0.0.1" + type: string + required: + - name + type: object + type: array hub: description: Hub provides specifications for an OCM hub cluster. properties: @@ -271,6 +301,31 @@ spec: description: Spoke provides specifications for joining and potentially upgrading spokes. properties: + addOns: + description: AddOns are the add-ons to enable for the spoke + cluster. + items: + description: AddOn enables add-on installation on the cluster. + properties: + annotations: + additionalProperties: + type: string + description: Optional annotations to apply to the add-on. + type: object + configName: + description: The name of the add-on being enabled. Must + match one of the default or manually configured add-on + names. + type: string + installNamespace: + description: The namespace to install the add-on in. If + left empty, installs into the "open-cluster-management-addon" + namespace. + type: string + required: + - configName + type: object + type: array ca: description: Hub cluster CA certificate, optional type: string