Skip to content

Commit

Permalink
Add boot from volume support (openshift#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
jichenjc authored and pierreprinetti committed Apr 22, 2024
1 parent 481d573 commit d3d4ddf
Show file tree
Hide file tree
Showing 10 changed files with 374 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Gopkg.lock

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

4 changes: 4 additions & 0 deletions cmd/clusterctl/examples/openstack/machines.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ items:
networks:
- uuid: <Kubernetes Network ID>
floatingIP: <Available Floating IP>
rootVolume:
diskSize: 0
sourceType: ""
SourceUUID: ""
securityGroups:
- <Security Group ID>
userDataSecret:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ spec:
type: string
type: object
type: array
rootVolume:
properties:
deviceType:
type: string
diskSize:
format: int64
type: integer
sourceType:
type: string
sourceUUID:
type: string
required:
- deviceType
type: object
securityGroups:
items:
properties:
Expand Down
24 changes: 24 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,27 @@ Instead of tagging, you also have the option to add metadata to instances. This
name: bob
nickname: bobbert
```
# Optional Configuration
## Boot From Volume
1. In `examples/openstack/<os>/out/machines.yaml`, generated with `generate-yaml.sh,
set `spec.providerSpec.value.rootVolume.diskSize` to great than 0 means boot from volume.
```yaml
items:
- apiVersion: "cluster.k8s.io/v1alpha1"
kind: Machine
...
spec:
providerSpec:
value:
...
rootVolume:
diskSize: 0
sourceType: ""
SourceUUID: ""
securityGroups:
...
```
10 changes: 7 additions & 3 deletions pkg/apis/openstackproviderconfig/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type OpenstackProviderSpec struct {
// The flavor reference for the flavor for your server instance.
Flavor string `json:"flavor"`
// The name of the image to use for your server instance.
// If the RootVolume is specified, this will be ignored and use rootVolume directly.
Image string `json:"image"`

// The ssh key to inject in the instance
Expand Down Expand Up @@ -68,8 +69,6 @@ type OpenstackProviderSpec struct {
// Whether the server instance is created on a trunk port or not.
Trunk bool `json:"trunk,omitempty"`

RootVolume RootVolume `json:"root_volume,omitempty"`

// Server tags
// Requires Nova api 2.52 minimum!
Tags []string `json:"tags,omitempty"`
Expand All @@ -79,6 +78,9 @@ type OpenstackProviderSpec struct {

// Config Drive support
ConfigDrive *bool `json:"configDrive,omitempty"`

// The volume metadata to boot from
RootVolume *RootVolume `json:"rootVolume,omitempty"`
}

type SecurityGroupParam struct {
Expand Down Expand Up @@ -169,7 +171,9 @@ type SubnetFilter struct {
}

type RootVolume struct {
VolumeType string `json:"volumeType"`
SourceType string `json:"sourceType,omitempty"`
SourceUUID string `json:"sourceUUID,omitempty"`
DeviceType string `json:"deviceType"`
Size int `json:"diskSize,omitempty"`
}

Expand Down
24 changes: 24 additions & 0 deletions pkg/cloud/openstack/clients/machineservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/gophercloud/gophercloud/openstack"
"github.com/gophercloud/gophercloud/openstack/common/extensions"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
Expand Down Expand Up @@ -343,6 +344,7 @@ func GetSecurityGroups(is *InstanceService, sg_param []openstackconfigv1.Securit
}

func (is *InstanceService) InstanceCreate(clusterName string, name string, config *openstackconfigv1.OpenstackProviderSpec, cmd string, keyName string) (instance *Instance, err error) {
var createOpts servers.CreateOptsBuilder
if config == nil {
return nil, fmt.Errorf("create Options need be specified to create instace")
}
Expand Down Expand Up @@ -498,6 +500,28 @@ func (is *InstanceService) InstanceCreate(clusterName string, name string, confi
is.computeClient.Microversion = "2.52"

}

// If the root volume Size is not 0, means boot from volume
if config.RootVolume != nil && config.RootVolume.Size != 0 {
var blocks []bootfromvolume.BlockDevice

block := bootfromvolume.BlockDevice{
SourceType: bootfromvolume.SourceType(config.RootVolume.SourceType),
BootIndex: 0,
UUID: config.RootVolume.SourceUUID,
DeleteOnTermination: true,
DestinationType: bootfromvolume.DestinationVolume,
VolumeSize: config.RootVolume.Size,
DeviceType: config.RootVolume.DeviceType,
}
blocks = append(blocks, block)

createOpts = bootfromvolume.CreateOptsExt{
CreateOptsBuilder: createOpts,
BlockDevice: blocks,
}
}

server, err := servers.Create(is.computeClient, keypairs.CreateOptsExt{
CreateOptsBuilder: serverCreateOpts,
KeyName: keyName,
Expand Down

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

Loading

0 comments on commit d3d4ddf

Please sign in to comment.