Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 14 additions & 30 deletions internal/controller/nova/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ var (

// ErrACSecretMissingKeys indicates that the ApplicationCredential secret is missing required keys
ErrACSecretMissingKeys = errors.New("ApplicationCredential secret missing required keys")
// ErrTemplateDirUnset indicates that no template directory was provided.
ErrTemplateDirUnset = errors.New("templateDir must be set")
)

type conditionsGetter interface {
Expand All @@ -169,32 +171,6 @@ type topologyHandler interface {
SetLastAppliedTopology(t *topologyv1.TopoRef)
}

// getTemplateInstanceType converts the CR Kind to the template directory path.
// templates are in templates/nova/<component>/
// e.g. NovaScheduler -> nova/scheduler, NovaAPI -> nova/api
func getTemplateInstanceType(instance client.Object) string {
kind := instance.GetObjectKind().GroupVersionKind().Kind

// Kind to template dir mapping
switch kind {
case "NovaAPI":
return "nova/api"
case "NovaConductor":
return "nova/conductor"
case "NovaMetadata":
return "nova/metadata"
case "NovaScheduler":
return "nova/scheduler"
case "NovaNoVNCProxy":
return "nova/novncproxy"
case "NovaCompute":
return "nova/compute"
default:
// For other types (like Nova itself), use the kind as it is
return strings.ToLower(kind)
}
}

// ensureTopology - when a Topology CR is referenced, remove the
// finalizer from a previous referenced Topology (if any), and retrieve the
// newly referenced topology object
Expand Down Expand Up @@ -533,20 +509,25 @@ func (r *ReconcilerBase) generateConfigsGeneric(
extraData map[string]string, cmLabels map[string]string,
additionalTemplates map[string]string,
withScripts bool,
templateDir string,
) error {

extraTemplates := map[string]string{
"01-nova.conf": "/nova/nova.conf",
"nova-blank.conf": "/nova/nova-blank.conf",
}
if templateDir == "" {
return ErrTemplateDirUnset
}

maps.Copy(extraTemplates, additionalTemplates)
cms := []util.Template{
{
Name: configName,
Namespace: instance.GetNamespace(),
Type: util.TemplateTypeConfig,
InstanceType: getTemplateInstanceType(instance),
InstanceType: instance.GetObjectKind().GroupVersionKind().Kind,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a NovaCell instance, lib-common will look under a subdir derived from "novacell", not "nova/compute". Is that expected?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks about right, sorry

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np!

MultiTemplateDir: templateDir,
ConfigOptions: templateParameters,
Labels: cmLabels,
CustomData: extraData,
Expand All @@ -559,7 +540,8 @@ func (r *ReconcilerBase) generateConfigsGeneric(
Name: nova.GetScriptSecretName(instance.GetName()),
Namespace: instance.GetNamespace(),
Type: util.TemplateTypeScripts,
InstanceType: getTemplateInstanceType(instance),
InstanceType: instance.GetObjectKind().GroupVersionKind().Kind,
MultiTemplateDir: templateDir,
AdditionalTemplate: map[string]string{},
Annotations: map[string]string{},
Labels: cmLabels,
Expand All @@ -575,10 +557,11 @@ func (r *ReconcilerBase) GenerateConfigs(
templateParameters map[string]any,
extraData map[string]string, cmLabels map[string]string,
additionalTemplates map[string]string,
templateDir string,
) error {
return r.generateConfigsGeneric(
ctx, h, instance, configName, envVars, templateParameters, extraData,
cmLabels, additionalTemplates, false,
cmLabels, additionalTemplates, false, templateDir,
)
}

Expand All @@ -590,11 +573,12 @@ func (r *ReconcilerBase) GenerateConfigsWithScripts(
templateParameters map[string]any,
extraData map[string]string, cmLabels map[string]string,
additionalTemplates map[string]string,
templateDir string,
) error {
return r.generateConfigsGeneric(
ctx, h, instance, nova.GetServiceConfigSecretName(instance.GetName()),
envVars, templateParameters, extraData,
cmLabels, additionalTemplates, true,
cmLabels, additionalTemplates, true, templateDir,
)
}

Expand Down
34 changes: 19 additions & 15 deletions internal/controller/nova/nova_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import (

novav1 "github.com/openstack-k8s-operators/nova-operator/api/nova/v1beta1"
"github.com/openstack-k8s-operators/nova-operator/internal/nova"
"github.com/openstack-k8s-operators/nova-operator/internal/nova/api"
novaapi "github.com/openstack-k8s-operators/nova-operator/internal/nova/api"
Comment thread
gibizer marked this conversation as resolved.

memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1"
rabbitmqv1 "github.com/openstack-k8s-operators/infra-operator/apis/rabbitmq/v1beta1"
Expand Down Expand Up @@ -1143,17 +1143,19 @@ func (r *NovaReconciler) ensureNovaManageJobSecret(

cms := []util.Template{
{
Name: scriptName,
Namespace: instance.Namespace,
Type: util.TemplateTypeScripts,
InstanceType: "nova/nova-manage",
Labels: cmLabels,
Name: scriptName,
Namespace: instance.Namespace,
Type: util.TemplateTypeScripts,
InstanceType: instance.GetObjectKind().GroupVersionKind().Kind,
MultiTemplateDir: "nova/nova-manage",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yepp this is the correct use of the new interface.

Explicit is better than implicit.
Simple is better than complex.

Labels: cmLabels,
},
{
Name: configName,
Namespace: instance.Namespace,
Type: util.TemplateTypeConfig,
InstanceType: "nova/nova-manage",
InstanceType: instance.GetObjectKind().GroupVersionKind().Kind,
MultiTemplateDir: "nova/nova-manage",
ConfigOptions: templateParameters,
Labels: cmLabels,
CustomData: extraData,
Expand Down Expand Up @@ -2142,10 +2144,11 @@ func (r *NovaReconciler) ensureCellSecret(
)

template := util.Template{
Name: secretName,
Namespace: instance.Namespace,
Type: util.TemplateTypeNone,
InstanceType: getTemplateInstanceType(instance),
Name: secretName,
Namespace: instance.Namespace,
Type: util.TemplateTypeNone,
// No MultiTemplateDir: TemplateTypeNone does not load templates from a directory.
InstanceType: instance.GetObjectKind().GroupVersionKind().Kind,
Labels: labels,
CustomData: data,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we are not loading any template from file here hence we don't need to pass a templateDir. If I'm correct then a comment would be nice here about it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In lib-common, we do not check InstanceType (old logic) or MultiTemplateDir (new change) if template type is none.
Ref: https://github.com/amartyasinha/lib-common/blob/135bf0acdeafc623f9f9f855ca6850748664ff69/modules/common/util/template_util.go#L297

Will add a comment in there in code to clarify.

}
Expand Down Expand Up @@ -2202,10 +2205,11 @@ func (r *NovaReconciler) ensureTopLevelSecret(
)

template := util.Template{
Name: secretName,
Namespace: instance.Namespace,
Type: util.TemplateTypeNone,
InstanceType: getTemplateInstanceType(instance),
Name: secretName,
Namespace: instance.Namespace,
Type: util.TemplateTypeNone,
// No MultiTemplateDir: TemplateTypeNone does not load templates from a directory.
InstanceType: instance.GetObjectKind().GroupVersionKind().Kind,
Labels: labels,
CustomData: data,
}
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/nova/novaapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ func (r *NovaAPIReconciler) generateConfigs(

err = r.GenerateConfigs(
ctx, h, instance, nova.GetServiceConfigSecretName(instance.GetName()),
hashes, templateParameters, extraData, cmLabels, map[string]string{},
hashes, templateParameters, extraData, cmLabels, map[string]string{}, "nova/api",
)
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/nova/novacell_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ func (r *NovaCellReconciler) generateComputeConfigs(

configName := instance.GetName() + "-compute-config"
err := r.GenerateConfigs(
ctx, h, instance, configName, &hashes, templateParameters, extraData, cmLabels, map[string]string{},
ctx, h, instance, configName, &hashes, templateParameters, extraData, cmLabels, map[string]string{}, "nova/compute",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I see that this resolved the 'novacell' mismatching behavior I thought still takes place

)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/nova/novacompute_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func (r *NovaComputeReconciler) generateConfigs(
)

err := r.GenerateConfigs(
ctx, h, instance, nova.GetServiceConfigSecretName(instance.GetName()), hashes, templateParameters, extraData, cmLabels, map[string]string{},
ctx, h, instance, nova.GetServiceConfigSecretName(instance.GetName()), hashes, templateParameters, extraData, cmLabels, map[string]string{}, "nova/compute",
)
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/nova/novaconductor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ func (r *NovaConductorReconciler) generateConfigs(
instance, labels.GetGroupLabel(NovaConductorLabelPrefix), map[string]string{})

return r.GenerateConfigsWithScripts(
ctx, h, instance, hashes, templateParameters, extraData, cmLabels, map[string]string{},
ctx, h, instance, hashes, templateParameters, extraData, cmLabels, map[string]string{}, "nova/conductor",
)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/controller/nova/novametadata_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ func (r *NovaMetadataReconciler) generateConfigs(

err = r.GenerateConfigs(
ctx, h, instance, nova.GetServiceConfigSecretName(instance.GetName()),
hashes, templateParameters, extraData, cmLabels, map[string]string{},
hashes, templateParameters, extraData, cmLabels, map[string]string{}, "nova/metadata",
)
return err
}
Expand Down Expand Up @@ -898,7 +898,7 @@ func (r *NovaMetadataReconciler) generateNeutronConfigs(
Name: configName,
Namespace: instance.GetNamespace(),
Type: util.TemplateTypeNone,
InstanceType: getTemplateInstanceType(instance),
InstanceType: instance.GetObjectKind().GroupVersionKind().Kind,
ConfigOptions: templateParameters,
Labels: labels,
AdditionalTemplate: templates,
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/nova/novanovncproxy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ func (r *NovaNoVNCProxyReconciler) generateConfigs(

err = r.GenerateConfigs(
ctx, h, instance, nova.GetServiceConfigSecretName(instance.GetName()),
hashes, templateParameters, extraData, cmLabels, map[string]string{},
hashes, templateParameters, extraData, cmLabels, map[string]string{}, "nova/novncproxy",
)
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/nova/novascheduler_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ func (r *NovaSchedulerReconciler) generateConfigs(

return r.GenerateConfigs(
ctx, h, instance, nova.GetServiceConfigSecretName(instance.GetName()),
hashes, templateParameters, extraData, cmLabels, map[string]string{},
hashes, templateParameters, extraData, cmLabels, map[string]string{}, "nova/scheduler",
)
}

Expand Down
Loading