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

Add machine pool logic #1795

Merged
merged 11 commits into from
Jan 27, 2023

Conversation

dimakis
Copy link
Contributor

@dimakis dimakis commented Jan 18, 2023

Addition of some machine pool logic, which validates machine pool (replica) node count --but does not currently validate name, taint or labels
constructs the payload and executes

Closes #

Verification Steps

  1. Do x
  2. Do y

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation change
  • Other (please specify)

@dimakis dimakis force-pushed the add-machine-pool-logic branch from 190102e to 85958fc Compare January 23, 2023 14:07
func validateMachinePoolNodes(opts *options) error {
if len(opts.clusterMachinePoolList.Slice()) > 0 {
for _, machinePool := range opts.clusterMachinePoolList.Slice() {
if validateMachinePoolCount(machinePool.Replicas()) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

The machinePool.Replicas() is only set for non autoscaled clusters.
For autoscaling clusters the value will we need to use here is max replicas.

I propose a functional change like

Suggested change
if validateMachinePoolCount(machinePool.Replicas()) &&
nodeCount := 0
replicas, ok := machinePool.GetReplicas()
if ok { // only retrieve the replica if not autoscaled
nodeCount = replicas
} else { // machine pool is autoscaled
autoscaledReplicas, ok := machinePool.GetAutoscaling()
if ok {
nodeCount, _ = autoscaledReplicas.GetMaxReplicas()
}
}

ClusterId: opts.selectedCluster.ID(),
ClusterExternalId: opts.selectedCluster.ExternalID(),
ClusterIngressDnsName: clusterIngressDNSName,
KafkaMachinePoolNodeCount: int32(opts.selectedClusterMachinePool.Replicas()),
Copy link
Contributor

Choose a reason for hiding this comment

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

response, r, err := resource.Execute()
if err != nil {
return err
return nil
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
return nil

Comment on lines 294 to 296
connection, err := ocmSdkClient.NewConnectionBuilder().
Tokens(a.AccessToken).
Build()
Copy link
Contributor

Choose a reason for hiding this comment

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

This will always use the api.openshift.com as base url.
That's fine for Stage/Prod

but for testing we might need the .URL() customizable somehow so that we could use api.stage.openshift.com


func (a *defaultAPI) CreateOCMConnection() (*ocmSdkClient.Connection, error) {
connection, err := ocmSdkClient.NewConnectionBuilder().
Tokens(a.AccessToken).
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 fine for Prod/Stage but for testing it might be great to have the token customizable since someone using kas-installer (https://github.com/bf2fc6cc711aee1a0c2a/kas-installer) might as well have KFM deployed using a different Auth server than the one used for OCM Stage/Prod (which is always sso.redhat.com)

}

// create an OCM clustermgmt client
func (a *defaultAPI) OCMClustermgmt() (*ocmclustersmgmtv1.Client, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not see this being used anywhere


//TODO add Localizer
cmd := &cobra.Command{
Use: "register-cluster",
Copy link
Contributor

Choose a reason for hiding this comment

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

This gives a command like

rhoas dedicated register-cluster

I am wondering if in the future we might consider

rhoas dedicated kafka register

return err
}
}
}
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
}

Copy link
Contributor

Choose a reason for hiding this comment

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

return nil
}
opts.f.Logger.Info("response: ", response)
opts.f.Logger.Info("r: ", r)
Copy link
Contributor

@machi1990 machi1990 Jan 23, 2023

Choose a reason for hiding this comment

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

To create the addon:

These method:

  1. https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/d0c418df2eeea93d22aeb5cd476d28e8eadec71a/pkg/client/ocm/client.go#L231
  2. https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/d0c418df2eeea93d22aeb5cd476d28e8eadec71a/pkg/client/ocm/client.go#L412

are useful.

The strimzi addon will have the id: managed-kafka and the parameters will be an empty list.
The fleetshard addon will have the id: kas-fleetshard-operator and the parameters will be from response.FleetshardParameters

Note: the addOns id changes depending on the environment. For Stage, they'll have a suffix of -qe e.g kas-fleetshard-operator-qe

machi1990
machi1990 previously approved these changes Jan 26, 2023
Copy link
Contributor

@machi1990 machi1990 left a comment

Choose a reason for hiding this comment

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

I've seen the demo of this working end to end. Thanks for the great work @dimakis

I'll let other experienced in the codebase have a look at the code.

@dimakis
Copy link
Contributor Author

dimakis commented Jan 26, 2023

I've seen the demo of this working end to end. Thanks for the great work @dimakis

I'll let other experienced in the codebase have a look at the code.

Thanks a million for your great and thorough help on this. Always a pleasure working with you 😁

@dimakis dimakis force-pushed the add-machine-pool-logic branch from b53657d to 70ca9dc Compare January 26, 2023 19:33
Copy link
Contributor

@rkpattnaik780 rkpattnaik780 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! Dropped a few comments. It will be better to add more inline descriptions to the functions defined here.

pkg/cmd/dedicated/dedicated.go Show resolved Hide resolved
@@ -40,7 +44,7 @@ type defaultAPI struct {
}

// New creates a new default API client wrapper
func New(cfg *api.Config) api.API {
func New(cfg *api.Config) *defaultAPI {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you briefly explain the purpose of this change?

pkg/cmd/dedicated/register/registercluster.go Outdated Show resolved Hide resolved
pkg/cmd/dedicated/register/registercluster.go Outdated Show resolved Hide resolved
pkg/cmd/dedicated/register/registercluster.go Outdated Show resolved Hide resolved
@@ -0,0 +1,433 @@
package register
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we look if this file can be split into multiple?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this file should def be split up, generic cluster mgmt api logic etc needs to move into its own dir.

I was planning on doing this after delivering the MVP

Copy link
Contributor

@rkpattnaik780 rkpattnaik780 left a comment

Choose a reason for hiding this comment

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

Needs some more localizations.

pkg/core/localize/locales/en/cmd/dedicated.en.toml Outdated Show resolved Hide resolved
pkg/core/localize/locales/en/cmd/dedicated.en.toml Outdated Show resolved Hide resolved
pkg/core/localize/locales/en/cmd/dedicated.en.toml Outdated Show resolved Hide resolved
@dimakis dimakis force-pushed the add-machine-pool-logic branch from c0a59c3 to 964152d Compare January 27, 2023 13:23
@dimakis dimakis changed the base branch from main to dedicated January 27, 2023 14:11
@dimakis dimakis dismissed machi1990’s stale review January 27, 2023 14:11

The base branch was changed.

@dimakis dimakis merged commit 08de2ed into redhat-developer:dedicated Jan 27, 2023
jackdelahunt pushed a commit that referenced this pull request Feb 28, 2023
* feat: addition of the new dedicated command to select ocm cluster

* feat: addition of getting machine pools and hitting the register cluster endpoint in KFM

* refactor: addition of close ocm connection

* fix: addition of autoscaling check logic

* refactor: addresses commments made in PR

* refactor: addresses comments in review

* feat: addition of the addon installation flow

* feat: addition of cluster-id flag

* refactor: addresses some further comments in the review

* feat: addition of localization

* refactor: addition of error when user has no valid clusters
jackdelahunt pushed a commit that referenced this pull request Mar 2, 2023
* feat: addition of the new dedicated command to select ocm cluster

* feat: addition of getting machine pools and hitting the register cluster endpoint in KFM

* refactor: addition of close ocm connection

* fix: addition of autoscaling check logic

* refactor: addresses commments made in PR

* refactor: addresses comments in review

* feat: addition of the addon installation flow

* feat: addition of cluster-id flag

* refactor: addresses some further comments in the review

* feat: addition of localization

* refactor: addition of error when user has no valid clusters
jackdelahunt pushed a commit that referenced this pull request Mar 3, 2023
* feat: addition of the new dedicated command to select ocm cluster

* feat: addition of getting machine pools and hitting the register cluster endpoint in KFM

* refactor: addition of close ocm connection

* fix: addition of autoscaling check logic

* refactor: addresses commments made in PR

* refactor: addresses comments in review

* feat: addition of the addon installation flow

* feat: addition of cluster-id flag

* refactor: addresses some further comments in the review

* feat: addition of localization

* refactor: addition of error when user has no valid clusters
jackdelahunt pushed a commit that referenced this pull request Mar 3, 2023
* feat: addition of the new dedicated command to select ocm cluster

* feat: addition of getting machine pools and hitting the register cluster endpoint in KFM

* refactor: addition of close ocm connection

* fix: addition of autoscaling check logic

* refactor: addresses commments made in PR

* refactor: addresses comments in review

* feat: addition of the addon installation flow

* feat: addition of cluster-id flag

* refactor: addresses some further comments in the review

* feat: addition of localization

* refactor: addition of error when user has no valid clusters
jackdelahunt pushed a commit that referenced this pull request Mar 7, 2023
* feat: addition of the new dedicated command to select ocm cluster

* feat: addition of getting machine pools and hitting the register cluster endpoint in KFM

* refactor: addition of close ocm connection

* fix: addition of autoscaling check logic

* refactor: addresses commments made in PR

* refactor: addresses comments in review

* feat: addition of the addon installation flow

* feat: addition of cluster-id flag

* refactor: addresses some further comments in the review

* feat: addition of localization

* refactor: addition of error when user has no valid clusters
dimakis added a commit that referenced this pull request Mar 8, 2023
* Enterprise crete kafka interactive (#1819)

* refactor: moving list enterprise clusters to util package

* feat: start of interactive enterprise create

* refactor: refactor of create kafka ams checks for enterprise quota (#1822)

* feat: when using dedicated with kafka create, we now check the capacity
of the cluster

* refactor: refactor of the interactive create kafka cmd

* refactor: refactoring dedicated list to use refactored search string func

* refactor: refactor and addition of name + id of cluster in prompt

* refactor: refactor to functional create enterprise flow with some updates based on reviews

* Add machine pool logic (#1795)

* feat: addition of the new dedicated command to select ocm cluster

* feat: addition of getting machine pools and hitting the register cluster endpoint in KFM

* refactor: addition of close ocm connection

* fix: addition of autoscaling check logic

* refactor: addresses commments made in PR

* refactor: addresses comments in review

* feat: addition of the addon installation flow

* feat: addition of cluster-id flag

* refactor: addresses some further comments in the review

* feat: addition of localization

* refactor: addition of error when user has no valid clusters

* chore(vendor): update vendoring (#1798)

* Add cluster id to create kafka (#1804)

* feat: addition of descriptions and examples to dedicated

* feat: Allows the CLI to install stage env addons when terraforming customer-cloud dataplane clusters

* refactor: the default api url is now set when creating a connection instead of in the registercluster cmd file

* refactor: update some func and var names

* refactor: add cluster-id flag to create kafka cmd to allow kafka creation on CC cluster

* refactor: doc and small refactor

* refactor: Refactor ocm methods out of register cmd file (#1807)

* feat: addition of descriptions and examples to dedicated

* feat: Allows the CLI to install stage env addons when terraforming customer-cloud dataplane clusters

* refactor: extraction of clustermgmt funcs from register to own dir

* refactor: addresses cluster pagination and refactor of ocm functions

* feat: added deregister command

* refactor: imrpoved quality of deregister command

* chore: added localisation to deregister command

* feat: deregister now waits for all kafkas to be deleted

* fix: better logging when deleting kafka

* refactor: getting cluster list now ask kfm then ocm

* chore: remove unused fields

* fix: edge case handling in deregister

* docs: update the docs (#1826)

* refactor: print the httpresponse (#1827)

* fix: fixing broken lints

* chore: rebase changes

---------

Co-authored-by: Dimitri Saridakis <[email protected]>
Co-authored-by: Ramakrishna Pattnaik <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants