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

Validation logic backward compatibility support for custom VNET #2693

Merged

Conversation

JunSun17
Copy link
Contributor

@JunSun17 JunSun17 commented Apr 14, 2018

Validation logic backward compatibility support for API models converted from prior v20180331 models.

This PR adds validation support for API models generated by serialization of

  1. un-versioned models created prior to v20180331.
  2. use template generator generated model with default values set.

Also adds various testings.

@ghost ghost assigned JunSun17 Apr 14, 2018
@ghost ghost added the in progress label Apr 14, 2018
@JunSun17 JunSun17 requested review from weinong and amanohar April 14, 2018 22:27
// ErrorInvalidNetworkPlugin error
var ErrorInvalidNetworkPlugin = fmt.Errorf("Network plugin should be either \"azure\" or \"kubenet\"")
var ErrorInvalidNetworkPlugin = fmt.Errorf("Network plugin should be either Azure or Kubenet")
Copy link
Contributor

Choose a reason for hiding this comment

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

Kubenet or none? Also, is it case insensitive?

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 plugin name is Kubenet, but in the model, we represent it internally as "none". Since the error message is more for customer, I put the name to Kubenet. Case does not matter here.

}
// validate network profile settings
if n != nil {
if string(n.NetworkPlugin) == string(Azure) || string(n.NetworkPlugin) == string(Kubenet) {
Copy link
Contributor

@weinong weinong Apr 15, 2018

Choose a reason for hiding this comment

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

is it easier to read using switch and case? Also, can't it be compared using NetworkPlugin type? how about case sensitivity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case, Azure and Kubenet is handled through the same code path, so switch does not help.

NetworkPlugin can be instantiated by taking a string, I think it can not be compared directly to constant Azure or Kubenet, even though the string value are the same.

The model now requires case matching too.

Copy link
Contributor

Choose a reason for hiding this comment

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

In pkg/acsengine/testdata/agentPoolOnly/v20180331/agentsWithFullNetworkProfile.json, it says azure, though..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually tested (NetworkPlugin("azure") == Azure) is true, will change the code to make it simple.

"azure" is the serialized representation of object Azure, NetworkPlugin("Azure") will not equal to object Azure. So it is case sensitive.

}
} else {
return ErrorNilAgentPoolProfile
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, it may not be required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is probably redundant and has been checked before, but I think it is no harm to be on the safe side to check this.

Copy link
Contributor

@weinong weinong Apr 16, 2018

Choose a reason for hiding this comment

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

if you are sure that update without AgentPoolProfile will be fine, then it's ok... but.. are you sure about that? :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we allow partial API model in the update case, remove ErrorNilAgentPoolProfile.

I still want to leave the validateAgentPoolVNET() method in VNET validation since VNET validation will cross multiple profiles (for example, we will need to validate subnetCidr from agentPoolProfile against serviceCidr from networkProfile).

}
}

return true
return false
}

// GetVNETSubnetIDComponents extract subscription, resourcegroup, vnetname, subnetname from the vnetSubnetID
Copy link
Contributor

Choose a reason for hiding this comment

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

The regex is static. Can be saved at package level. Also, most literals used in Azure are case insensitive. For instance, resourcegroups is as good as resourceGroups

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we will look into this in a separate task.

@@ -59,7 +59,7 @@ const (
// Azure represents Azure CNI network plugin
Azure NetworkPlugin = "azure"
// Kubenet represents Kubenet network plugin
Kubenet NetworkPlugin = "kubenet"
Kubenet NetworkPlugin = "none"
Copy link
Contributor

Choose a reason for hiding this comment

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

please use kubenet and translate to internal none

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, will do.

weinong
weinong previously approved these changes Apr 16, 2018
jackfrancis
jackfrancis previously approved these changes Apr 16, 2018
Copy link
Member

@jackfrancis jackfrancis left a comment

Choose a reason for hiding this comment

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

lgtm pending e2e

@JunSun17 JunSun17 dismissed stale reviews from jackfrancis and weinong via a54709d April 16, 2018 22:27
t.Error("error in orchestrator profile networkPlugin conversion")
}

if api.KubernetesConfig.ServiceCIDR != "" {
if api.KubernetesConfig.ServiceCIDR != "10.0.0.0/16" {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you define consts for 10.0.0.0/16 and 172.17.0.1/16

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, will do.

Copy link
Member

@jackfrancis jackfrancis 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 89de6ab into Azure:master Apr 16, 2018
@ghost ghost removed the in progress label Apr 16, 2018
@JunSun17 JunSun17 deleted the custom-vnet-apimodel-backward-compatibility branch April 16, 2018 23:53
jackfrancis pushed a commit that referenced this pull request Apr 17, 2018
* Validation logic backward compatibility support for API models converted from prior v20180331 models.

* Fix check-style.

* Simplify network plugin check.

* Change network plugin "none" to "kubenet", remove agent pool nil check.

* Set default network values in un-versioned model.

* Add defaults for network settings.
JunSun17 added a commit that referenced this pull request Apr 17, 2018
* Validation logic backward compatibility support for API models converted from prior v20180331 models.

* Fix check-style.

* Simplify network plugin check.

* Change network plugin "none" to "kubenet", remove agent pool nil check.

* Set default network values in un-versioned model.

* Add defaults for network settings.

(cherry picked from commit 89de6ab)
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.

3 participants