-
Notifications
You must be signed in to change notification settings - Fork 558
adding nil check for managed cluster and its properties object #3197
Conversation
/assign @CecileRobertMichon |
/lgtm |
[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 |
pkg/api/apiloader.go
Outdated
@@ -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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
-- | -
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
pkg/api/apiloader.go
Outdated
@@ -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") |
There was a problem hiding this comment.
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.
-- | -
/hold |
New changes are detected. LGTM label has been removed. |
Codecov Report
@@ 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 |
@shrutir25 Couple of suggestions:
|
pkg/api/apiloader.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
) | ||
|
||
// Merge existing ManagedCluster attribute into mc | ||
func (mc *ManagedCluster) Merge(emc *ManagedCluster) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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..
* 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
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:
Release note: