mirror of https://github.com/kubernetes/kops.git
feat(spotinst/ocean): add support for tags (cloud labels)
This commit is contained in:
parent
1a8b99fca3
commit
11a532aff6
|
@ -476,6 +476,12 @@ func (b *InstanceGroupModelBuilder) buildLaunchSpec(c *fi.ModelBuilderContext,
|
|||
return fmt.Errorf("error building security groups: %v", err)
|
||||
}
|
||||
|
||||
// Tags.
|
||||
launchSpec.Tags, err = b.buildTags(ig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error building cloud tags: %v", err)
|
||||
}
|
||||
|
||||
// Labels.
|
||||
autoScalerOpts, err := b.buildAutoScalerOpts(b.ClusterName(), ig)
|
||||
if err != nil {
|
||||
|
|
|
@ -43,6 +43,7 @@ type LaunchSpec struct {
|
|||
SecurityGroups []*awstasks.SecurityGroup
|
||||
IAMInstanceProfile *awstasks.IAMInstanceProfile
|
||||
ImageID *string
|
||||
Tags map[string]string
|
||||
Labels map[string]string
|
||||
|
||||
Ocean *Ocean
|
||||
|
@ -167,6 +168,16 @@ func (o *LaunchSpec) Find(c *fi.Context) (*LaunchSpec, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// Tags.
|
||||
{
|
||||
if len(spec.Tags) > 0 {
|
||||
actual.Tags = make(map[string]string)
|
||||
for _, tag := range spec.Tags {
|
||||
actual.Tags[fi.StringValue(tag.Key)] = fi.StringValue(tag.Value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Labels.
|
||||
if spec.Labels != nil {
|
||||
actual.Labels = make(map[string]string)
|
||||
|
@ -265,6 +276,13 @@ func (_ *LaunchSpec) create(cloud awsup.AWSCloud, a, e, changes *LaunchSpec) err
|
|||
}
|
||||
}
|
||||
|
||||
// Tags.
|
||||
{
|
||||
if e.Tags != nil {
|
||||
spec.SetTags(e.buildTags())
|
||||
}
|
||||
}
|
||||
|
||||
// Labels.
|
||||
{
|
||||
if e.Labels != nil && len(e.Labels) > 0 {
|
||||
|
@ -366,6 +384,15 @@ func (_ *LaunchSpec) update(cloud awsup.AWSCloud, a, e, changes *LaunchSpec) err
|
|||
}
|
||||
}
|
||||
|
||||
// Tags.
|
||||
{
|
||||
if changes.Tags != nil {
|
||||
spec.SetTags(e.buildTags())
|
||||
changes.Tags = nil
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
|
||||
// Labels.
|
||||
{
|
||||
if changes.Labels != nil {
|
||||
|
@ -474,6 +501,18 @@ func (_ *LaunchSpec) RenderTerraform(t *terraform.TerraformTarget, a, e, changes
|
|||
tf.IAMInstanceProfile = e.IAMInstanceProfile.TerraformLink()
|
||||
}
|
||||
|
||||
// Tags.
|
||||
{
|
||||
if e.Tags != nil {
|
||||
for _, tag := range e.buildTags() {
|
||||
tf.Tags = append(tf.Tags, &terraformKV{
|
||||
Key: tag.Key,
|
||||
Value: tag.Value,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Labels.
|
||||
{
|
||||
if e.Labels != nil {
|
||||
|
@ -493,3 +532,16 @@ func (_ *LaunchSpec) RenderTerraform(t *terraform.TerraformTarget, a, e, changes
|
|||
func (o *LaunchSpec) TerraformLink() *terraform.Literal {
|
||||
return terraform.LiteralProperty("spotinst_ocean_aws_launch_spec", *o.Name, "id")
|
||||
}
|
||||
|
||||
func (o *LaunchSpec) buildTags() []*aws.Tag {
|
||||
tags := make([]*aws.Tag, 0, len(o.Tags))
|
||||
|
||||
for key, value := range o.Tags {
|
||||
tags = append(tags, &aws.Tag{
|
||||
Key: fi.String(key),
|
||||
Value: fi.String(value),
|
||||
})
|
||||
}
|
||||
|
||||
return tags
|
||||
}
|
||||
|
|
|
@ -951,6 +951,7 @@ type terraformOceanLaunchSpec struct {
|
|||
KeyName *terraform.Literal `json:"key_name,omitempty"`
|
||||
SecurityGroups []*terraform.Literal `json:"security_groups,omitempty"`
|
||||
Labels []*terraformKV `json:"labels,omitempty"`
|
||||
Tags []*terraformKV `json:"tags,omitempty"`
|
||||
}
|
||||
|
||||
func (_ *Ocean) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Ocean) error {
|
||||
|
|
Loading…
Reference in New Issue