Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

adding nil check for managed cluster and its properties object #3197

Merged
merged 5 commits into from
Jun 14, 2018

Conversation

shrutir25
Copy link
Contributor

What this PR does / why we need it:
Checks for managed cluster object and properties object to make sure it is not nil

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #
Fixes nil panics seen here https://jarvis-west.dc.ad.msft.net/C7CCDED7
Special notes for your reviewer:

If applicable:

  • documentation
  • unit tests
  • tested backward compatibility (ie. deploy with previous version, upgrade with this branch)

Release note:

@ghost ghost assigned shrutir25 Jun 6, 2018
@ghost ghost added the in progress label Jun 6, 2018
@acs-bot acs-bot added the size/XS label Jun 6, 2018
@shrutir25
Copy link
Contributor Author

/assign @CecileRobertMichon

@CecileRobertMichon
Copy link
Contributor

/lgtm

@acs-bot acs-bot added the lgtm label Jun 6, 2018
@acs-bot
Copy link

acs-bot commented Jun 6, 2018

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: CecileRobertMichon, shrutir25

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

@@ -200,6 +200,10 @@ func (a *Apiloader) LoadContainerServiceForAgentPoolOnlyCluster(
if e := json.Unmarshal(contents, &managedCluster); e != nil {
return nil, IsSSHAutoGenerated, e
}
// verify managedCluster
if managedCluster == nil || managedCluster.Properties == nil {
return nil, false, a.Translator.Errorf("properties object in managed cluster should not be nil")
Copy link
Contributor

Choose a reason for hiding this comment

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

@shrutir25 actually the properties can be nil and is a supported ARM scenario. RPs need to be able to handle this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Here is the documentation: https://github.com/Azure/azure-resource-manager-rpc/blob/master/v1.0/resource-api-reference.md#put-resource -

properties | Optional. Format not defined by ARM. Settings used to provision or configure the resource. All Resource Provider specific properties must be placed within this. The order of parameters in the request is unspecified. RPs should not rely on any particular ordering.
-- | -

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@amanohar - so then you are suggesting that we make this check in RP before calling this function in acs-engine right ?

Copy link
Contributor

Choose a reason for hiding this comment

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

@shrutir25 I meant RP has to support a payload with nil properties and PUT should not fail.

Copy link
Contributor

Choose a reason for hiding this comment

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

I talked to Gaurav to get clarification. So long as the fields inside Properties are required, we can return 400 if it's not supplied.

Copy link
Contributor

@amanohar amanohar Jun 6, 2018

Choose a reason for hiding this comment

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

In case of update correct behavior is to accept properties=nil as user is not required to supply "required" properties during update.

@@ -200,6 +200,10 @@ func (a *Apiloader) LoadContainerServiceForAgentPoolOnlyCluster(
if e := json.Unmarshal(contents, &managedCluster); e != nil {
return nil, IsSSHAutoGenerated, e
}
// verify managedCluster
if managedCluster == nil || managedCluster.Properties == nil {
return nil, false, a.Translator.Errorf("properties object in managed cluster should not be nil")
Copy link
Contributor

Choose a reason for hiding this comment

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

Here is the documentation: https://github.com/Azure/azure-resource-manager-rpc/blob/master/v1.0/resource-api-reference.md#put-resource -

properties | Optional. Format not defined by ARM. Settings used to provision or configure the resource. All Resource Provider specific properties must be placed within this. The order of parameters in the request is unspecified. RPs should not rely on any particular ordering.
-- | -

@jackfrancis
Copy link
Member

/hold

@acs-bot acs-bot removed the lgtm label Jun 6, 2018
@acs-bot
Copy link

acs-bot commented Jun 6, 2018

New changes are detected. LGTM label has been removed.

@codecov
Copy link

codecov bot commented Jun 6, 2018

Codecov Report

Merging #3197 into master will increase coverage by <.01%.
The diff coverage is 0%.

@@            Coverage Diff             @@
##           master    #3197      +/-   ##
==========================================
+ Coverage   52.31%   52.32%   +<.01%     
==========================================
  Files         103      103              
  Lines       15458    15454       -4     
==========================================
- Hits         8087     8086       -1     
+ Misses       6643     6640       -3     
  Partials      728      728

@amanohar
Copy link
Contributor

amanohar commented Jun 6, 2018

@shrutir25 Couple of suggestions:

  1. I recommend using isUpdate param to make a determination of what kind of error to return. If it's an existing MC and nil then create managedCluster.Properties and then merge should happen.
  2. Fix this for both (all) MC versions and not just 2018-03-31.

@@ -200,6 +200,10 @@ func (a *Apiloader) LoadContainerServiceForAgentPoolOnlyCluster(
if e := json.Unmarshal(contents, &managedCluster); e != nil {
return nil, IsSSHAutoGenerated, e
}
// verify managedCluster.Properties is not nil for creating case
if (managedCluster == nil || managedCluster.Properties == nil) && !hasExistingCS {
Copy link
Contributor

Choose a reason for hiding this comment

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

Properties is a pointer. In update case if customer didn't set Properties would it be nil? Will that pointer need initialization in update case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also add a test for this in: apiloader_test.go

Copy link
Contributor

Choose a reason for hiding this comment

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

in update case, wouldn't nil managedCluster.Properties cause panic in line 208?

@acs-bot acs-bot added size/L and removed size/XS labels Jun 13, 2018
)

// Merge existing ManagedCluster attribute into mc
func (mc *ManagedCluster) Merge(emc *ManagedCluster) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

@amanohar @JunSun17 I think we should also merge KubernetesConfig

Copy link
Contributor

Choose a reason for hiding this comment

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

oh nvm this is versioned managed cluster..

@CecileRobertMichon CecileRobertMichon merged commit 1dc55c0 into master Jun 14, 2018
@ghost ghost removed the in progress label Jun 14, 2018
CecileRobertMichon pushed a commit that referenced this pull request Jun 14, 2018
* adding nil check for managed cluster and its properties object

* adding check for update scenario

* adding merge code and UTs

* correcting UTs

* correcting lint errors
@mboersma mboersma deleted the fix-nil-panic branch October 5, 2018 21:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants