Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor and simplify the config and script template #8902

Merged
merged 17 commits into from
Feb 20, 2025
Merged
67 changes: 67 additions & 0 deletions apis/apps/v1/componentdefinition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,24 @@ type ComponentDefinitionSpec struct {
// +optional
Services []ComponentService `json:"services,omitempty"`

// Specifies the config file templates and volume mount parameters used by the Component.
//
// This field specifies a list of templates that will be rendered into Component containers' config files.
// Each template is represented as a ConfigMap and may contain multiple config files, with each file being a key in the ConfigMap.
//
// This field is immutable.
//
// +optional
Configs2 []ComponentFileTemplate `json:"configs2,omitempty"`

// Specifies groups of scripts, each provided via a ConfigMap, to be mounted as volumes in the container.
// These scripts can be executed during container startup or via specific actions.
//
// This field is immutable.
//
// +optional
Scripts2 []ComponentFileTemplate `json:"scripts2,omitempty"`

// Specifies the configuration file templates and volume mount parameters used by the Component.
// It also includes descriptions of the parameters in the ConfigMaps, such as value range limitations.
//
Expand Down Expand Up @@ -1016,6 +1034,55 @@ type HostNetworkContainerPort struct {
Ports []string `json:"ports"`
}

type ComponentFileTemplate struct {
// Specifies the name of the template.
//
// +kubebuilder:validation:Required
// +kubebuilder:validation:MaxLength=63
// +kubebuilder:validation:Pattern:=`^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$`
Name string `json:"name"`

// Specifies the name of the referenced template ConfigMap object.
//
// +kubebuilder:validation:MaxLength=63
// +kubebuilder:validation:Pattern:=`^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$`
// +optional
Template string `json:"template,omitempty"`

// Specifies the namespace of the referenced template ConfigMap object.
//
// +kubebuilder:validation:MaxLength=63
// +kubebuilder:validation:Pattern:=`^[a-z0-9]([a-z0-9\-]*[a-z0-9])?$`
// +kubebuilder:default="default"
// +optional
Namespace string `json:"namespace,omitempty"`

// Refers to the volume name of PodTemplate. The file produced through the template will be mounted to
// the corresponding volume. Must be a DNS_LABEL name.
// The volume name must be defined in podSpec.containers[*].volumeMounts.
//
// +kubebuilder:validation:MaxLength=63
// +kubebuilder:validation:Pattern:=`^[a-z]([a-z0-9\-]*[a-z0-9])?$`
// +optional
VolumeName string `json:"volumeName,omitempty"`

// The operator attempts to set default file permissions (0444).
//
// Must be specified as an octal value between 0000 and 0777 (inclusive),
// or as a decimal value between 0 and 511 (inclusive).
// YAML supports both octal and decimal values for file permissions.
//
// Please note that this setting only affects the permissions of the files themselves.
// Directories within the specified path are not impacted by this setting.
// It's important to be aware that this setting might conflict with other options
// that influence the file mode, such as fsGroup.
// In such cases, the resulting file mode may have additional bits set.
// Refers to documents of k8s.ConfigMapVolumeSource.defaultMode for more information.
//
// +optional
DefaultMode *int32 `json:"defaultMode,omitempty"`
}

type ComponentTemplateSpec struct {
// Specifies the name of the configuration template.
//
Expand Down
35 changes: 31 additions & 4 deletions apis/apps/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,25 +452,52 @@ type ProvisionSecretRef struct {
Password string `json:"password,omitempty"`
}

// ClusterComponentConfig represents a config with its source bound.
// ClusterComponentConfig represents a configuration for a component.
type ClusterComponentConfig struct {
// The name of the config.
//
// +kubebuilder:validation:MaxLength=63
// +kubebuilder:validation:Pattern:=`^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$`
// +optional
Name *string `json:"name,omitempty"`

// The source of the config.
// Variables are key-value pairs for dynamic configuration values that can be provided by the user.
//
// +optional
Variables map[string]string `json:"variables,omitempty"`

// The external source for the configuration.
ClusterComponentConfigSource `json:",inline"`

// The custom reconfigure action to reload the service configuration whenever changes to this config are detected.
//
// The container executing this action has access to following variables:
//
// - KB_CONFIG_FILES_CREATED: file1,file2...
// - KB_CONFIG_FILES_REMOVED: file1,file2...
// - KB_CONFIG_FILES_UPDATED: file1:checksum1,file2:checksum2...
//
// Note: This field is immutable once it has been set.
//
// +optional
Reconfigure *Action `json:"reconfigure,omitempty"`

// ExternalManaged indicates whether the configuration is managed by an external system.
// When set to true, the controller will use the user-provided template and reconfigure action,
// ignoring the default template and update behavior.
//
// +optional
ExternalManaged *bool `json:"externalManaged,omitempty"`
}

// ClusterComponentConfigSource represents the source of a config.
// ClusterComponentConfigSource represents the source of a configuration for a component.
type ClusterComponentConfigSource struct {
// ConfigMap source for the config.
//
// +optional
ConfigMap *corev1.ConfigMapVolumeSource `json:"configMap,omitempty"`

// TODO: support more diverse sources:
// TODO: additional fields can be added to support other types of sources in the future, such as:
// - Config template of other components within the same cluster
// - Config template of components from other clusters
// - Secret
Expand Down
51 changes: 51 additions & 0 deletions apis/apps/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading