Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Add 'version' field to ESC. Auto-generate Elasticsearch image details #205

Merged
merged 11 commits into from
Jan 18, 2018

Conversation

munnerz
Copy link
Contributor

@munnerz munnerz commented Jan 13, 2018

What this PR does / why we need it:

This PR adds a version field to an ElasticsearchCluster. It is used to auto-default the ElasticsearchImageSpec in its absence. If a user wants to override the image to be used and take manual control, they can specify their own fields as before.

The new version field should be required regardless whether the image is manually specified, as in future it can be used to help influence upgrade strategy. It will be up to the administrator to update the image and listed version in unison.

In future we should make the default image repository and uid be configurable.

Special notes for your reviewer:

Ensuring the spec.version field is set will be in a follow up after #199 is merged

Release note:

Add a new spec.version field to ElasticsearchCluster and auto-default the image version and repository to an official upstream image.

@munnerz
Copy link
Contributor Author

munnerz commented Jan 15, 2018

/test e2e

1 similar comment
@munnerz
Copy link
Contributor Author

munnerz commented Jan 15, 2018

/test e2e

Copy link
Member

@wallrj wallrj left a comment

Choose a reason for hiding this comment

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

Looks good, but similar questions as for #206

  • If I omit the ElasticSearch image spec when I create my cluster resource, what happens when I try and change the new Version attribute?
  • Do I then need to also provide the full image spec or will the appropriate default image spec be selected for that version?

if esImage.FsGroup == 0 &&
esImage.ImageSpec.PullPolicy == "" &&
esImage.ImageSpec.Repository == "" &&
esImage.ImageSpec.Tag == "" {
Copy link
Member

Choose a reason for hiding this comment

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

  • Why check for FsGroup here?
  • Could you instead compare esImage.ImageSpec to the zero value of ImageSpec?
  • What if I supply FsGroup, but omit the ImageSpec? It looks like the pod will fail to start.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Changing the version attribute is expected use. This should cause navigator to begin an upgrade/downgrade/report an error that upgrade/downgrade isn't possible.

  2. Nope - provide the version and everything else is handled for you. As soon as you specify either FsGroup, PullPolicy, Repository or Tag however, you've gone into manual mode. Manual mode might be removed at some point in the future (as discussed today)

  3. As above, fsGroup is checked because if specified, you've switched to 'manual mode' (and so all the others are required too). Perhaps this will make a bit more sense once we get the validation PR (Add basic ElasticsearchCluster resource validation #199) merged.

  4. Yep potentially we could just check the zero values - or as you suggested earlier, make this field a pointer.

  5. Yep you are correct. FsGroup = manual mode. Remember users never see imageSpec as a field (as it's json tag is: json:",inline")

@jetstack-ci-bot
Copy link
Contributor

@munnerz PR needs rebase

@munnerz
Copy link
Contributor Author

munnerz commented Jan 17, 2018

/test e2e

},
// We don't error here - if the specified version is non semver but the
// user has specified a manual image, validation should detect the
// invalid semver and fail.
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we always error with non-semver version?
Or does this comment mean that the non-semver version will be caught and rejected by resource validation in #199?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Precisely that - yep. It seems odd to return an error in this case. The function should be returning the image that should be used for the spec, and the image is explicitly defined in the manifest, so there's not really an error.

There is however an error with the overall state/spec of the cluster, and validation should be responsible for detecting this. I guess more gates isn't a bad thing, but I think the gate might need to be moved to some other function if we do add it. I'm working on validation now and will expand that PR to encompass new fields added here once merged.

Copy link
Member

@wallrj wallrj left a comment

Choose a reason for hiding this comment

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

Thanks @munnerz

Looks great. I like your change to make ESImage a reference. And happy to see the unit tests. 👍

  • I've always been taught to convert to rich types as soon as possible, so
  • I'd be inclined to make the Version *semver.Version,
  • assuming that it's simple to register a JSON unmarshaller for that type.
  • That way we wouldn't have to parse the Semver everytime we need to use it.

Up to you. Merge when you're happy with everything.

@@ -89,10 +89,11 @@ type ElasticsearchClusterList struct {
}

type ElasticsearchClusterSpec struct {
Version string
Copy link
Member

Choose a reason for hiding this comment

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

I'd be inclined to make this type *semver.Version ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure we can just make this some other struct. The Golang JSON parser would fail because string is not a structure, which it would expect the field to be.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That said, UnmarshalJSON etc. is defined so maybe it would. I'll take a look. Depending on external types in our apis can get pretty prickly though - if we update our dependency it could cause breaking API changes (and we don't 'control' the downstream code, which makes it harder to fix/manage)

@munnerz
Copy link
Contributor Author

munnerz commented Jan 17, 2018

/test e2e

@munnerz
Copy link
Contributor Author

munnerz commented Jan 17, 2018

@wallrj I've updated the PR to make the new Version field in our API into a semver.Version.

The unit tests obviously work with Golang structs (and pass), but they don't test the unmarshalling from a string. I've added a version parameter to the Elasticsearch Cluster test fixture for our e2e tests in order to verify this works correctly, and from what I can see it is passing happily.

Once #199 merges, I'll add further validation to this to stop invalid values being submitted to the API.

@munnerz
Copy link
Contributor Author

munnerz commented Jan 17, 2018

I've added additional validation to this now, which ensures that version is specified.

Unmarshaling will error if an invalid string is provided, but it doesn't error if no string is provided (it returns nil). In order to handle this case, I check for an empty semver.Version struct during validation and throw a Required error in this case.

@jetstack-ci-bot
Copy link
Contributor

@munnerz PR needs rebase

Copy link
Member

@wallrj wallrj left a comment

Choose a reason for hiding this comment

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

Thanks @munnerz

Just take another look at those error cases in the tests I think they need modifying.

Then merge when happy.

NodePools: []navigator.ElasticsearchClusterNodePool{validNodePool, validNodePool},
Pilot: validPilotImage,
Image: validESImage,
},
Copy link
Member

Choose a reason for hiding this comment

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

Version is missing from all the other error cases too.
So it's not clear whether they're failing because of version or minimummaster

Copy link
Member

@wallrj wallrj left a comment

Choose a reason for hiding this comment

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

/lgtm

@jetstack-ci-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wallrj

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@jetstack-ci-bot
Copy link
Contributor

@munnerz PR needs rebase

@jetstack-ci-bot
Copy link
Contributor

/lgtm cancel //PR changed after LGTM, removing LGTM. @munnerz @wallrj

@jetstack-ci-bot
Copy link
Contributor

/lgtm cancel //PR changed after LGTM, removing LGTM. @munnerz @wallrj

@jetstack-ci-bot
Copy link
Contributor

/test all [submit-queue is verifying that this PR is safe to merge]

@jetstack-ci-bot
Copy link
Contributor

Automatic merge from submit-queue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants