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 35a2e60
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 21 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,
})
}
7 changes: 4 additions & 3 deletions cmd/pro/provider/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ func (cmd *UpCmd) Run(ctx context.Context) error {
if version == "latest" {
version = ""
}

environmentTemplate := os.GetEnv(loft.EnvironmentTemplateOptionEnv)

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

View workflow job for this annotation

GitHub Actions / test-e2e-windows (build)

undefined: os.GetEnv

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

View workflow job for this annotation

GitHub Actions / test-e2e-windows (build)

undefined: os.GetEnv

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

View workflow job for this annotation

GitHub Actions / unit-tests

undefined: os.GetEnv

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

View workflow job for this annotation

GitHub Actions / lint

undefined: os.GetEnv

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

View workflow job for this annotation

GitHub Actions / lint

undefined: os.GetEnv
// set template and version
workspace.Spec.TemplateRef = &storagev1.TemplateRef{
Name: template,
Version: version,
Name: template,
Version: version,
Environment: environmentTemplate,

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

View workflow job for this annotation

GitHub Actions / test-e2e-windows (build)

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

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

View workflow job for this annotation

GitHub Actions / test-e2e-windows (build)

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

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

View workflow job for this annotation

GitHub Actions / unit-tests

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

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

View workflow job for this annotation

GitHub Actions / lint

unknown field Environment in struct literal of type "github.com/loft-sh/api/v4/pkg/apis/storage/v1".TemplateRef (typecheck)

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

View workflow job for this annotation

GitHub Actions / lint

unknown field Environment in struct literal of type "github.com/loft-sh/api/v4/pkg/apis/storage/v1".TemplateRef) (typecheck)
}

// find parameters for template
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 35a2e60

Please sign in to comment.