mirror of https://github.com/kubernetes/kops.git
Merge pull request #15420 from spotinst/feature/new_integrate_instance_metadata
Spotinst: integrate AWS instance metadata config to instance groups #2
This commit is contained in:
commit
eccf23c920
|
|
@ -324,6 +324,9 @@ func (b *SpotInstanceGroupModelBuilder) buildElastigroup(c *fi.CloudupModelBuild
|
||||||
group.AutoScalerOpts.Taints = nil
|
group.AutoScalerOpts.Taints = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Instance Metadata Options
|
||||||
|
group.InstanceMetadataOptions = b.buildInstanceMetadataOptions(ig)
|
||||||
|
|
||||||
klog.V(4).Infof("Adding task: Elastigroup/%s", fi.ValueOf(group.Name))
|
klog.V(4).Infof("Adding task: Elastigroup/%s", fi.ValueOf(group.Name))
|
||||||
c.AddTask(group)
|
c.AddTask(group)
|
||||||
|
|
||||||
|
|
@ -452,6 +455,9 @@ func (b *SpotInstanceGroupModelBuilder) buildOcean(c *fi.CloudupModelBuilderCont
|
||||||
ocean.AutoScalerOpts.Headroom = nil
|
ocean.AutoScalerOpts.Headroom = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Instance Metadata Options
|
||||||
|
ocean.InstanceMetadataOptions = b.buildInstanceMetadataOptions(ig)
|
||||||
|
|
||||||
if !fi.ValueOf(ocean.UseAsTemplateOnly) {
|
if !fi.ValueOf(ocean.UseAsTemplateOnly) {
|
||||||
// Capacity.
|
// Capacity.
|
||||||
ocean.MinSize = fi.PtrTo(int64(0))
|
ocean.MinSize = fi.PtrTo(int64(0))
|
||||||
|
|
@ -545,10 +551,7 @@ func (b *SpotInstanceGroupModelBuilder) buildLaunchSpec(c *fi.CloudupModelBuilde
|
||||||
|
|
||||||
// Capacity.
|
// Capacity.
|
||||||
minSize, maxSize := b.buildCapacity(ig)
|
minSize, maxSize := b.buildCapacity(ig)
|
||||||
if fi.ValueOf(ocean.UseAsTemplateOnly) {
|
if !fi.ValueOf(ocean.UseAsTemplateOnly) {
|
||||||
ocean.MinSize = minSize
|
|
||||||
ocean.MaxSize = maxSize
|
|
||||||
} else {
|
|
||||||
ocean.MinSize = fi.PtrTo(fi.ValueOf(ocean.MinSize) + fi.ValueOf(minSize))
|
ocean.MinSize = fi.PtrTo(fi.ValueOf(ocean.MinSize) + fi.ValueOf(minSize))
|
||||||
ocean.MaxSize = fi.PtrTo(fi.ValueOf(ocean.MaxSize) + fi.ValueOf(maxSize))
|
ocean.MaxSize = fi.PtrTo(fi.ValueOf(ocean.MaxSize) + fi.ValueOf(maxSize))
|
||||||
}
|
}
|
||||||
|
|
@ -624,6 +627,9 @@ func (b *SpotInstanceGroupModelBuilder) buildLaunchSpec(c *fi.CloudupModelBuilde
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Instance Metadata Options
|
||||||
|
launchSpec.InstanceMetadataOptions = b.buildInstanceMetadataOptions(ig)
|
||||||
|
|
||||||
klog.V(4).Infof("Adding task: LaunchSpec/%s", fi.ValueOf(launchSpec.Name))
|
klog.V(4).Infof("Adding task: LaunchSpec/%s", fi.ValueOf(launchSpec.Name))
|
||||||
c.AddTask(launchSpec)
|
c.AddTask(launchSpec)
|
||||||
|
|
||||||
|
|
@ -1032,6 +1038,16 @@ func (b *SpotInstanceGroupModelBuilder) buildAutoScalerOpts(clusterID string, ig
|
||||||
return opts, nil
|
return opts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *SpotInstanceGroupModelBuilder) buildInstanceMetadataOptions(ig *kops.InstanceGroup) *spotinsttasks.InstanceMetadataOptions {
|
||||||
|
if ig.Spec.InstanceMetadata != nil {
|
||||||
|
opt := new(spotinsttasks.InstanceMetadataOptions)
|
||||||
|
opt.HTTPPutResponseHopLimit = fi.PtrTo(fi.ValueOf(ig.Spec.InstanceMetadata.HTTPPutResponseHopLimit))
|
||||||
|
opt.HTTPTokens = fi.PtrTo(fi.ValueOf(ig.Spec.InstanceMetadata.HTTPTokens))
|
||||||
|
return opt
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func parseBool(str string) (*bool, error) {
|
func parseBool(str string) (*bool, error) {
|
||||||
v, err := strconv.ParseBool(str)
|
v, err := strconv.ParseBool(str)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ type Elastigroup struct {
|
||||||
Tenancy *string
|
Tenancy *string
|
||||||
RootVolumeOpts *RootVolumeOpts
|
RootVolumeOpts *RootVolumeOpts
|
||||||
AutoScalerOpts *AutoScalerOpts
|
AutoScalerOpts *AutoScalerOpts
|
||||||
|
InstanceMetadataOptions *InstanceMetadataOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
type RootVolumeOpts struct {
|
type RootVolumeOpts struct {
|
||||||
|
|
@ -112,6 +113,11 @@ type AutoScalerResourceLimitsOpts struct {
|
||||||
MaxMemory *int
|
MaxMemory *int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type InstanceMetadataOptions struct {
|
||||||
|
HTTPPutResponseHopLimit *int64
|
||||||
|
HTTPTokens *string
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_ fi.CloudupTask = &Elastigroup{}
|
_ fi.CloudupTask = &Elastigroup{}
|
||||||
_ fi.CompareWithID = &Elastigroup{}
|
_ fi.CompareWithID = &Elastigroup{}
|
||||||
|
|
@ -421,6 +427,14 @@ func (e *Elastigroup) Find(c *fi.CloudupContext) (*Elastigroup, error) {
|
||||||
if lc.HealthCheckType != nil {
|
if lc.HealthCheckType != nil {
|
||||||
actual.HealthCheckType = lc.HealthCheckType
|
actual.HealthCheckType = lc.HealthCheckType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Instance Metadata Options
|
||||||
|
if lc.MetadataOptions != nil {
|
||||||
|
actual.InstanceMetadataOptions = new(InstanceMetadataOptions)
|
||||||
|
actual.InstanceMetadataOptions.HTTPTokens = fi.PtrTo(fi.ValueOf(lc.MetadataOptions.HTTPTokens))
|
||||||
|
actual.InstanceMetadataOptions.HTTPPutResponseHopLimit = fi.PtrTo(int64(fi.ValueOf(lc.MetadataOptions.HTTPPutResponseHopLimit)))
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto Scaler.
|
// Auto Scaler.
|
||||||
|
|
@ -748,6 +762,15 @@ func (_ *Elastigroup) create(cloud awsup.AWSCloud, a, e, changes *Elastigroup) e
|
||||||
group.SetIntegration(integration)
|
group.SetIntegration(integration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Instance Metadata Options
|
||||||
|
{
|
||||||
|
if e.InstanceMetadataOptions != nil {
|
||||||
|
opt := new(aws.MetadataOptions)
|
||||||
|
opt.SetHTTPPutResponseHopLimit(fi.PtrTo(int(fi.ValueOf(e.InstanceMetadataOptions.HTTPPutResponseHopLimit))))
|
||||||
|
opt.SetHTTPTokens(fi.PtrTo(fi.ValueOf(e.InstanceMetadataOptions.HTTPTokens)))
|
||||||
|
group.Compute.LaunchSpecification.SetMetadataOptions(opt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
attempt := 0
|
attempt := 0
|
||||||
maxAttempts := 10
|
maxAttempts := 10
|
||||||
|
|
@ -1243,6 +1266,27 @@ func (_ *Elastigroup) update(cloud awsup.AWSCloud, a, e, changes *Elastigroup) e
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Instance Metadata Options
|
||||||
|
{
|
||||||
|
if changes.InstanceMetadataOptions != nil {
|
||||||
|
if group.Compute == nil {
|
||||||
|
group.Compute = new(aws.Compute)
|
||||||
|
}
|
||||||
|
if group.Compute.LaunchSpecification == nil {
|
||||||
|
group.Compute.LaunchSpecification = new(aws.LaunchSpecification)
|
||||||
|
}
|
||||||
|
|
||||||
|
opt := new(aws.MetadataOptions)
|
||||||
|
opt.SetHTTPPutResponseHopLimit(fi.PtrTo(int(fi.ValueOf(e.InstanceMetadataOptions.HTTPPutResponseHopLimit))))
|
||||||
|
opt.SetHTTPTokens(fi.PtrTo(fi.ValueOf(e.InstanceMetadataOptions.HTTPTokens)))
|
||||||
|
group.Compute.LaunchSpecification.SetMetadataOptions(opt)
|
||||||
|
changes.InstanceMetadataOptions = nil
|
||||||
|
changed = true
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ type LaunchSpec struct {
|
||||||
AssociatePublicIPAddress *bool
|
AssociatePublicIPAddress *bool
|
||||||
MinSize *int64
|
MinSize *int64
|
||||||
MaxSize *int64
|
MaxSize *int64
|
||||||
|
InstanceMetadataOptions *InstanceMetadataOptions
|
||||||
|
|
||||||
Ocean *Ocean
|
Ocean *Ocean
|
||||||
}
|
}
|
||||||
|
|
@ -327,6 +328,13 @@ func (o *LaunchSpec) Find(c *fi.CloudupContext) (*LaunchSpec, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Instance Metadata Options
|
||||||
|
if spec.InstanceMetadataOptions != nil {
|
||||||
|
actual.InstanceMetadataOptions = new(InstanceMetadataOptions)
|
||||||
|
actual.InstanceMetadataOptions.HTTPTokens = fi.PtrTo(fi.ValueOf(spec.InstanceMetadataOptions.HTTPTokens))
|
||||||
|
actual.InstanceMetadataOptions.HTTPPutResponseHopLimit = fi.PtrTo(int64(fi.ValueOf(spec.InstanceMetadataOptions.HTTPPutResponseHopLimit)))
|
||||||
|
}
|
||||||
|
|
||||||
// Avoid spurious changes.
|
// Avoid spurious changes.
|
||||||
actual.Lifecycle = o.Lifecycle
|
actual.Lifecycle = o.Lifecycle
|
||||||
|
|
||||||
|
|
@ -534,6 +542,15 @@ func (_ *LaunchSpec) create(cloud awsup.AWSCloud, a, e, changes *LaunchSpec) err
|
||||||
spec.SetRestrictScaleDown(e.RestrictScaleDown)
|
spec.SetRestrictScaleDown(e.RestrictScaleDown)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Instance Metadata Options
|
||||||
|
{
|
||||||
|
if e.InstanceMetadataOptions != nil {
|
||||||
|
opt := new(aws.LaunchspecInstanceMetadataOptions)
|
||||||
|
opt.SetHTTPPutResponseHopLimit(fi.PtrTo(int(fi.ValueOf(e.InstanceMetadataOptions.HTTPPutResponseHopLimit))))
|
||||||
|
opt.SetHTTPTokens(fi.PtrTo(fi.ValueOf(e.InstanceMetadataOptions.HTTPTokens)))
|
||||||
|
spec.SetLaunchspecInstanceMetadataOptions(opt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Wrap the raw object as a LaunchSpec.
|
// Wrap the raw object as a LaunchSpec.
|
||||||
sp, err := spotinst.NewLaunchSpec(cloud.ProviderID(), spec)
|
sp, err := spotinst.NewLaunchSpec(cloud.ProviderID(), spec)
|
||||||
|
|
@ -787,6 +804,17 @@ func (_ *LaunchSpec) update(cloud awsup.AWSCloud, a, e, changes *LaunchSpec) err
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Instance Metadata Options
|
||||||
|
{
|
||||||
|
if changes.InstanceMetadataOptions != nil {
|
||||||
|
opt := new(aws.LaunchspecInstanceMetadataOptions)
|
||||||
|
opt.SetHTTPPutResponseHopLimit(fi.PtrTo(int(fi.ValueOf(e.InstanceMetadataOptions.HTTPPutResponseHopLimit))))
|
||||||
|
opt.SetHTTPTokens(fi.PtrTo(fi.ValueOf(e.InstanceMetadataOptions.HTTPTokens)))
|
||||||
|
spec.SetLaunchspecInstanceMetadataOptions(opt)
|
||||||
|
changes.InstanceMetadataOptions = nil
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
empty := &LaunchSpec{}
|
empty := &LaunchSpec{}
|
||||||
if !reflect.DeepEqual(empty, changes) {
|
if !reflect.DeepEqual(empty, changes) {
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ type Ocean struct {
|
||||||
UseAsTemplateOnly *bool
|
UseAsTemplateOnly *bool
|
||||||
RootVolumeOpts *RootVolumeOpts
|
RootVolumeOpts *RootVolumeOpts
|
||||||
AutoScalerOpts *AutoScalerOpts
|
AutoScalerOpts *AutoScalerOpts
|
||||||
|
InstanceMetadataOptions *InstanceMetadataOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -290,6 +291,13 @@ func (o *Ocean) Find(c *fi.CloudupContext) (*Ocean, error) {
|
||||||
if lc.UseAsTemplateOnly != nil {
|
if lc.UseAsTemplateOnly != nil {
|
||||||
actual.UseAsTemplateOnly = lc.UseAsTemplateOnly
|
actual.UseAsTemplateOnly = lc.UseAsTemplateOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Instance Metadata Options
|
||||||
|
if lc.InstanceMetadataOptions != nil {
|
||||||
|
actual.InstanceMetadataOptions = new(InstanceMetadataOptions)
|
||||||
|
actual.InstanceMetadataOptions.HTTPTokens = fi.PtrTo(fi.ValueOf(lc.InstanceMetadataOptions.HTTPTokens))
|
||||||
|
actual.InstanceMetadataOptions.HTTPPutResponseHopLimit = fi.PtrTo(int64(fi.ValueOf(lc.InstanceMetadataOptions.HTTPPutResponseHopLimit)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto Scaler.
|
// Auto Scaler.
|
||||||
|
|
@ -455,7 +463,15 @@ func (_ *Ocean) create(cloud awsup.AWSCloud, a, e, changes *Ocean) error {
|
||||||
ocean.Compute.LaunchSpecification.SetSecurityGroupIDs(securityGroupIDs)
|
ocean.Compute.LaunchSpecification.SetSecurityGroupIDs(securityGroupIDs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
{
|
||||||
|
if e.InstanceMetadataOptions != nil {
|
||||||
|
opt := new(aws.InstanceMetadataOptions)
|
||||||
|
opt.SetHTTPPutResponseHopLimit(fi.PtrTo(int(fi.ValueOf(e.InstanceMetadataOptions.HTTPPutResponseHopLimit))))
|
||||||
|
opt.SetHTTPTokens(fi.PtrTo(fi.ValueOf(e.InstanceMetadataOptions.HTTPTokens)))
|
||||||
|
ocean.Compute.LaunchSpecification.SetInstanceMetadataOptions(opt)
|
||||||
|
}
|
||||||
|
}
|
||||||
if !fi.ValueOf(e.UseAsTemplateOnly) {
|
if !fi.ValueOf(e.UseAsTemplateOnly) {
|
||||||
// User data.
|
// User data.
|
||||||
{
|
{
|
||||||
|
|
@ -812,6 +828,24 @@ func (_ *Ocean) update(cloud awsup.AWSCloud, a, e, changes *Ocean) error {
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Instance Metadata Options
|
||||||
|
{
|
||||||
|
if changes.InstanceMetadataOptions != nil {
|
||||||
|
if ocean.Compute == nil {
|
||||||
|
ocean.Compute = new(aws.Compute)
|
||||||
|
}
|
||||||
|
if ocean.Compute.LaunchSpecification == nil {
|
||||||
|
ocean.Compute.LaunchSpecification = new(aws.LaunchSpecification)
|
||||||
|
}
|
||||||
|
|
||||||
|
opt := new(aws.InstanceMetadataOptions)
|
||||||
|
opt.SetHTTPPutResponseHopLimit(fi.PtrTo(int(fi.ValueOf(e.InstanceMetadataOptions.HTTPPutResponseHopLimit))))
|
||||||
|
opt.SetHTTPTokens(fi.PtrTo(fi.ValueOf(e.InstanceMetadataOptions.HTTPTokens)))
|
||||||
|
ocean.Compute.LaunchSpecification.SetInstanceMetadataOptions(opt)
|
||||||
|
changes.InstanceMetadataOptions = nil
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !fi.ValueOf(e.UseAsTemplateOnly) {
|
if !fi.ValueOf(e.UseAsTemplateOnly) {
|
||||||
// User data.
|
// User data.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue