Skip to content

Store feature names in backend service description#305

Merged
bowei merged 3 commits intokubernetes:masterfrom
MrHohn:backend-service-description-version
Jun 16, 2018
Merged

Store feature names in backend service description#305
bowei merged 3 commits intokubernetes:masterfrom
MrHohn:backend-service-description-version

Conversation

@MrHohn
Copy link
Copy Markdown
Member

@MrHohn MrHohn commented Jun 5, 2018

/assign @rramkumar1

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 5, 2018
@MrHohn
Copy link
Copy Markdown
Member Author

MrHohn commented Jun 5, 2018

cc @bowei

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

description is misspelled

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, done.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Will remove security policy related thing from this PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

@MrHohn MrHohn force-pushed the backend-service-description-version branch 5 times, most recently from 08a63c7 to d3ec794 Compare June 7, 2018 18:15
@MrHohn MrHohn force-pushed the backend-service-description-version branch from d3ec794 to 81f2ecb Compare June 8, 2018 21:48
@MrHohn MrHohn changed the title Bake compute version into backend service description Store feature names in backend service description Jun 8, 2018
@MrHohn MrHohn force-pushed the backend-service-description-version branch from 81f2ecb to 284b61c Compare June 8, 2018 22:09
@MrHohn
Copy link
Copy Markdown
Member Author

MrHohn commented Jun 8, 2018

@rramkumar1 @bowei Revised PR to store feature names instead. PTAL thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not just iterate through versionToFeatures?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Humm, could you elaborate? Maybe the func name is confusing, it tries to get what features are used by the given servicePort.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Doesn't versionToFeatures contain all non-ga features? I was wondering why you can't just use that in this function rather than doing those if conditions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry I didn't mean to say iterate, that was confusing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Humm, this function isn't really relevant to versionToFeatures. It is not about getting all possible non-GA features, but getting the features that are currently in used by the passed in ServicePort. I renamed it to featuresFromServicePort() which hopefully makes a little more sense..

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, I was misunderstanding what that function was doing, makes sense now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: Remove the period from the comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if at some point we should add this to the cloud provider layer as an extension method on meta.Version.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if this we should put this in serviceport.go?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm having some cyclic import issues. I would like to put description struct along with the Description func, which depends on some functions implemented in package "features". Meanwhile package "features" needs to import ServicePort from package "utils"...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

any reason why this is exported? Doesn't seem like its being used outside of this package.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nope, changed to not exported.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you call this NonGAFeatures to be consistent with the json tag.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure, done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add a type alias for the features slice?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sorry, do you mean making a alias type for feature itself?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah I think we should just have type Feature string

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sounds good, done.

@MrHohn MrHohn force-pushed the backend-service-description-version branch 3 times, most recently from cf9c7d6 to 8c00e0f Compare June 8, 2018 23:10
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Changed from non-ga-features to x-features as suggested in doc.

@MrHohn MrHohn force-pushed the backend-service-description-version branch 3 times, most recently from 04864b1 to bf4c748 Compare June 9, 2018 00:50
Copy link
Copy Markdown
Contributor

@rramkumar1 rramkumar1 Jun 10, 2018

Choose a reason for hiding this comment

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

Should we have an additional unit test here to test the description functionality or do the existing unit tests cover it?

Copy link
Copy Markdown
Member Author

@MrHohn MrHohn Jun 11, 2018

Choose a reason for hiding this comment

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

Added a TODO for myself to add additional test here.

@rramkumar1
Copy link
Copy Markdown
Contributor

/assign @nicksardo
/assign @bowei

Copy link
Copy Markdown
Member

@bowei bowei left a comment

Choose a reason for hiding this comment

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

move description up and make the serviceport, feature do Set(desc)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

create a const map that goes from version to the set {1,2,3} and compare the numbers

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

featuresToStringSet

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Function removed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

just have this as a string

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

document

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

document

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

doc

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

@MrHohn MrHohn force-pushed the backend-service-description-version branch from bf4c748 to 32a45a8 Compare June 13, 2018 19:23
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 13, 2018
@MrHohn
Copy link
Copy Markdown
Member Author

MrHohn commented Jun 13, 2018

move description up and make the serviceport, feature do Set(desc)

@bowei Moved description out of serviceport and features and rearranged some of the functions. PTAL thanks!

// ensureDescription updates the BackendService Description with the expected value
func ensureDescription(be *composite.BackendService, description string) (needsUpdate bool) {
if be.Description == description {
func ensureDescription(be *composite.BackendService, sp utils.ServicePort) (needsUpdate bool) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sp *utils.ServicePort?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

*/

// This package contains the implementations of backend service
// features.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

you should document what needs to happen when a feature is added (do it in a follow up PR)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sounds good, added a TODO comment.


// IsLowerVersion reutrns if v1 is a lower version than v2.
func IsLowerVersion(v1, v2 meta.Version) bool {
versionMap := map[meta.Version]int{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

you can make this a global to avoid constructing it every time the func is called

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

}

// GetDescriptionFromString gets a Description from string,
func GetDescriptionFromString(descString string) Description {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

no need for Get

DescriptionFromString

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

}

// GetDescriptionFromString gets a Description from string,
func GetDescriptionFromString(descString string) Description {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

return *Description

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

}
var desc Description
if err := json.Unmarshal([]byte(descString), &desc); err != nil {
glog.Errorf("Failed to parse description: %s, falling back to empty list", descString)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this seems problematic, return an error

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The idea is that: in case of the description is messed up on backend service, the controller will fall back to assume the backend service was using GA (because the features field is empty) instead of halting the ingress sync.

On the other hand, if fail to parse description blocks the sync, it will prevent controller from fixing the description on backend service as well.

if sp.Protocol == annotations.ProtocolHTTP2 {
return meta.VersionAlpha
// GetDescription returns a Description for this ServicePort.
func (sp ServicePort) GetDescription() Description {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

no need for get

func Description()

return *Description

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The function was renamed to GetDescription() because Description itself is a struct now.

}
)

// IsLowerVersion reutrns if v1 is a lower version than v2.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

spelling

@bowei bowei merged commit 87d86be into kubernetes:master Jun 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants