-
Notifications
You must be signed in to change notification settings - Fork 82
Conversation
ca31a8d
to
7001eb7
Compare
ksonnet-gen/kubeversion/version.go
Outdated
// Beta returns the beta status of the version. | ||
func Beta(k8sVersion string) bool { | ||
verData, ok := versions[k8sVersion] | ||
if !ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't want to be erroring out on if someone supplies 1.8.1
or 1.7.5
. Thoughts on how this should be handled? I think we should check for patch versions and as long as the minor version is supported, return true / false accordingly. Only error where minor versions aren't supported.
Likewise is 1.6
currently supported by ks
? If yes, we should probably return false for anything less than the highest minor version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated it to return false if 1) it doesn't know the version, 2) the version beta flag is set to false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we may need to do a little more work here because ks
wouldn't be able to warn users on 1.8.1
.
Maybe for now just add a check:
const (
maxVersion := "v.1.8."
)
if strings.HasPrefix(k8sVersion, maxVersion) {
return true
}
... (insert other logic you have)
or something.
"importstr": "\"importstr\"", | ||
"in": "\"in\"", | ||
// TODO: this needs to be resolved | ||
// "local": "\"local\"", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be resolved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not today. It was broken in master as well.
Modifies ksonnet-gen to support the new definition semantics added in in Kubernetes 1.8.0. Signed-off-by: bryanl <bryanliles@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of suggestions that are non-blocking.
Ran errcheck
to make sure introduction of error
into signatures didn't inadvertently introduce places we're accidentally ignoring an error.
Also I'm in favor of moving to the return-an-error approach (rather than the panic approach that exists currently). Historically we used panic to try to fail quickly with a stack trace, since we didn't how the swagger schema was structured. Now we do, so there's fewer advantages to it.
@@ -32,6 +40,39 @@ func Emit(spec *kubespec.APISpec, ksonnetLibSHA, k8sSHA *string) ([]byte, []byte | |||
// Root. | |||
//----------------------------------------------------------------------------- | |||
|
|||
func usesLegacySchema(version string) (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think this is worth sourcing to a semver library? I think this whole function can be a couple lines of code in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not in this change set. We don't even have a way of managing dependencies and we are under a time crunch.
@@ -46,26 +87,59 @@ type root struct { | |||
|
|||
ksonnetLibSHA *string | |||
k8sSHA *string | |||
|
|||
isLegacySchema bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally? I would make usesLegacySchema
a method (e.g., root#isLegacySchema
) which inspects spec.info.Version
and returns true if the version works.
Rationale is, I think it's a little harder to maintain isLegacySchema
as state, and since we don't care about perf here, I don't see a penalty to re-parsing and comparing versions any time we need to know whether it's a legacy schema. It also simplifies newRoot
somewhat.
for defName, def := range spec.Definitions { | ||
if def.IsCRD() { | ||
crds[defName] = false | ||
ref := def.Properties["Schema"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote this with a hardcoded string to confirm it works, but if I was writing it for prod, I'd handle this logic in the SchemaDefinition
rather than relying on the emission routines to parse the schema definitions. Maybe worth replacing SchemaDefinition#IsCRD
with something like SchemaDefinition#CRDSchemaName() (DefinitionName, bool)
(or something) which would allow us to write the following (which I estimate to be clearer):
if crdDefName, isCRD := def.CRDSchemaName(); isCRD {
crds[defName] = false
crds[crdDefName] = false
}
So, this function would retrieve the "Schema"
member, perform the strings.TrimPrefix
below, and return as a DefinitionName, true
(or "", false
if not found).
@@ -85,60 +159,83 @@ func (root *root) emit(m *indentWriter) { | |||
m.indent() | |||
|
|||
// Emit in sorted order so that we can diff the output. | |||
groups := root.groups.toSortedSlice() | |||
var groupNames []string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I don't see groupNames
being used anywhere? Am I missing something?
for _, g := range groups { | ||
groupNames = append(groupNames, string(g.name)) | ||
} | ||
|
||
for _, group := range root.groups.toSortedSlice() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're calling root.groups.toSortedSlice()
twice (once here and once on 162). This should be deterministic, so it seems like we might as well just re-use instead of sorting twice?
} | ||
|
||
func (root *root) createAPIObject( | ||
func (r *root) createAPIObject( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just FYI, renaming root
-> r
causes the linter to complain. Here and below.
dn, err := parsedName.Unparse(r.isLegacySchema) | ||
if err != nil { | ||
return nil, fmt.Errorf("unparse definition name: %v", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since dn
is only used in the error, you might want to move this into the error block. (Though this doesn't apply, in my estimation, below in functions like getAPIObjectHelper
.)
if ok { | ||
log.Panicf("Duplicate object kinds with name '%s'", parsedName.Unparse()) | ||
var names []string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I might be missing something, but names
doesn't seem to be used?
} | ||
) | ||
|
||
type description struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few things.
- It seems like
description#Validate
is not used? - It seems like actually
describeDefinition
is really just doing whatDefinitionName#Parse
should be doing? Should we just move this code there? - If I'm missing something in (2) and this needs to stay in its own file, do you mind if we call this file something other than
new.go
(and also renamedescription
to something else, since it's really actually aDefinitionName
)? :) (I suspect this was a placeholder name.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm marking "approve" since I don't see any bugs and we are under pressure to ship. I do hope we can come back and address these comments, though.
Discussed offline with @bryanl -- we will pull these issues up as a group and discuss next week. He is OOO for now, so I'm proceeding with the merge. |
Making ksonnet-lib Kubernetes 1.8.0 aware.