Skip to content

Commit

Permalink
Added labels and annotations string flags. Parse json to map for labels
Browse files Browse the repository at this point in the history
and annotations
  • Loading branch information
nicolamarella committed Jun 11, 2021
1 parent f986bcd commit dc09ad9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
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 => ../go-harvester
)

require (
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

0 comments on commit dc09ad9

Please sign in to comment.