Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Support k8s 1.8.0 #90

Merged
merged 1 commit into from
Dec 1, 2017
Merged

Support k8s 1.8.0 #90

merged 1 commit into from
Dec 1, 2017

Conversation

bryanl
Copy link
Member

@bryanl bryanl commented Nov 30, 2017

Making ksonnet-lib Kubernetes 1.8.0 aware.

@bryanl bryanl force-pushed the support-1.8 branch 2 times, most recently from ca31a8d to 7001eb7 Compare December 1, 2017 20:15
@bryanl bryanl self-assigned this Dec 1, 2017
// Beta returns the beta status of the version.
func Beta(k8sVersion string) bool {
verData, ok := versions[k8sVersion]
if !ok {
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

@jessicayuen jessicayuen Dec 1, 2017

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\"",
Copy link
Contributor

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?

Copy link
Member Author

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.

@bryanl bryanl changed the title [WIP] Support k8s 1.8.0 Support k8s 1.8.0 Dec 1, 2017
Modifies ksonnet-gen to support the new definition semantics
added in in Kubernetes 1.8.0.

Signed-off-by: bryanl <bryanliles@gmail.com>
Copy link
Contributor

@jessicayuen jessicayuen left a comment

Choose a reason for hiding this comment

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

This LGTM.

Copy link
Contributor

@hausdorff hausdorff left a 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) {
Copy link
Contributor

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.

Copy link
Member Author

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
Copy link
Contributor

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"]
Copy link
Contributor

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
Copy link
Contributor

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() {
Copy link
Contributor

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(
Copy link
Contributor

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)
}
Copy link
Contributor

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
Copy link
Contributor

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

A few things.

  1. It seems like description#Validate is not used?
  2. It seems like actually describeDefinition is really just doing what DefinitionName#Parse should be doing? Should we just move this code there?
  3. 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 rename description to something else, since it's really actually a DefinitionName)? :) (I suspect this was a placeholder name.)

Copy link
Contributor

@hausdorff hausdorff left a 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.

@jessicayuen
Copy link
Contributor

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.

@jessicayuen jessicayuen merged commit e807702 into ksonnet:master Dec 1, 2017
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