Skip to content

Commit

Permalink
Add environment template to pro provider options
Browse files Browse the repository at this point in the history
  • Loading branch information
janekbaraniewski committed Sep 19, 2024
1 parent 742f54d commit d879125
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 18 deletions.
62 changes: 44 additions & 18 deletions cmd/pro/provider/list/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,50 @@ func (cmd *TemplatesCmd) Run(ctx context.Context) error {
return cmp.Compare(a.Value, b.Value)
})

return printOptions(&OptionsFormat{
Options: map[string]*types.Option{
loft.RunnerEnv: {
DisplayName: "Runner",
Description: "The DevPod Pro runner to use for a new workspace.",
Enum: runners,
Required: true,
Mutable: false,
},
loft.TemplateOptionEnv: {
DisplayName: "Template",
Description: "The template to use for a new workspace.",
Required: true,
Enum: templates,
Default: templateList.DefaultDevPodWorkspaceTemplate,
SubOptionsCommand: fmt.Sprintf("'%s' pro provider list templateoptions", executable),
Mutable: true,
},
//collect environments
environmentsList, err := managementClient.Loft().ManagementV1().DevPodEnvironmentTemplates().List(ctx, metav1.ListOptions{})
if err != nil {
return fmt.Errorf("list environments: %w", err)
}

environments := []types.OptionEnum{}
for _, env := range environmentsList.Items {
environments = append(environments, types.OptionEnum{
Value: env.Name,
DisplayName: loft.DisplayName(env.Name, env.Spec.DisplayName),
})
}

options := map[string]*types.Option{
loft.RunnerEnv: {
DisplayName: "Runner",
Description: "The DevPod Pro runner to use for a new workspace.",
Enum: runners,
Required: true,
Mutable: false,
},
loft.TemplateOptionEnv: {
DisplayName: "Template",
Description: "The template to use for a new workspace.",
Required: true,
Enum: templates,
Default: templateList.DefaultDevPodWorkspaceTemplate,
SubOptionsCommand: fmt.Sprintf("'%s' pro provider list templateoptions", executable),
Mutable: true,
},
}

if len(environments) > 0 {
options[loft.EnvironmentTemplateOptionEnv] = &types.Option{
DisplayName: "Environment Template",
Description: "The template to use for creating environment",
Enum: environments,
Required: true,
Mutable: false,
}
}

return printOptions(&OptionsFormat{
Options: options,
})
}
5 changes: 5 additions & 0 deletions cmd/pro/provider/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ func createWorkspace(ctx context.Context, baseClient client.Client, log log.Logg
templateVersion = ""
}

environmentName := os.Getenv(loft.EnvironmentTemplateOptionEnv)

// find parameters
resolvedParameters, err := getParametersFromEnvironment(ctx, managementClient, workspaceInfo.ProjectName, template, templateVersion)
if err != nil {
Expand Down Expand Up @@ -239,6 +241,9 @@ func createWorkspace(ctx context.Context, baseClient client.Client, log log.Logg
Name: template,
Version: templateVersion,
},
EnvironmentRef: storagev1.EnvironmentRef{

Check failure on line 244 in cmd/pro/provider/up.go

View workflow job for this annotation

GitHub Actions / test-e2e-windows (build)

unknown field EnvironmentRef in struct literal of type "github.com/loft-sh/api/v4/pkg/apis/storage/v1".DevPodWorkspaceInstanceSpec

Check failure on line 244 in cmd/pro/provider/up.go

View workflow job for this annotation

GitHub Actions / test-e2e-windows (build)

undefined: storagev1.EnvironmentRef

Check failure on line 244 in cmd/pro/provider/up.go

View workflow job for this annotation

GitHub Actions / test-e2e-windows (build)

unknown field EnvironmentRef in struct literal of type "github.com/loft-sh/api/v4/pkg/apis/storage/v1".DevPodWorkspaceInstanceSpec

Check failure on line 244 in cmd/pro/provider/up.go

View workflow job for this annotation

GitHub Actions / test-e2e-windows (build)

undefined: storagev1.EnvironmentRef

Check failure on line 244 in cmd/pro/provider/up.go

View workflow job for this annotation

GitHub Actions / unit-tests

unknown field EnvironmentRef in struct literal of type "github.com/loft-sh/api/v4/pkg/apis/storage/v1".DevPodWorkspaceInstanceSpec

Check failure on line 244 in cmd/pro/provider/up.go

View workflow job for this annotation

GitHub Actions / unit-tests

undefined: storagev1.EnvironmentRef

Check failure on line 244 in cmd/pro/provider/up.go

View workflow job for this annotation

GitHub Actions / lint

unknown field EnvironmentRef in struct literal of type "github.com/loft-sh/api/v4/pkg/apis/storage/v1".DevPodWorkspaceInstanceSpec

Check failure on line 244 in cmd/pro/provider/up.go

View workflow job for this annotation

GitHub Actions / lint

undefined: storagev1.EnvironmentRef (typecheck)

Check failure on line 244 in cmd/pro/provider/up.go

View workflow job for this annotation

GitHub Actions / lint

unknown field EnvironmentRef in struct literal of type "github.com/loft-sh/api/v4/pkg/apis/storage/v1".DevPodWorkspaceInstanceSpec

Check failure on line 244 in cmd/pro/provider/up.go

View workflow job for this annotation

GitHub Actions / lint

undefined: storagev1.EnvironmentRef) (typecheck)
Name: environmentName,
},
},
},
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/loft/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ const (
TemplateOptionEnv = "LOFT_TEMPLATE"
TemplateVersionOptionEnv = "LOFT_TEMPLATE_VERSION"

EnvironmentTemplateOptionEnv = "LOFT_ENVIRONMENT_TEMPLATE"

TimeoutEnv = "LOFT_TIMEOUT"
)

0 comments on commit d879125

Please sign in to comment.