Skip to content

Commit

Permalink
nodepool-builder: enable log level selection in the CRD
Browse files Browse the repository at this point in the history
Change-Id: I094e128cc7592275fc5a150ccb694a8f6e62f13c
  • Loading branch information
morucci committed Oct 5, 2023
1 parent 9f96eb7 commit cf28946
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 22 deletions.
16 changes: 11 additions & 5 deletions api/v1/softwarefactory_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -240,8 +249,6 @@ spec:
required:
- size
type: object
required:
- storage
type: object
launcher:
properties:
Expand Down
46 changes: 34 additions & 12 deletions controllers/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions controllers/static/nodepool/logging.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit cf28946

Please sign in to comment.