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

add EnableRBAC to v20180331 api model #2647

Merged
merged 6 commits into from
Apr 10, 2018

Conversation

rjtsdl
Copy link
Contributor

@rjtsdl rjtsdl commented Apr 9, 2018

What this PR does / why we need it:

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

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 rjtsdl Apr 9, 2018
@ghost ghost added the in progress label Apr 9, 2018
@rjtsdl rjtsdl requested review from weinong, amanohar and JunSun17 April 9, 2018 23:57
@rjtsdl rjtsdl force-pushed the jiren-addrbacflag branch from 81e9755 to a0bead6 Compare April 9, 2018 23:59
@rjtsdl rjtsdl force-pushed the jiren-addrbacflag branch from a0bead6 to 3a5a6c9 Compare April 10, 2018 00:01
@@ -349,6 +350,13 @@ func convertV20180331AgentPoolOnlyWindowsProfile(obj *v20180331.WindowsProfile)
}
}

func convertV20180331AgentPoolOnlyKubernetesConfig(enableRBAC bool) *KubernetesConfig {
Copy link
Contributor

@amanohar amanohar Apr 10, 2018

Choose a reason for hiding this comment

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

@rjtsdl thanks for making this change as this also has a good side effect of resolving bug 2265988 in VSTS! You can also now remove lines 126-141 from putmanagedcluster.go and close out bug 2265988 in VSTS when new ACS E is vendored.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I will deal with that.

I think we also need to modify the older agentPoolOnly api version behavior. To always set those two flags to be false ptr.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made the change for v20170831 to make sure those two flags to be false ptr. Then RP don't need to deal with that.

enableRBAC = enableRBAC && *kc.EnableRbac
}

if kc.EnableSecureKubelet == nil {
Copy link
Contributor

@amanohar amanohar Apr 10, 2018

Choose a reason for hiding this comment

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

IMO if the code in convertertoagentpoolonlyapi.go is written as expected then we shouldn't need to check for EnableSecureKubelet state. Checking enableRBAC flag state should suffice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way we want to make it, is to have EnableSecureKubelet also enabled when use specify enableRBAC. I should make it clear in the enableRBAC flag description. Check the email thread I included you.

Copy link
Contributor

@amanohar amanohar Apr 10, 2018

Choose a reason for hiding this comment

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

Yes, agreed. We are on the same page regarding:

The way we want to make it, is to have EnableSecureKubelet also enabled when use specify enableRBAC.

I am suggesting that if RBAC is enabled in API model then EnableSecureKubelet should/would have been set to true. So when converting it back to versioned API model state of EnableSecureKubelet should not need to be validated.

Another way to put it is RBAC can still be technically enabled even if EnableSecureKubelet was set to false because customer only controls setting of enableRBAC. So if they set enableRBAC to true then they should get the same value back regardless of the state of EnableSecureKubelet.

Copy link
Contributor

Choose a reason for hiding this comment

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

why enableRBAC && false when it must be false?

Copy link
Contributor

Choose a reason for hiding this comment

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

what email thread?

Check the email thread I included you.

Copy link
Contributor Author

@rjtsdl rjtsdl Apr 10, 2018

Choose a reason for hiding this comment

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

@amanohar I got your point. However, I think we still need to validate EnableSecureKubelet. Because,

if EnableRbac == true && EnableSecureKubelet == false, then the cluster won't work properly. In the api model's conversion back and forth, there is no way to make them different. However, I can still see hacks like 126-141 from putmanagedcluster.go could make them different. That is why I want to validate both of them.

Validation is used to surface hacks :)

@@ -40,6 +40,7 @@ type Properties struct {
AccessProfiles map[string]AccessProfile `json:"accessProfiles,omitempty"`
AddonProfiles map[string]AddonProfile `json:"addonProfiles,omitempty"`
NodeResourceGroup string `json:"nodeResourceGroup,omitempty"`
EnableRBAC bool `json:"enableRBAC"`
Copy link
Contributor

Choose a reason for hiding this comment

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

does omitempty matter here?

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. should this be on by default?
  2. can this be changed? (turning on and off?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change to *bool, so we have 3 state

nil -> true
true -> true
false -> false

Note, we default behavior is to set it to true.

}
// Only if both KubernetesConfig.EnableRbac and KubernetesConfig.EnableSecureKubelet true
// We think EnableRBAC is on
enableRBAC := true
Copy link
Contributor

Choose a reason for hiding this comment

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

the code seems pretty complicated to me. why not base on the comments:

enableRBAC := (KubernetesConfig.EnableRbac == true) && (KubernetesConfig.EnableSecureKubelet == true)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

EnableRbac is *bool !

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, could this work then:
enableRBAC := (KubernetesConfig.EnableRbac != nil) && ((KubernetesConfig.EnableRbac) == true) && (KubernetesConfig.EnableSecureKubelet != nil) && ((KubernetesConfig.EnableSecureKubelet) == true)

no big deal, just want to make code a bit more easy to read. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made it easier to read.

if api.OrchestratorProfile != nil {
if api.OrchestratorProfile.OrchestratorVersion != "" {
p.KubernetesVersion = api.OrchestratorProfile.OrchestratorVersion
}
p.EnableRBAC = convertKubernetesConfigToEnableRBACV20180331AgentPoolOnly(api.OrchestratorProfile.KubernetesConfig)
p.EnableRBAC = *api.OrchestratorProfile.KubernetesConfig.EnableRbac &&
Copy link
Contributor

Choose a reason for hiding this comment

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

is this line redundant?

Copy link
Contributor Author

@rjtsdl rjtsdl Apr 10, 2018

Choose a reason for hiding this comment

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

Yeah, it is :) Removed

@rjtsdl
Copy link
Contributor Author

rjtsdl commented Apr 10, 2018

I have change the default behavior to be true for EnableRBAC api flag.
I also modified the older agentPoolOnly api model to always set those to be false, then we can remove the hack in RP codebase.

@rjtsdl rjtsdl added the ready label Apr 10, 2018
// Only if both KubernetesConfig.EnableRbac and KubernetesConfig.EnableSecureKubelet true
// We think EnableRBAC is on
if kc != nil && kc.EnableRbac != nil && *kc.EnableRbac &&
kc.EnableSecureKubelet != nil && *kc.EnableSecureKubelet {
Copy link
Contributor

Choose a reason for hiding this comment

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

I still think that EnableSecureKubelet should not factor into converting back to versioned API model. if *kc.EnableRbac then it should be enough to say that RBAC is enabled. You can also always log a warning line that EnableSecureKubelet was not enabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have strong opinion on this. Updated only use *kc.EnableRbac to deduct the versioned api model.

@@ -349,6 +354,20 @@ func convertV20180331AgentPoolOnlyWindowsProfile(obj *v20180331.WindowsProfile)
}
}

func convertV20180331AgentPoolOnlyKubernetesConfig(enableRBAC *bool) *KubernetesConfig {
if enableRBAC == nil || *enableRBAC == true {
Copy link
Contributor

Choose a reason for hiding this comment

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

If if enableRBAC == nil shouldn't EnableRbac be false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, we want the default behavior to be true.

Default behavior is when enableRBAC == nil

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, cool. Thanks!

Copy link
Contributor

@amanohar amanohar left a comment

Choose a reason for hiding this comment

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

Added some feedback. PTAL.

@ghost ghost removed the ready label Apr 10, 2018
amanohar
amanohar previously approved these changes Apr 10, 2018
@rjtsdl
Copy link
Contributor Author

rjtsdl commented Apr 10, 2018

TODO:

  1. @JunSun17 have a link to the api document? I need to update that
  2. We need to update the template used in Build to specify this field to be false.
  3. @amanohar , you probably also want to add enableAADAuth in a similar fashion. I will leave it to you :)

weinong
weinong previously approved these changes Apr 10, 2018
@@ -51,3 +51,8 @@ func HandleValidationErrors(e validator.ValidationErrors) error {
}
return fmt.Errorf("Namespace %s is not caught, %+v", ns, e)
}

// BoolPtr convert a bool to *bool
func BoolPtr(b bool) *bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

there is already a function doing this at

func PointerToBool(b bool) *bool {
I think you could re-use it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, will do

@rjtsdl rjtsdl dismissed stale reviews from weinong and amanohar via ec87d4d April 10, 2018 20:10
@rjtsdl rjtsdl force-pushed the jiren-addrbacflag branch from ec87d4d to 10bc6a0 Compare April 10, 2018 20:17
Copy link
Contributor

@CecileRobertMichon CecileRobertMichon left a comment

Choose a reason for hiding this comment

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

lgtm

@jackfrancis jackfrancis merged commit cf0f10d into Azure:master Apr 10, 2018
@ghost ghost removed the in progress label Apr 10, 2018
@jackfrancis jackfrancis deleted the jiren-addrbacflag branch April 10, 2018 22:18
jackfrancis pushed a commit that referenced this pull request Apr 11, 2018
* add EnableRBAC to v20180331 api model

* behavior change to set default EnableRBAC to be true for v20180331 api

* set KubernetesConfig to be false for those two flags, so RP don't need to hack

* set older version's kubernetesConfig's two flags to be false ptr, and add unittest

* only use EnableRBAC to convert to versioned api model

* re-use PointerToBool
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.

Need to add EnableRBAC as a flag in v20180331 api model
6 participants