Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ New API for Server Groups #1779

Merged
merged 2 commits into from
Jan 8, 2024

Conversation

stephenfin
Copy link
Contributor

@stephenfin stephenfin commented Dec 7, 2023

What this PR does / why we need it:

Allow users to (a) specify server groups by name or (b) defer management of server groups to CAPO.

Note

This is a proposal to allow me test out ideas before writing a KEP. It's
intentionally incomplete so we can focus on the API first.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):

n/a

Special notes for your reviewer:

n/a

TODOs:

  • Implement non-API code
  • Run make generate
  • Propose KEP?

/hold

@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Dec 7, 2023
Copy link

netlify bot commented Dec 7, 2023

Deploy Preview for kubernetes-sigs-cluster-api-openstack ready!

Name Link
🔨 Latest commit 32369b6
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-cluster-api-openstack/deploys/659be64885ff190008ccb5ab
😎 Deploy Preview https://deploy-preview-1779--kubernetes-sigs-cluster-api-openstack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 7, 2023
api/v1alpha7/openstackmachine_types.go Outdated Show resolved Hide resolved
api/v1alpha7/openstackmachine_types.go Outdated Show resolved Hide resolved
api/v1alpha7/types.go Outdated Show resolved Hide resolved
api/v1alpha7/managed_server_groups.go Outdated Show resolved Hide resolved
@EmilienM
Copy link
Contributor

EmilienM commented Dec 7, 2023

/cc EmilienM

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 8, 2023
@stephenfin stephenfin force-pushed the better-server-groups branch 3 times, most recently from 3155371 to f6d6a88 Compare December 8, 2023 16:59
@stephenfin stephenfin marked this pull request as ready for review December 8, 2023 17:31
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 8, 2023
@@ -562,8 +568,18 @@ func applyServerGroupID(opts servers.CreateOptsBuilder, serverGroupID string) se
return opts
}

