Skip to content
Merged
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
7 changes: 2 additions & 5 deletions pkg/blueprint/templates/aws.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ local terraformConfig = [
}
];

// Determine the blueprint, defaulting to an empty string if not defined
local blueprint = if std.objectHas(context, "blueprint") then context.blueprint else "";

// Kustomize configuration
local kustomizeConfig = if blueprint == "full" then [
local kustomizeConfig = [
{
name: "telemetry-base",
source: "core",
Expand Down Expand Up @@ -151,7 +148,7 @@ local kustomizeConfig = if blueprint == "full" then [
"grafana/flux"
],
}
] else [];
];

// Blueprint metadata
local blueprintMetadata = {
Expand Down
7 changes: 2 additions & 5 deletions pkg/blueprint/templates/azure.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ local terraformConfig = [
}
];

// Determine the blueprint, defaulting to an empty string if not defined
local blueprint = if std.objectHas(context, "blueprint") then context.blueprint else "";

// Kustomize configuration
local kustomizeConfig = if blueprint == "full" then [
local kustomizeConfig = [
{
name: "telemetry-base",
source: "core",
Expand Down Expand Up @@ -149,7 +146,7 @@ local kustomizeConfig = if blueprint == "full" then [
"grafana/flux"
],
}
] else [];
];

// Blueprint metadata
local blueprintMetadata = {
Expand Down
7 changes: 2 additions & 5 deletions pkg/blueprint/templates/local.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,8 @@ local terraformConfig = [
}
];

// Determine the blueprint, defaulting to an empty string if not defined
local blueprint = if std.objectHas(context, "blueprint") then context.blueprint else "";

// Kustomize configuration
local kustomizeConfig = if blueprint == "full" then [
local kustomizeConfig = [
{
name: "telemetry-base",
source: "core",
Expand Down Expand Up @@ -379,7 +376,7 @@ local kustomizeConfig = if blueprint == "full" then [
"grafana/flux"
],
}
] else [];
];

// Blueprint metadata
local blueprintMetadata = {
Expand Down
7 changes: 2 additions & 5 deletions pkg/blueprint/templates/metal.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,8 @@ local terraformConfig = [
}
];

// Determine the blueprint, defaulting to an empty string if not defined
local blueprint = if std.objectHas(context, "blueprint") then context.blueprint else "";

// Kustomize configuration
local kustomizeConfig = if blueprint == "full" then [
local kustomizeConfig = [
{
name: "telemetry-base",
source: "core",
Expand Down Expand Up @@ -346,7 +343,7 @@ local kustomizeConfig = if blueprint == "full" then [
"grafana/flux"
],
}
] else [];
];

// Blueprint metadata
local blueprintMetadata = {
Expand Down
4 changes: 4 additions & 0 deletions pkg/pipelines/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func (p *InstallPipeline) Execute(ctx context.Context) error {
return fmt.Errorf("No blueprint handler found")
}

if err := p.blueprintHandler.LoadConfig(); err != nil {
return fmt.Errorf("Error loading blueprint config: %w", err)
}

if err := p.blueprintHandler.Install(); err != nil {
return fmt.Errorf("Error installing blueprint: %w", err)
}
Expand Down
70 changes: 70 additions & 0 deletions pkg/pipelines/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,74 @@ func TestInstallPipeline_Execute(t *testing.T) {
t.Errorf("Expected blueprint wait error, got %q", err.Error())
}
})

t.Run("LoadsBlueprintConfigBeforeInstall", func(t *testing.T) {
// Given a pipeline with blueprint handler
pipeline, mocks := setup(t)

loadConfigCalled := false
installCalled := false
var callOrder []string

// Track the order of method calls
mocks.BlueprintHandler.LoadConfigFunc = func() error {
loadConfigCalled = true
callOrder = append(callOrder, "LoadConfig")
return nil
}

mocks.BlueprintHandler.InstallFunc = func() error {
installCalled = true
callOrder = append(callOrder, "Install")
return nil
}

// When Execute is called
err := pipeline.Execute(context.Background())

// Then no error should be returned
if err != nil {
t.Errorf("Expected no error, got %v", err)
}

// And LoadConfig should be called before Install
if !loadConfigCalled {
t.Error("Expected LoadConfig to be called")
}
if !installCalled {
t.Error("Expected Install to be called")
}

// And LoadConfig should be called before Install
if len(callOrder) != 2 {
t.Errorf("Expected 2 method calls, got %d", len(callOrder))
}
if callOrder[0] != "LoadConfig" {
t.Errorf("Expected LoadConfig to be called first, got %s", callOrder[0])
}
if callOrder[1] != "Install" {
t.Errorf("Expected Install to be called second, got %s", callOrder[1])
}
})

t.Run("ReturnsErrorWhenBlueprintLoadConfigFails", func(t *testing.T) {
// Given a pipeline with failing blueprint LoadConfig
pipeline, mocks := setup(t)

// Override blueprint handler to return error during LoadConfig
mocks.BlueprintHandler.LoadConfigFunc = func() error {
return fmt.Errorf("blueprint load config failed")
}

// When Execute is called
err := pipeline.Execute(context.Background())

// Then an error should be returned
if err == nil {
t.Fatal("Expected error, got nil")
}
if err.Error() != "Error loading blueprint config: blueprint load config failed" {
t.Errorf("Expected blueprint load config error, got %q", err.Error())
}
})
}
Loading