Skip to content

Commit

Permalink
Allow specifying the volume label on configmaps and secrets
Browse files Browse the repository at this point in the history
Allows supporting different bootstrap solutions without having explicit
support for them. For instance right now we don't have a special
kickstart volume. If we would already allow setting volume labels people
could just use configmaps and secrets right now without explicit
support.

Signed-off-by: Roman Mohr <[email protected]>
  • Loading branch information
rmohr committed Apr 15, 2020
1 parent 646cc4b commit e66549f
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 15 deletions.
8 changes: 8 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4549,6 +4549,10 @@
"optional": {
"description": "Specify whether the ConfigMap or it's keys must be defined\n+optional",
"type": "boolean"
},
"volumeLabel": {
"description": "The volume label of the resulting disk inside the VMI.\nDifferent bootstrapping mechanisms require different values.\nTypical values are \"cidata\" (cloud-init), \"config-2\" (cloud-init) or \"OEMDRV\" (kickstart).\n+optional",
"type": "string"
}
}
},
Expand Down Expand Up @@ -5961,6 +5965,10 @@
"secretName": {
"description": "Name of the secret in the pod's namespace to use.\nMore info: https://kubernetes.io/docs/concepts/storage/volumes#secret\n+optional",
"type": "string"
},
"volumeLabel": {
"description": "The volume label of the resulting disk inside the VMI.\nDifferent bootstrapping mechanisms require different values.\nTypical values are \"cidata\" (cloud-init), \"config-2\" (cloud-init) or \"OEMDRV\" (kickstart).\n+optional",
"type": "string"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config-map.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func CreateConfigMapDisks(vmi *v1.VirtualMachineInstance) error {
}

disk := GetConfigMapDiskPath(volume.Name)
if err := createIsoConfigImage(disk, filesPath); err != nil {
if err := createIsoConfigImage(disk, volume.ConfigMap.VolumeLabel, filesPath); err != nil {
return err
}

Expand Down
15 changes: 10 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type (
// Type represents allowed config types like ConfigMap or Secret
Type string

isoCreationFunc func(output string, files []string) error
isoCreationFunc func(output string, volID string, files []string) error
)

const (
Expand Down Expand Up @@ -84,12 +84,17 @@ func getFilesLayout(dirPath string) ([]string, error) {
return filesPath, nil
}

func defaultCreateIsoImage(output string, files []string) error {
func defaultCreateIsoImage(output string, volID string, files []string) error {

if volID == "" {
volID = "cfgdata"
}

var args []string
args = append(args, "-output")
args = append(args, output)
args = append(args, "-volid")
args = append(args, "cfgdata")
args = append(args, volID)
args = append(args, "-joliet")
args = append(args, "-rock")
args = append(args, "-graft-points")
Expand All @@ -103,8 +108,8 @@ func defaultCreateIsoImage(output string, files []string) error {
return nil
}

func createIsoConfigImage(output string, files []string) error {
err := createISOImage(output, files)
func createIsoConfigImage(output string, volID string, files []string) error {
err := createISOImage(output, volID, files)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
. "github.com/onsi/gomega"
)

func mockCreateISOImage(output string, files []string) error {
func mockCreateISOImage(output string, volID string, files []string) error {
_, err := os.Create(output)
if err != nil {
panic(err)
Expand Down Expand Up @@ -73,7 +73,7 @@ var _ = Describe("Creating config images", func() {

It("Should create an iso image", func() {
imgPath := filepath.Join(tempISODir, "volume1.iso")
err := createIsoConfigImage(imgPath, expectedLayout)
err := createIsoConfigImage(imgPath, "", expectedLayout)
Expect(err).NotTo(HaveOccurred())
_, err = os.Stat(imgPath)
Expect(err).NotTo(HaveOccurred())
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func CreateSecretDisks(vmi *v1.VirtualMachineInstance) error {
}

disk := GetSecretDiskPath(volume.Name)
if err := createIsoConfigImage(disk, filesPath); err != nil {
if err := createIsoConfigImage(disk, volume.Secret.VolumeLabel, filesPath); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/config/service-account.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func CreateServiceAccountDisk(vmi *v1.VirtualMachineInstance) error {
}

disk := GetServiceAccountDiskPath()
if err := createIsoConfigImage(disk, filesPath); err != nil {
if err := createIsoConfigImage(disk, "", filesPath); err != nil {
return err
}

Expand Down
14 changes: 14 additions & 0 deletions staging/src/kubevirt.io/client-go/api/v1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions staging/src/kubevirt.io/client-go/api/v1/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ type ConfigMapVolumeSource struct {
// Specify whether the ConfigMap or it's keys must be defined
// +optional
Optional *bool `json:"optional,omitempty"`
// The volume label of the resulting disk inside the VMI.
// Different bootstrapping mechanisms require different values.
// Typical values are "cidata" (cloud-init), "config-2" (cloud-init) or "OEMDRV" (kickstart).
// +optional
VolumeLabel string `json:"volumeLabel,omitempty"`
}

// SecretVolumeSource adapts a Secret into a volume.
Expand All @@ -79,6 +84,11 @@ type SecretVolumeSource struct {
// Specify whether the Secret or it's keys must be defined
// +optional
Optional *bool `json:"optional,omitempty"`
// The volume label of the resulting disk inside the VMI.
// Different bootstrapping mechanisms require different values.
// Typical values are "cidata" (cloud-init), "config-2" (cloud-init) or "OEMDRV" (kickstart).
// +optional
VolumeLabel string `json:"volumeLabel,omitempty"`
}

// ServiceAccountVolumeSource adapts a ServiceAccount into a volume.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e66549f

Please sign in to comment.