diff --git a/api/v1/softwarefactory_types.go b/api/v1/softwarefactory_types.go index 4a457494..d1a4009a 100644 --- a/api/v1/softwarefactory_types.go +++ b/api/v1/softwarefactory_types.go @@ -181,17 +181,23 @@ type NodepoolLauncherSpec struct { LogLevel LogLevel `json:"logLevel,omitempty"` } +type NodepoolBuilderSpec struct { + // Storage related settings + Storage StorageSpec `json:"storage,omitempty"` + // Specify the Log Level of the nodepool launcher process. + // Valid values are: + // - "INFO" (default) + // - "WARN" + // - "DEBUG" + LogLevel LogLevel `json:"logLevel,omitempty"` +} + type NodepoolSpec struct { Launcher NodepoolLauncherSpec `json:"launcher,omitempty"` // Nodepool-builder related settings Builder NodepoolBuilderSpec `json:"builder,omitempty"` } -type NodepoolBuilderSpec struct { - // Storage related settings - Storage StorageSpec `json:"storage"` -} - type ZookeeperSpec struct { Storage StorageSpec `json:"storage"` } diff --git a/config/crd/bases/sf.softwarefactory-project.io_softwarefactories.yaml b/config/crd/bases/sf.softwarefactory-project.io_softwarefactories.yaml index c3e3baba..834fe4b8 100644 --- a/config/crd/bases/sf.softwarefactory-project.io_softwarefactories.yaml +++ b/config/crd/bases/sf.softwarefactory-project.io_softwarefactories.yaml @@ -217,6 +217,15 @@ spec: builder: description: Nodepool-builder related settings properties: + logLevel: + description: 'Specify the Log Level of the nodepool launcher + process. Valid values are: - "INFO" (default) - "WARN" - + "DEBUG"' + enum: + - INFO + - WARN + - DEBUG + type: string storage: description: Storage related settings properties: @@ -240,8 +249,6 @@ spec: required: - size type: object - required: - - storage type: object launcher: properties: diff --git a/controllers/nodepool.go b/controllers/nodepool.go index 4b0d294d..6beff9f0 100644 --- a/controllers/nodepool.go +++ b/controllers/nodepool.go @@ -79,12 +79,31 @@ func (r *SFController) getNodepoolConfigEnvs() []apiv1.EnvVar { } } +func mkLoggingTemplate(logLevel v1.LogLevel) (string, error) { + // Unfortunatly I'm unable to leverage default value set at API validation + selectedLogLevel := v1.InfoLogLevel + if logLevel != "" { + selectedLogLevel = logLevel + } + + loggingConfig, err := utils.ParseString( + loggingConfigTemplate, struct{ LogLevel string }{LogLevel: string(selectedLogLevel)}) + + return loggingConfig, err +} + func (r *SFController) DeployNodepoolBuilder() bool { r.EnsureSSHKeySecret("nodepool-builder-ssh-key") r.setNodepoolTooling() + loggingConfig, _ := mkLoggingTemplate(r.cr.Spec.Nodepool.Builder.LogLevel) + + builderExtraConfigData := make(map[string]string) + builderExtraConfigData["logging.yaml"] = loggingConfig + r.EnsureConfigMap("nodepool-builder-extra-config", builderExtraConfigData) + var mod int32 = 256 // decimal for 0400 octal volumes := []apiv1.Volume{ base.MkVolumeSecret("zookeeper-client-tls"), @@ -101,6 +120,8 @@ func (r *SFController) DeployNodepoolBuilder() bool { }, }, }, + base.MkVolumeCM("nodepool-builder-extra-config-vol", + "nodepool-builder-extra-config-config-map"), } volumeMount := []apiv1.VolumeMount{ @@ -142,13 +163,19 @@ func (r *SFController) DeployNodepoolBuilder() bool { MountPath: "/var/lib/nodepool/.ssh/config", ReadOnly: true, }, + { + Name: "nodepool-builder-extra-config-vol", + SubPath: "logging.yaml", + MountPath: "/etc/nodepool-logging/logging.yaml", + }, } annotations := map[string]string{ - "nodepool.yaml": utils.Checksum([]byte(generateConfigScript)), - "dib-ansible.py": utils.Checksum([]byte(dibAnsibleWrapper)), - "ssh_config": utils.Checksum([]byte(builderSSHConfig)), - "serial": "7", + "nodepool.yaml": utils.Checksum([]byte(generateConfigScript)), + "nodepool-logging.yaml": utils.Checksum([]byte(loggingConfig)), + "dib-ansible.py": utils.Checksum([]byte(dibAnsibleWrapper)), + "ssh_config": utils.Checksum([]byte(builderSSHConfig)), + "serial": "7", } initContainer := base.MkContainer("nodepool-builder-init", BusyboxImage) @@ -178,6 +205,8 @@ func (r *SFController) DeployNodepoolBuilder() bool { nb.Spec.Template.ObjectMeta.Annotations = annotations nb.Spec.Template.Spec.InitContainers = []apiv1.Container{initContainer} nb.Spec.Template.Spec.Volumes = volumes + nb.Spec.Template.Spec.Containers[0].Command = []string{"/usr/local/bin/dumb-init", "--", + "/usr/local/bin/nodepool-builder", "-f", "-l", "/etc/nodepool-logging/logging.yaml"} nb.Spec.Template.Spec.Containers[0].VolumeMounts = volumeMount nb.Spec.Template.Spec.Containers[0].Env = append(r.getNodepoolConfigEnvs(), base.MkEnvVar("HOME", "/var/lib/nodepool")) @@ -206,14 +235,7 @@ func (r *SFController) DeployNodepoolLauncher() bool { r.setNodepoolTooling() - // Unfortunatly I'm unable to leverage default value set at API validation - logLevel := v1.InfoLogLevel - if r.cr.Spec.Nodepool.Launcher.LogLevel != "" { - logLevel = r.cr.Spec.Nodepool.Launcher.LogLevel - } - - loggingConfig, _ := utils.ParseString( - loggingConfigTemplate, struct{ LogLevel string }{LogLevel: string(logLevel)}) + loggingConfig, _ := mkLoggingTemplate(r.cr.Spec.Nodepool.Launcher.LogLevel) launcherExtraConfigData := make(map[string]string) launcherExtraConfigData["logging.yaml"] = loggingConfig diff --git a/controllers/static/nodepool/logging.yaml.tmpl b/controllers/static/nodepool/logging.yaml.tmpl index 3645650b..68282b90 100644 --- a/controllers/static/nodepool/logging.yaml.tmpl +++ b/controllers/static/nodepool/logging.yaml.tmpl @@ -1,8 +1,5 @@ version: 1 formatters: - normal: - class: 'nodepool.logconfig.MultiLineFormatter' - format: "%(asctime)s %(levelname)s %(name)s: %(message)s" console: class: 'nodepool.logconfig.MultiLineFormatter' format: "%(asctime)s %(levelname)7s %(name)s: %(message)s"