Store feature names in backend service description#305
Store feature names in backend service description#305bowei merged 3 commits intokubernetes:masterfrom
Conversation
|
cc @bowei |
pkg/utils/serviceport.go
Outdated
There was a problem hiding this comment.
description is misspelled
pkg/utils/serviceport_test.go
Outdated
There was a problem hiding this comment.
Will remove security policy related thing from this PR.
08a63c7 to
d3ec794
Compare
d3ec794 to
81f2ecb
Compare
81f2ecb to
284b61c
Compare
|
@rramkumar1 @bowei Revised PR to store feature names instead. PTAL thanks! |
pkg/backends/features/features.go
Outdated
There was a problem hiding this comment.
Why not just iterate through versionToFeatures?
There was a problem hiding this comment.
Humm, could you elaborate? Maybe the func name is confusing, it tries to get what features are used by the given servicePort.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Sorry I didn't mean to say iterate, that was confusing.
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
Sorry, I was misunderstanding what that function was doing, makes sense now.
pkg/backends/backends.go
Outdated
There was a problem hiding this comment.
Nit: Remove the period from the comment.
pkg/backends/features/features.go
Outdated
There was a problem hiding this comment.
I wonder if at some point we should add this to the cloud provider layer as an extension method on meta.Version.
pkg/backends/features/features.go
Outdated
There was a problem hiding this comment.
I wonder if this we should put this in serviceport.go?
There was a problem hiding this comment.
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"...
pkg/backends/features/features.go
Outdated
There was a problem hiding this comment.
any reason why this is exported? Doesn't seem like its being used outside of this package.
There was a problem hiding this comment.
Nope, changed to not exported.
pkg/backends/features/features.go
Outdated
There was a problem hiding this comment.
Can you call this NonGAFeatures to be consistent with the json tag.
pkg/backends/features/features.go
Outdated
There was a problem hiding this comment.
Can we add a type alias for the features slice?
There was a problem hiding this comment.
Sorry, do you mean making a alias type for feature itself?
There was a problem hiding this comment.
Yeah I think we should just have type Feature string
cf9c7d6 to
8c00e0f
Compare
pkg/backends/features/features.go
Outdated
There was a problem hiding this comment.
Changed from non-ga-features to x-features as suggested in doc.
04864b1 to
bf4c748
Compare
pkg/backends/backends_test.go
Outdated
There was a problem hiding this comment.
Should we have an additional unit test here to test the description functionality or do the existing unit tests cover it?
There was a problem hiding this comment.
Added a TODO for myself to add additional test here.
|
/assign @nicksardo |
bowei
left a comment
There was a problem hiding this comment.
move description up and make the serviceport, feature do Set(desc)
pkg/backends/features/features.go
Outdated
There was a problem hiding this comment.
create a const map that goes from version to the set {1,2,3} and compare the numbers
pkg/backends/features/features.go
Outdated
pkg/backends/features/features.go
Outdated
pkg/backends/features/features.go
Outdated
pkg/backends/features/features.go
Outdated
pkg/backends/features/features.go
Outdated
bf4c748 to
32a45a8
Compare
@bowei Moved description out of serviceport and features and rearranged some of the functions. PTAL thanks! |
pkg/backends/backends.go
Outdated
| // 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) { |
| */ | ||
|
|
||
| // This package contains the implementations of backend service | ||
| // features. |
There was a problem hiding this comment.
you should document what needs to happen when a feature is added (do it in a follow up PR)
There was a problem hiding this comment.
Sounds good, added a TODO comment.
pkg/backends/features/features.go
Outdated
|
|
||
| // IsLowerVersion reutrns if v1 is a lower version than v2. | ||
| func IsLowerVersion(v1, v2 meta.Version) bool { | ||
| versionMap := map[meta.Version]int{ |
There was a problem hiding this comment.
you can make this a global to avoid constructing it every time the func is called
pkg/utils/description.go
Outdated
| } | ||
|
|
||
| // GetDescriptionFromString gets a Description from string, | ||
| func GetDescriptionFromString(descString string) Description { |
There was a problem hiding this comment.
no need for Get
DescriptionFromString
pkg/utils/description.go
Outdated
| } | ||
|
|
||
| // GetDescriptionFromString gets a Description from string, | ||
| func GetDescriptionFromString(descString string) Description { |
| } | ||
| 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) |
There was a problem hiding this comment.
this seems problematic, return an error
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
no need for get
func Description()
return *Description
There was a problem hiding this comment.
The function was renamed to GetDescription() because Description itself is a struct now.
| } | ||
| ) | ||
|
|
||
| // IsLowerVersion reutrns if v1 is a lower version than v2. |
/assign @rramkumar1