Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature vm spec labels annotations #20

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ replace (
kubevirt.io/client-go => github.com/kubevirt/client-go v0.40.0-rc.2
kubevirt.io/containerized-data-importer => github.com/rancher/kubevirt-containerized-data-importer v1.26.1-0.20210303063201-9e7a78643487
sigs.k8s.io/structured-merge-diff => sigs.k8s.io/structured-merge-diff v0.0.0-20190302045857-e85c7b244fd2
github.com/harvester/go-harvester => github.com/nicolamarella/go-harvester v0.0.0-20210611103401-4ab3f45066a7
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,8 @@ github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM=
github.com/nicolamarella/go-harvester v0.0.0-20210611103401-4ab3f45066a7 h1:/yqmiqCCRDOvpL6zmGSlI4xk/ybz6mewPWoKjn0XkNQ=
github.com/nicolamarella/go-harvester v0.0.0-20210611103401-4ab3f45066a7/go.mod h1:/4BiNqnNK5HGfvlanwKv0RZLXNTIaE8GT3D1w4Vmt+Y=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.5 h1:obHEce3upls1IBn1gTw/o7bCv7OJb6Ib/o7wNO+4eKw=
github.com/nxadm/tail v1.4.5/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
Expand Down
14 changes: 14 additions & 0 deletions harvester/create.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package harvester

import (
"encoding/json"
"fmt"
"io/ioutil"
"strings"
Expand Down Expand Up @@ -104,13 +105,26 @@ func (d *Driver) Create() error {
ImageID: fmt.Sprintf("%s/%s", d.Namespace, d.ImageName),
}

templateAnnotations := make(map[string]string)
j_err := json.Unmarshal([]byte(d.Annotations), &templateAnnotations)
if j_err != nil {
panic(j_err)
}
templateLabels := make(map[string]string)
l_err := json.Unmarshal([]byte(d.Labels), &templateLabels)
if l_err != nil {
panic(l_err)
}

// create vm
vmBuilder := builder.NewVMBuilder("docker-machine-driver-harvester").
Namespace(d.Namespace).Name(d.MachineName).
CPU(d.CPU).Memory(d.MemorySize).
Image(d.DiskSize, d.DiskBus, dataVolumeOption).
EvictionStrategy(true).
DefaultPodAntiAffinity().
SpecTemplateAnnotations(templateAnnotations).
SpecTemplateLabels(templateLabels).
CloudInit(userData, networkData)

if d.KeyPairName != "" {
Expand Down
13 changes: 13 additions & 0 deletions harvester/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Name: "harvester-network-name",
Usage: "harvester network name",
},
mcnflag.StringFlag{
EnvVar: "HARVESTER_ANNOTATIONS",
Name: "harvester-annotations",
Usage: "harvester annotations",
},
mcnflag.StringFlag{
EnvVar: "HARVESTER_ANNOTATIONS",
Name: "harvester-labels",
Usage: "harvester labels",
},
mcnflag.StringFlag{
EnvVar: "HARVESTER_NETWORK_MODEL",
Name: "harvester-network-model",
Expand Down Expand Up @@ -161,6 +171,9 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.NetworkName = flags.String("harvester-network-name")
d.NetworkModel = flags.String("harvester-network-model")

d.Annotations = flags.String("harvester-annotations")
d.Labels = flags.String("harvester-labels")

d.SetSwarmConfigFromFlags(flags)

return d.checkConfig()
Expand Down
3 changes: 3 additions & 0 deletions harvester/harvester.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ type Driver struct {

NetworkName string
NetworkModel string

Annotations string
Labels string
}

func NewDriver(hostName, storePath string) *Driver {
Expand Down