Files
nomad/command/volume_create_csi.go
Allison Larson e16a3339ad Add CSI Volume Sentinel Policy scaffolding (#26438)
* Add ent policy enforcement stubs to CSI Volume create/register

* Wire policy override/warnings through CSI volume register/create

* Add new scope to sentinel apply

* Sanitize CSISecrets & CSIMountOptions

* Add sentinel policy scope to ui

* Update docs for new sentinel scope/policy

* Create new api funcs for CSI endpoints

* fix sentinel csi ui test

* Update sentinel-policy docs

* Add changelog

* Update docs from feedback
2025-08-07 12:03:18 -07:00

43 lines
1021 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package command
import (
"fmt"
"github.com/hashicorp/hcl/hcl/ast"
"github.com/hashicorp/nomad/api"
)
func (c *VolumeCreateCommand) csiCreate(client *api.Client, ast *ast.File, override bool) int {
vol, err := csiDecodeVolume(ast)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error decoding the volume definition: %s", err))
return 1
}
resp, _, err := client.CSIVolumes().CreateOpts(&api.CSIVolumeCreateRequest{
Volumes: []*api.CSIVolume{vol},
PolicyOverride: override,
}, nil)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error creating volume: %s", err))
return 1
}
if resp.Warnings != "" {
c.Ui.Output(
c.Colorize().Color(
fmt.Sprintf("[bold][yellow]Volume Warnings:\n%s[reset]\n", resp.Warnings)))
}
for _, vol := range resp.Volumes {
// note: the command only ever returns 1 volume from the API
c.Ui.Output(fmt.Sprintf(
"Created external volume %s with ID %s", vol.ExternalID, vol.ID))
}
return 0
}