Skip to content

Commit

Permalink
GCE: Always add boot disk annotations to templates
Browse files Browse the repository at this point in the history
  • Loading branch information
yaroslava-serdiuk committed Jul 4, 2022
1 parent 6ce299e commit dd488f0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cluster-autoscaler/cloudprovider/gce/gce_price_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ func (model *GcePriceModel) NodePrice(node *apiv1.Node, startTime time.Time, end
// Boot disk price
bootDiskSize, _ := strconv.ParseInt(node.Annotations[BootDiskSizeAnnotation], 10, 64)
if bootDiskSize == 0 {
klog.Error("Boot disk size is not found for node %s, using default size %v", node.Name, DefaultBootDiskSize)
klog.Errorf("Boot disk size is not found for node %s, using default size %v", node.Name, DefaultBootDiskSize)
bootDiskSize = DefaultBootDiskSize
}
bootDiskType := node.Annotations[BootDiskTypeAnnotation]
if val, ok := node.Labels[bootDiskTypeLabel]; ok {
bootDiskType = val
}
if bootDiskType == "" {
klog.Error("Boot disk type is not found for node %s, using default type %s", node.Name, DefaultBootDiskType)
klog.Errorf("Boot disk type is not found for node %s, using default type %s", node.Name, DefaultBootDiskType)
bootDiskType = DefaultBootDiskType
}
bootDiskPrice := model.PriceInfo.BootDiskPricePerHour()[bootDiskType]
Expand Down
6 changes: 3 additions & 3 deletions cluster-autoscaler/cloudprovider/gce/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,13 @@ func (t *GceTemplateBuilder) BuildNodeFromTemplate(mig Mig, template *gce.Instan
klog.Errorf("Couldn't extract architecture from kube-env for MIG %q, falling back to %q. Error: %v", mig.Id(), arch, err)
}

addBootDiskAnnotations(&node, template.Properties)
var ephemeralStorage int64 = -1

if !isBootDiskEphemeralStorageWithInstanceTemplateDisabled(kubeEnvValue) {
addBootDiskAnnotations(&node, template.Properties)
// ephemeral storage is backed up by boot disk
ephemeralStorage, err = getBootDiskEphemeralStorageFromInstanceTemplateProperties(template.Properties)
} else {
// ephemeral storage is backed up by local ssd
addAnnotation(&node, EphemeralStorageLocalSsdAnnotation, strconv.FormatBool(true))
}

Expand Down Expand Up @@ -780,7 +781,6 @@ func addBootDiskAnnotations(node *apiv1.Node, instanceProperties *gce.InstancePr
if instanceProperties.Disks == nil {
return
}

for _, disk := range instanceProperties.Disks {
if disk != nil && disk.InitializeParams != nil {
if disk.Boot {
Expand Down
1 change: 1 addition & 0 deletions cluster-autoscaler/cloudprovider/gce/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func TestBuildNodeFromTemplateSetsResources(t *testing.T) {
kubeEnv: "AUTOSCALER_ENV_VARS: os_distribution=cos;os=linux;ephemeral_storage_local_ssd_count=2\n",
physicalCpu: 8,
physicalMemory: 200 * units.MiB,
bootDiskSizeGiB: 300,
ephemeralStorageLocalSSDCount: 2,
attachedLocalSSDCount: 2,
expectedErr: false,
Expand Down

0 comments on commit dd488f0

Please sign in to comment.