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

populate default value in unmarshal #939

Merged
merged 4 commits into from
Jul 9, 2017

Conversation

rjtsdl
Copy link
Contributor

@rjtsdl rjtsdl commented Jul 7, 2017

What this PR does / why we need it:
close api definition gap to public document

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #936

Special notes for your reviewer:
One sample for masterCount, if looks good, I will apply to all the other fields.

Release note:


This change is Reviewable

@rjtsdl
Copy link
Contributor Author

rjtsdl commented Jul 7, 2017

@JiangtianLi , i saw OrchestratorType is using UnmarshalText, which needs a custom type OrchestratorType. If you think it is ok, i want to change all of them using UnmarshalJSON, which does addition decoding compared with UnmarshalText

Then i can use OrchestratorProfile's UnmarshalJSON to do what we have now. We can eliminate a type definition.

return e
}
*m = MasterProfile(mm)
if m.Count == 0 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If other fields in MasterProfile need to populate default value, it can be done inside this function.

@rjtsdl rjtsdl changed the title populate default value in unmarshal [WIP, welcome early feedback]populate default value in unmarshal Jul 7, 2017
return e
}
*m = MasterProfile(mm)
if m.Count == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does json.Unmarshal fill the empty field with 0?

Copy link
Contributor Author

@rjtsdl rjtsdl Jul 7, 2017

Choose a reason for hiding this comment

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

Yes, for int 0, for string ""

// And do fields manipulation, such as populating default value
func (m *MasterProfile) UnmarshalJSON(b []byte) error {
// Need to have a alias type to avoid circular unmarshal
type aliasMasterProfile MasterProfile
Copy link
Contributor

Choose a reason for hiding this comment

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

why use alias?

Copy link
Contributor Author

@rjtsdl rjtsdl Jul 7, 2017

Choose a reason for hiding this comment

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

otherwise, when you call MasterProfile.UnmarshalJSON, it causes a circular call to itself.
Because we have this, if mm is not the alias, it will be MasterProfile. Here is when circular call starts.

if e := json.Unmarshal(b, &mm); e != nil {
		return e
}

@weinong
Copy link
Contributor

weinong commented Jul 7, 2017

LGTM. let me know when you are ready to checkin.

@weinong weinong self-requested a review July 7, 2017 23:34
@rjtsdl
Copy link
Contributor Author

rjtsdl commented Jul 7, 2017

There maybe concerns on why do we need to populate default values when we have SetPropertiesDefaults when GenerateTemplate.

My principle would be
SetPropertiesDefaults operates on api.ContainerService, which is agnostic to api version. When the api doesn't expose all the vlab features, we use SetPropertiesDefaults to fill in vlab.ContainerService's defaults.

The populating in the unmarshal function is to fulfill the promise we made on the versioned api documents. Think about the scenario, in version 2018-09-30, we probably will switch default storageProfile to managedDisk. However, we won't change the existing versions default, which is to storageAccount. Make sense now?

@rjtsdl
Copy link
Contributor Author

rjtsdl commented Jul 7, 2017

@weinong, thx for reviewing. I will do this trick for the other versions. And also, I am inclined to do this for 2017-07-01. I will have the PR ready by Monday.

@rjtsdl rjtsdl force-pushed the jiren-unmarshalwithdefault branch from 9569e11 to 9384fc5 Compare July 8, 2017 00:11
@rjtsdl rjtsdl changed the title [WIP, welcome early feedback]populate default value in unmarshal populate default value in unmarshal Jul 8, 2017
@rjtsdl rjtsdl removed the in progress label Jul 8, 2017
@rjtsdl
Copy link
Contributor Author

rjtsdl commented Jul 8, 2017

@acs-bot test this please

@rjtsdl
Copy link
Contributor Author

rjtsdl commented Jul 8, 2017

@weinong , i get code ready. PTAL
@JiangtianLi , i want to do OrchestratorType change in different PR. I expect changes, as Cole is changing the OrchestratorVersion part.

@weinong
Copy link
Contributor

weinong commented Jul 8, 2017

Reviewed 2 of 2 files at r2, 5 of 5 files at r3.
Review status: all files reviewed at latest revision, 2 unresolved discussions.


Comments from Reviewable

@JiangtianLi
Copy link
Contributor

@rjtsdl LGTM. Yes, we can change orchestratorType in a separate PR.

@rjtsdl
Copy link
Contributor Author

rjtsdl commented Jul 9, 2017

I will just merge it. Thx

@rjtsdl rjtsdl merged commit efee998 into Azure:master Jul 9, 2017
@rjtsdl rjtsdl deleted the jiren-unmarshalwithdefault branch July 9, 2017 03:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Close the gap of acs-engine api and ACS public document
4 participants