Skip to content

Commit

Permalink
Merge pull request kubevirt#2120 from gonzolino/config-drive
Browse files Browse the repository at this point in the history
Extend cloud-init interface and support config drive
  • Loading branch information
Marcin Franczyk authored Jun 6, 2019
2 parents 369aba3 + dfbe846 commit cee5650
Show file tree
Hide file tree
Showing 23 changed files with 1,193 additions and 442 deletions.
33 changes: 33 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4186,6 +4186,35 @@
}
}
},
"v1.CloudInitConfigDriveSource": {
"description": "Represents a cloud-init config drive user data source.\nMore info: https://cloudinit.readthedocs.io/en/latest/topics/datasources/configdrive.html",
"properties": {
"networkData": {
"description": "NetworkData contains config drive inline cloud-init networkdata.\n+ optional",
"type": "string"
},
"networkDataBase64": {
"description": "NetworkDataBase64 contains config drive cloud-init networkdata as a base64 encoded string.\n+ optional",
"type": "string"
},
"networkDataSecretRef": {
"description": "NetworkDataSecretRef references a k8s secret that contains config drive networkdata.\n+ optional",
"$ref": "#/definitions/v1.LocalObjectReference"
},
"secretRef": {
"description": "UserDataSecretRef references a k8s secret that contains config drive userdata.\n+ optional",
"$ref": "#/definitions/v1.LocalObjectReference"
},
"userData": {
"description": "UserData contains config drive inline cloud-init userdata.\n+ optional",
"type": "string"
},
"userDataBase64": {
"description": "UserDataBase64 contains config drive cloud-init userdata as a base64 encoded string.\n+ optional",
"type": "string"
}
}
},
"v1.CloudInitNoCloudSource": {
"description": "Represents a cloud-init nocloud user data source.\nMore info: http://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html",
"properties": {
Expand Down Expand Up @@ -6528,6 +6557,10 @@
"name"
],
"properties": {
"cloudInitConfigDrive": {
"description": "CloudInitConfigDrive represents a cloud-init Config Drive user-data source.\nThe Config Drive data will be added as a disk to the vmi. A proper cloud-init installation is required inside the guest.\nMore info: https://cloudinit.readthedocs.io/en/latest/topics/datasources/configdrive.html\n+optional",
"$ref": "#/definitions/v1.CloudInitConfigDriveSource"
},
"cloudInitNoCloud": {
"description": "CloudInitNoCloud represents a cloud-init NoCloud user-data source.\nThe NoCloud data will be added as a disk to the vmi. A proper cloud-init installation is required inside the guest.\nMore info: http://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html\n+optional",
"$ref": "#/definitions/v1.CloudInitNoCloudSource"
Expand Down
1 change: 1 addition & 0 deletions cmd/example-cloudinit-hook-sidecar/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ go_library(
visibility = ["//visibility:private"],
deps = [
"//pkg/api/v1:go_default_library",
"//pkg/cloud-init:go_default_library",
"//pkg/hooks:go_default_library",
"//pkg/hooks/info:go_default_library",
"//pkg/hooks/v1alpha2:go_default_library",
Expand Down
8 changes: 4 additions & 4 deletions cmd/example-cloudinit-hook-sidecar/cloudinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"google.golang.org/grpc"

v1 "kubevirt.io/kubevirt/pkg/api/v1"
cloudinit "kubevirt.io/kubevirt/pkg/cloud-init"
hooks "kubevirt.io/kubevirt/pkg/hooks"
hooksInfo "kubevirt.io/kubevirt/pkg/hooks/info"
hooksV1alpha2 "kubevirt.io/kubevirt/pkg/hooks/v1alpha2"
Expand Down Expand Up @@ -75,21 +76,20 @@ func (s v1alpha2Server) PreCloudInitIso(ctx context.Context, params *hooksV1alph
}

cloudInitDataJSON := params.GetCloudInitData()
cloudInitData := v1.CloudInitNoCloudSource{}
cloudInitData := cloudinit.CloudInitData{}
err = json.Unmarshal(cloudInitDataJSON, &cloudInitData)
if err != nil {
log.Log.Reason(err).Errorf("Failed to unmarshal given CloudInitNoCloudSource: %s", cloudInitDataJSON)
log.Log.Reason(err).Errorf("Failed to unmarshal given CloudInitData: %s", cloudInitDataJSON)
panic(err)
}

cloudInitData.UserData = "#cloud-config\n"
cloudInitData.UserDataBase64 = ""

response, err := json.Marshal(cloudInitData)
if err != nil {
return &hooksV1alpha2.PreCloudInitIsoResult{
CloudInitData: params.GetCloudInitData(),
}, fmt.Errorf("Failed to marshal CloudInitNoCloudSource: %v", cloudInitData)
}, fmt.Errorf("Failed to marshal CloudInitData: %v", cloudInitData)

}

Expand Down
43 changes: 43 additions & 0 deletions pkg/api/v1/deepcopy_generated.go

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

71 changes: 69 additions & 2 deletions pkg/api/v1/openapi_generated.go

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

30 changes: 30 additions & 0 deletions pkg/api/v1/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,31 @@ type CloudInitNoCloudSource struct {
NetworkData string `json:"networkData,omitempty"`
}

// Represents a cloud-init config drive user data source.
// More info: https://cloudinit.readthedocs.io/en/latest/topics/datasources/configdrive.html
// ---
// +k8s:openapi-gen=true
type CloudInitConfigDriveSource struct {
// UserDataSecretRef references a k8s secret that contains config drive userdata.
// + optional
UserDataSecretRef *v1.LocalObjectReference `json:"secretRef,omitempty"`
// UserDataBase64 contains config drive cloud-init userdata as a base64 encoded string.
// + optional
UserDataBase64 string `json:"userDataBase64,omitempty"`
// UserData contains config drive inline cloud-init userdata.
// + optional
UserData string `json:"userData,omitempty"`
// NetworkDataSecretRef references a k8s secret that contains config drive networkdata.
// + optional
NetworkDataSecretRef *v1.LocalObjectReference `json:"networkDataSecretRef,omitempty"`
// NetworkDataBase64 contains config drive cloud-init networkdata as a base64 encoded string.
// + optional
NetworkDataBase64 string `json:"networkDataBase64,omitempty"`
// NetworkData contains config drive inline cloud-init networkdata.
// + optional
NetworkData string `json:"networkData,omitempty"`
}

// ---
// +k8s:openapi-gen=true
type DomainSpec struct {
Expand Down Expand Up @@ -456,6 +481,11 @@ type VolumeSource struct {
// More info: http://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html
// +optional
CloudInitNoCloud *CloudInitNoCloudSource `json:"cloudInitNoCloud,omitempty"`
// CloudInitConfigDrive represents a cloud-init Config Drive user-data source.
// The Config Drive data will be added as a disk to the vmi. A proper cloud-init installation is required inside the guest.
// More info: https://cloudinit.readthedocs.io/en/latest/topics/datasources/configdrive.html
// +optional
CloudInitConfigDrive *CloudInitConfigDriveSource `json:"cloudInitConfigDrive,omitempty"`
// ContainerDisk references a docker image, embedding a qcow or raw disk.
// More info: https://kubevirt.gitbooks.io/user-guide/registry-disk.html
// +optional
Expand Down
13 changes: 13 additions & 0 deletions pkg/api/v1/schema_swagger_generated.go

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

2 changes: 2 additions & 0 deletions pkg/cloud-init/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ go_library(
"//pkg/kubecli:go_default_library",
"//pkg/log:go_default_library",
"//pkg/precond:go_default_library",
"//pkg/util/net/dns:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
],
)
Expand Down
Loading

0 comments on commit cee5650

Please sign in to comment.