// Helper function for getting image id from name.
func (s *Service) getImageIDFromName(imageName string) (string, error) {
// Helper function for getting image ID from name or ID.
Copy link
Contributor

Choose a reason for hiding this comment

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

Helper function for getting image ID from name or ID.

this seems confusing

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 agree 😄 However, despite what GitHub says I didn't write this. This is being picked up as a moved line when in fact I simply renamed the function from getImageID to GetImageID and folded getImageIDFromName into this. It's also technically true.

if err != nil {
return "", err
}
if serverGroupFilter.Name != "" && serverGroupFilter.Name != serverGroup.Name {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we really have this check? or just safely ignore the Name ? I think the logic here want to make sure they are consistent..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So while I think this is silly check and I think providing both a name and ID is even sillier, but if someone does it then I think we should respect their request fully. To not do so would be confusing.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm with @jichenjc on this one. Can we not just add an admission validation that if you specify ID you can't specify anything else?

If the machine creation fails because the specified ID was invalid that should be reported in the machine status.

Copy link
Contributor

@mdbooth mdbooth left a comment

Choose a reason for hiding this comment

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

I think this is mostly there. I'd like to:

  • Rebase on to v1alpha8
  • Consequently, take the opportunity the remove the ServerGroupID field
  • Remove changes to ImageID in status unless I'm missing some reason it's required for Server Groups (it's good but I'd prefer a separate PR)
  • Remove additional validation of SecurityGroup specified by ID

Comment on lines 116 to 117
// ImageID contains the ID of the image this machine was created with.
ImageID string `json:"imageID,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we also adding ImageID here? It seems like a good addition, but does it need to happen in this PR?

if err != nil {
return "", err
}
if serverGroupFilter.Name != "" && serverGroupFilter.Name != serverGroup.Name {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm with @jichenjc on this one. Can we not just add an admission validation that if you specify ID you can't specify anything else?

If the machine creation fails because the specified ID was invalid that should be reported in the machine status.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 15, 2023
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 19, 2023
@dulek
Copy link
Contributor

dulek commented Dec 19, 2023

I tried to implement Matt's remarks based on his own version of this code. I think I'm still failing to get the conversions or the conversions tests right, will continue on that.

ServerGroupID string `json:"serverGroupID,omitempty"`
// The server group to assign the machine to.
// +optional
ServerGroup *ServerGroupFilter `json:"serverGroup,omitempty"`
Copy link
Contributor

@EmilienM EmilienM Dec 19, 2023

Choose a reason for hiding this comment

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

Copy link
Contributor

@EmilienM EmilienM left a comment

Choose a reason for hiding this comment

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

beside a few nits which can be fixed later, I think this is good to go (feel free to do it in this PR though)

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 22, 2023
@EmilienM
Copy link
Contributor

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 22, 2023

### `OpenStackMachine`

#### Change to `serverGroupID`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
#### Change to `serverGroupID`
#### ⚠️ Change to `serverGroupID`

docs/book/src/topics/crd-changes/v1alpha7-to-v1alpha8.md Outdated Show resolved Hide resolved
docs/book/src/topics/crd-changes/v1alpha7-to-v1alpha8.md Outdated Show resolved Hide resolved
Copy link
Contributor

@mdbooth mdbooth left a comment

Choose a reason for hiding this comment

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

There's something wrong with the API conversions, but the rest of it lgtm.

pkg/cloud/services/compute/referenced_resources_test.go Outdated Show resolved Hide resolved
pkg/cloud/services/compute/servergroup_test.go Outdated Show resolved Hide resolved
@@ -0,0 +1,99 @@
/*
Copyright 2018 The Kubernetes Authors.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Copyright 2018 The Kubernetes Authors.
Copyright 2024 The Kubernetes Authors.

if in.ServerGroupID != "" {
out.ServerGroup = &infrav1.ServerGroupFilter{ID: in.ServerGroupID}
} else {
out.ServerGroup = &infrav1.ServerGroupFilter{}
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't necessary. You don't need to set ServerGroup in this case: it can safely be nil.

Copy link
Contributor

Choose a reason for hiding this comment

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

Somehow tests fail when this is set. I have hard time debugging these, I could use pairing with someone who would teach me how to debug conversion tests failures.

func(v1alpha8OpenStackMachine *infrav1.OpenStackMachine, c fuzz.Continue) {
c.FuzzNoCustom(v1alpha8OpenStackMachine)

// None of the following fields have ever been set in v1alpha7
Copy link
Contributor

Choose a reason for hiding this comment

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

This is v1alpha8, though, and they are set in v1alpha8.

Comment on lines 63 to 84

func(v1alpha8OpenStackMachine *infrav1.OpenStackMachine, c fuzz.Continue) {
c.FuzzNoCustom(v1alpha8OpenStackMachine)

// None of the following fields have ever been set in v1alpha7
v1alpha8OpenStackMachine.Status.ReferencedResources = infrav1.ReferencedMachineResources{}
},

func(v1alpha8OpenStackCluster *infrav1.OpenStackCluster, c fuzz.Continue) {
c.FuzzNoCustom(v1alpha8OpenStackCluster)

// None of the following fields have ever been set in v1alpha7
if v1alpha8OpenStackCluster.Status.Bastion != nil {
v1alpha8OpenStackCluster.Status.Bastion.ReferencedResources = infrav1.ReferencedMachineResources{}
}
},

func(v1alpha8ServerGroupFilter *infrav1.ServerGroupFilter, c fuzz.Continue) {
c.FuzzNoCustom(v1alpha8ServerGroupFilter)

// None of the following fields have ever been set in v1alpha7
v1alpha8ServerGroupFilter.Name = ""
},
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't look right to me. We should support round-trip conversion of all of these new fields without constraining the fuzzer.

Copy link
Contributor

Choose a reason for hiding this comment

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

For reference, @mdbooth found a problem in the conversion functions: RestoreField must be provided to a HashedFieldRestorer. AFIK he's working on a patch now to address this so we can apply that in ongoing PRs where I wrote these unwanted fuzzer functions.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 4, 2024
@dulek
Copy link
Contributor

dulek commented Jan 4, 2024

I addressed the docs and comments issue. I'm not sure how to debug the conversions though.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 5, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 5, 2024
@EmilienM
Copy link
Contributor

EmilienM commented Jan 5, 2024

I've addressed the conversion stuff.

@EmilienM
Copy link
Contributor

EmilienM commented Jan 5, 2024

/test pull-cluster-api-provider-openstack-e2e-test

Comment on lines +242 to +261
} else {
out.ServerGroup = nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: This can be omitted.

}

func Convert_v1alpha8_OpenStackMachineStatus_To_v1alpha7_OpenStackMachineStatus(in *infrav1.OpenStackMachineStatus, out *OpenStackMachineStatus, s apiconversion.Scope) error {
// ReferencedResources have no equivalent in v1alpha7
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// ReferencedResources have no equivalent in v1alpha7
// ReferencedResources has no equivalent in v1alpha7

}

func Convert_v1alpha8_BastionStatus_To_v1alpha7_BastionStatus(in *infrav1.BastionStatus, out *BastionStatus, s apiconversion.Scope) error {
// ReferencedResources have no equivalent in v1alpha7
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// ReferencedResources have no equivalent in v1alpha7
// ReferencedResources has no equivalent in v1alpha7

Comment on lines +267 to +286
} else {
out.Instance.ServerGroup = nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: This can be omitted.

Comment on lines 63 to 84

func(v1alpha8OpenStackMachine *infrav1.OpenStackMachine, c fuzz.Continue) {
c.FuzzNoCustom(v1alpha8OpenStackMachine)

v1alpha8OpenStackMachine.Status.ReferencedResources = infrav1.ReferencedMachineResources{}
},

func(v1alpha8OpenStackCluster *infrav1.OpenStackCluster, c fuzz.Continue) {
c.FuzzNoCustom(v1alpha8OpenStackCluster)

// None of the following fields have ever been set in v1alpha7
if v1alpha8OpenStackCluster.Status.Bastion != nil {
v1alpha8OpenStackCluster.Status.Bastion.ReferencedResources = infrav1.ReferencedMachineResources{}
}
},

func(v1alpha8ServerGroupFilter *infrav1.ServerGroupFilter, c fuzz.Continue) {
c.FuzzNoCustom(v1alpha8ServerGroupFilter)

// None of the following fields have ever been set in v1alpha7
v1alpha8ServerGroupFilter.Name = ""
},
Copy link
Contributor

Choose a reason for hiding this comment

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

None of these should be required. I'll debug.

mdbooth and others added 2 commits January 8, 2024 11:50
Allow users to request Server Groups by either name or ID. This aligns
us with the pattern of filters used for other resources such as Security
Groups and Ports.

Additionally `ReferencedResources` field is added to `BastionStatus` and
`OpenStackMachineStatus` as a container to hold all the IDs of resources
computed by the controllers. `ServerGroupID` is the first field added
there.

Co-Authored-By: Emilien Macchi <emilien@redhat.com>
Co-Authored-By: Michał Dulko <mdulko@redhat.com>
Co-Authored-By: Stephen Finucane <stephenfin@redhat.com>
@mdbooth
Copy link
Contributor

mdbooth commented Jan 8, 2024

I've pushed a new version which makes changes only to the conversion code. It:

  • Removes all the fuzzer test workarounds in v1alpha7
  • Adds a missing restorer for ReferencedMachineResources in v1alpha7 (which was why the workarounds were required)
  • Updates the way we store ServerGroupID in v1alpha6

The last one is interesting. In v1alpha6 Instance had an unused ServerGroupID field which was removed in v1alpha7. We were storing the ServerGroupID in there. This works well for ServerGroup, but I think we're about to add more fields to this struct. As this trick is only likely to work for ServerGroupID I think it'll end up being more confusing than it's worth, so I've switched it to just doing a regular restore.

Copy link
Contributor

@EmilienM EmilienM left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 8, 2024
@mdbooth
Copy link
Contributor

mdbooth commented Jan 8, 2024

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: EmilienM, mdbooth, stephenfin

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

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 8, 2024
@k8s-ci-robot k8s-ci-robot merged commit 5f306c3 into kubernetes-sigs:main Jan 8, 2024
9 checks passed
@EmilienM EmilienM deleted the better-server-groups branch January 8, 2024 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants