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

Add tags usage when creating machine #1757

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 15 additions & 8 deletions pkg/cloudprovider/provider/equinixmetal/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (p *provider) getMetalDevice(machine *clusterv1alpha1.Machine) (*packngo.De
}

client := getClient(c.Token)
device, err := getDeviceByTag(client, c.ProjectID, generateTag(string(machine.UID)))
device, err := getDeviceByTag(client, c.ProjectID, generateMachineTag(string(machine.UID)))
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -241,7 +241,7 @@ func (p *provider) Validate(_ context.Context, _ *zap.SugaredLogger, spec cluste
}

func (p *provider) Create(_ context.Context, _ *zap.SugaredLogger, machine *clusterv1alpha1.Machine, _ *cloudprovidertypes.ProviderData, userdata string) (instance.Instance, error) {
c, _, pc, err := p.getConfig(machine.Spec.ProviderSpec)
c, rc, pc, err := p.getConfig(machine.Spec.ProviderSpec)
if err != nil {
return nil, cloudprovidererrors.TerminalError{
Reason: common.InvalidConfigurationMachineError,
Expand All @@ -259,6 +259,11 @@ func (p *provider) Create(_ context.Context, _ *zap.SugaredLogger, machine *clus
}
}

tags := append(c.Tags, generateMachineTag(string(machine.UID)))
for k, v := range rc.Labels {
tags = append(tags, generateTag(k, v))
}

serverCreateOpts := &packngo.DeviceCreateRequest{
Hostname: machine.Spec.Name,
UserData: userdata,
Expand All @@ -268,9 +273,7 @@ func (p *provider) Create(_ context.Context, _ *zap.SugaredLogger, machine *clus
BillingCycle: c.BillingCycle,
Plan: c.InstanceType,
OS: imageName,
Tags: []string{
generateTag(string(machine.UID)),
},
Tags: tags,
}

device, res, err := client.Devices.Create(serverCreateOpts)
Expand Down Expand Up @@ -352,7 +355,7 @@ func (p *provider) MigrateUID(_ context.Context, log *zap.SugaredLogger, machine
}

// create a new UID label
tags = append(tags, generateTag(string(newID)))
tags = append(tags, generateMachineTag(string(newID)))

log.Info("Setting UID label for machine")
dur := &packngo.DeviceUpdateRequest{
Expand Down Expand Up @@ -489,8 +492,12 @@ func getClient(apiKey string) *packngo.Client {
return packngo.NewClientWithAuth("kubermatic", apiKey, nil)
}

func generateTag(ID string) string {
return fmt.Sprintf("%s:%s", machineUIDTag, ID)
func generateMachineTag(ID string) string {
return generateTag(machineUIDTag, ID)
}

func generateTag(key string, value string) string {
return fmt.Sprintf("%s:%s", key, value)
}

func getTagUID(tag string) (string, error) {
Expand Down
1 change: 1 addition & 0 deletions pkg/cloudprovider/provider/equinixmetal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type RawConfig struct {
Metro providerconfigtypes.ConfigVarString `json:"metro,omitempty"`
Facilities []providerconfigtypes.ConfigVarString `json:"facilities,omitempty"`
Tags []providerconfigtypes.ConfigVarString `json:"tags,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
}

func GetConfig(pconfig providerconfigtypes.Config) (*RawConfig, error) {
Expand Down