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

Fixes nil pointer panic on autoscaling types conversion #71744

Merged

Conversation

yue9944882
Copy link
Member

@yue9944882 yue9944882 commented Dec 5, 2018

/kind bug
/sig autoscaling
/priority critical-urgent

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #70806

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Fixes apiserver nil pointer panics when requesting v2beta1 autoscaling object metrics

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 5, 2018
@@ -171,7 +171,8 @@ func Convert_autoscaling_ExternalMetricStatus_To_v1_ExternalMetricStatus(in *aut
out.CurrentValue = *in.Current.Value
}
if in.Current.AverageValue != nil {
out.CurrentAverageValue = in.Current.AverageValue
Copy link
Member Author

@yue9944882 yue9944882 Dec 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is another surprise when i walk thru all the autoscaling conversion. should do a deep copy here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conversion is not required to make copies of the input object values

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conversion is not required to make copies of the input object values

@liggitt if we call this conversion directly (not recommended tho), modifying the input obj will propagates to the output. is that okay? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edit: mmm.. quantity might be special.. we don't actually modify that in-place

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we call this conversion directly (not recommended tho), modifying the input obj will propagates to the output. is that okay?

Yes. Generated conversions share memory between the input and output object where possible:

func autoConvert_v1_VolumeSource_To_core_VolumeSource(in *v1.VolumeSource, out *core.VolumeSource, s conversion.Scope) error {
out.HostPath = (*core.HostPathVolumeSource)(unsafe.Pointer(in.HostPath))
out.EmptyDir = (*core.EmptyDirVolumeSource)(unsafe.Pointer(in.EmptyDir))
out.GCEPersistentDisk = (*core.GCEPersistentDiskVolumeSource)(unsafe.Pointer(in.GCEPersistentDisk))
out.AWSElasticBlockStore = (*core.AWSElasticBlockStoreVolumeSource)(unsafe.Pointer(in.AWSElasticBlockStore))
out.GitRepo = (*core.GitRepoVolumeSource)(unsafe.Pointer(in.GitRepo))
out.Secret = (*core.SecretVolumeSource)(unsafe.Pointer(in.Secret))
out.NFS = (*core.NFSVolumeSource)(unsafe.Pointer(in.NFS))
out.ISCSI = (*core.ISCSIVolumeSource)(unsafe.Pointer(in.ISCSI))
out.Glusterfs = (*core.GlusterfsVolumeSource)(unsafe.Pointer(in.Glusterfs))
out.PersistentVolumeClaim = (*core.PersistentVolumeClaimVolumeSource)(unsafe.Pointer(in.PersistentVolumeClaim))
out.RBD = (*core.RBDVolumeSource)(unsafe.Pointer(in.RBD))
out.FlexVolume = (*core.FlexVolumeSource)(unsafe.Pointer(in.FlexVolume))
out.Cinder = (*core.CinderVolumeSource)(unsafe.Pointer(in.Cinder))
out.CephFS = (*core.CephFSVolumeSource)(unsafe.Pointer(in.CephFS))
out.Flocker = (*core.FlockerVolumeSource)(unsafe.Pointer(in.Flocker))
out.DownwardAPI = (*core.DownwardAPIVolumeSource)(unsafe.Pointer(in.DownwardAPI))
out.FC = (*core.FCVolumeSource)(unsafe.Pointer(in.FC))
out.AzureFile = (*core.AzureFileVolumeSource)(unsafe.Pointer(in.AzureFile))
out.ConfigMap = (*core.ConfigMapVolumeSource)(unsafe.Pointer(in.ConfigMap))
out.VsphereVolume = (*core.VsphereVirtualDiskVolumeSource)(unsafe.Pointer(in.VsphereVolume))
out.Quobyte = (*core.QuobyteVolumeSource)(unsafe.Pointer(in.Quobyte))
out.AzureDisk = (*core.AzureDiskVolumeSource)(unsafe.Pointer(in.AzureDisk))
out.PhotonPersistentDisk = (*core.PhotonPersistentDiskVolumeSource)(unsafe.Pointer(in.PhotonPersistentDisk))
if in.Projected != nil {
in, out := &in.Projected, &out.Projected
*out = new(core.ProjectedVolumeSource)
if err := Convert_v1_ProjectedVolumeSource_To_core_ProjectedVolumeSource(*in, *out, s); err != nil {
return err
}
} else {
out.Projected = nil
}
out.PortworxVolume = (*core.PortworxVolumeSource)(unsafe.Pointer(in.PortworxVolume))
out.ScaleIO = (*core.ScaleIOVolumeSource)(unsafe.Pointer(in.ScaleIO))
out.StorageOS = (*core.StorageOSVolumeSource)(unsafe.Pointer(in.StorageOS))
return nil
}

@yue9944882
Copy link
Member Author

/assign @liggitt
/cc @kubernetes/sig-autoscaling-bugs

@@ -247,8 +247,10 @@ func Convert_autoscaling_ObjectMetricStatus_To_v2beta1_ObjectMetricStatus(in *au
}
out.MetricName = in.Metric.Name
out.Selector = in.Metric.Selector
currentAverageValue := *in.Current.AverageValue
out.AverageValue = &currentAverageValue
if in.Current.AverageValue != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs a test demonstrating the bug and that this fixes the issue

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this have the same issue:

targetAverageValue := *in.Target.AverageValue
out.TargetAverageValue = targetAverageValue

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Dec 5, 2018
@yue9944882
Copy link
Member Author

@liggitt is it ready for cherry-picks?

@liggitt
Copy link
Member

liggitt commented Dec 5, 2018

/lgtm
/approve

let's wait for green CI before opening picks

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 5, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liggitt, yue9944882

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 5, 2018
@liggitt liggitt added this to the v1.13 milestone Dec 5, 2018
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

@k8s-ci-robot k8s-ci-robot merged commit 809eaa7 into kubernetes:master Dec 5, 2018
@liggitt
Copy link
Member

liggitt commented Dec 5, 2018

@yue9944882 can you open the picks for this to release-1.13 and release-1.12?

@yue9944882
Copy link
Member Author

@liggitt sure, done (wake up hour here)

k8s-ci-robot added a commit that referenced this pull request Dec 6, 2018
…1744-origin-release-1.12

Automated cherry pick of #71744: fixes autoscaling types conversion
k8s-ci-robot added a commit that referenced this pull request Dec 6, 2018
…1744-origin-release-1.13

Automated cherry pick of #71744: fixes autoscaling types conversion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

K8s kube-apiserver 1.12.2 nil pointer crash
4 participants