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

MGMT-15704 Assisted service should create Day2 import CR for hub cluster. #5459

Merged
merged 1 commit into from Sep 6, 2023

Conversation

paul-maidment
Copy link
Contributor

@paul-maidment paul-maidment commented Sep 5, 2023

When using assisted-service in KubeAPI mode, we want to import the local cluster automatically, allowing it to be managed in a similar fashion to the spoke cluster.

The intent is to allow the user to perform day2 operations on the local cluster, to allow the addition of workers and so on.

Presently this is only possible via manual efforts and is not very customer friendly.

This PR aims to resolve this by adding functionality to import the local cluster as described above.

The behaviour during upgrade will be dealt with in another ticket.

List all the issues related to this PR

  • New Feature
  • Enhancement
  • Bug fix
  • Tests
  • Documentation
  • CI/CD

What environments does this code impact?

  • Automation (CI, tools, etc)
  • Cloud
  • Operator Managed Deployments
  • None

How was this code tested?

  • assisted-test-infra environment
  • dev-scripts environment
  • Reviewer's test appreciated
  • Waiting for CI to do a full test run
  • Manual (Elaborate on how it was tested)
  • No tests needed

Checklist

  • Title and description added to both, commit and PR.
  • Relevant issues have been associated (see CONTRIBUTING guide)
  • This change does not require a documentation update (docstring, docs, README, etc)
  • Does this change include unit-tests (note that code changes require unit-tests)

Reviewers Checklist

  • Are the title and description (in both PR and commit) meaningful and clear?
  • Is there a bug required (and linked) for this change?
  • Should this PR be backported?

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 5, 2023
@openshift-ci
Copy link

openshift-ci bot commented Sep 5, 2023

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

@openshift-ci openshift-ci bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Sep 5, 2023
@paul-maidment paul-maidment force-pushed the MGMT-15704 branch 7 times, most recently from 1060b2c to f01d801 Compare September 5, 2023 09:43
@paul-maidment paul-maidment marked this pull request as ready for review September 5, 2023 09:49
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 5, 2023
@filanov
Copy link
Contributor

filanov commented Sep 5, 2023

Using ZTP in the commit message is incorrect, here you are referring to kube-api or the operator, have nothing to do with ZTP

@filanov
Copy link
Contributor

filanov commented Sep 5, 2023

/assign @nmagnezi

@codecov
Copy link

codecov bot commented Sep 5, 2023

Codecov Report

Merging #5459 (eeca32d) into master (52448cd) will decrease coverage by 0.06%.
Report is 4 commits behind head on master.
The diff coverage is 63.72%.

❗ Current head eeca32d differs from pull request most recent head c2aabc3. Consider uploading reports for the commit c2aabc3 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5459      +/-   ##
==========================================
- Coverage   67.74%   67.68%   -0.06%     
==========================================
  Files         229      232       +3     
  Lines       33571    33968     +397     
==========================================
+ Hits        22741    22992     +251     
- Misses       8790     8929     +139     
- Partials     2040     2047       +7     
Files Changed Coverage Δ
...oller/controllers/clusterdeployments_controller.go 71.23% <ø> (ø)
...alclusterimport/local_cluster_import_operations.go 0.00% <0.00%> (ø)
...terimport/local_cluster_import_operations_mocks.go 76.10% <76.10%> (ø)
pkg/localclusterimport/import_local_cluster.go 90.27% <90.27%> (ø)

... and 1 file with indirect coverage changes

Copy link
Contributor

@filanov filanov left a comment

Choose a reason for hiding this comment

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

Please add in the commit message why did you had to add permissions to specific resources

General comment about if else
usually it's cleaner to handle the error first, then you will not need the else in most cases

cmd/main.go Outdated Show resolved Hide resolved
pkg/localclusterimport/import_local_cluster.go Outdated Show resolved Hide resolved
pkg/localclusterimport/import_local_cluster.go Outdated Show resolved Hide resolved
pkg/localclusterimport/import_local_cluster.go Outdated Show resolved Hide resolved
pkg/localclusterimport/import_local_cluster.go Outdated Show resolved Hide resolved
pkg/localclusterimport/import_local_cluster.go Outdated Show resolved Hide resolved
pkg/localclusterimport/import_local_cluster.go Outdated Show resolved Hide resolved
@paul-maidment paul-maidment force-pushed the MGMT-15704 branch 4 times, most recently from 3d6c930 to 85f69f1 Compare September 5, 2023 12:27
cmd/main.go Outdated Show resolved Hide resolved
cmd/main.go Show resolved Hide resolved
pkg/localclusterimport/import_local_cluster.go Outdated Show resolved Hide resolved
return false, err
}
if agentClusterInstall != nil {
i.log.Infof("hubClusterDay2Importer: Found AgentClusterInstall for hub cluster, assuming that hub has been correctly registered for ZTP day 2 operations: %s", agentClusterInstall.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any checks we can do here to ensure that cluster is actually healthy?
Also, why is ZTP mentioned here?

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 that this is possible at this stage.

The one thing we do perform is a check of the cluster-version history, which will show up as completed if the last update was applied.

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 not sure which tests can be done in this case, domain resolution and valid kubeconfig, but if you are taking them from the cluster and even if they are invalid, what can be done?

pkg/localclusterimport/import_local_cluster.go Outdated Show resolved Hide resolved
pkg/localclusterimport/import_local_cluster.go Outdated Show resolved Hide resolved
pkg/localclusterimport/import_local_cluster.go Outdated Show resolved Hide resolved
return true, nil
}

func (i *LocalClusterImport) ImportLocalCluster() error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Few things about this function:

  1. It does to many things, which should be split to sub functions for both readability and tests.
  2. It can potentially fail in too many places (which is related to the first point, in part). I also think that for many things here it is worth to use multiErr to aggregate a much of the problems and reflect them to the user as early as possible.

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: Done
2: Done

@paul-maidment paul-maidment force-pushed the MGMT-15704 branch 3 times, most recently from 8d0af57 to eeca32d Compare September 5, 2023 21:19
@paul-maidment paul-maidment force-pushed the MGMT-15704 branch 8 times, most recently from 9a2f924 to 23bc5d3 Compare September 6, 2023 07:56
@paul-maidment
Copy link
Contributor Author

Using ZTP in the commit message is incorrect, here you are referring to kube-api or the operator, have nothing to do with ZTP

Fixed now

Using ZTP in the commit message is incorrect, here you are referring to kube-api or the operator, have nothing to do with ZTP

Fixed

cmd/main.go Outdated
@@ -205,6 +208,23 @@ func maxDuration(dur time.Duration, durations ...time.Duration) time.Duration {
return ret
}

func importLocalCluster(ctrlMgr manager.Manager, log *logrus.Logger) {
if !Options.EnableLocalClusterImport {
log.Debug("EnableLocalClusterImport disabled in options, skipping...")
Copy link
Contributor

Choose a reason for hiding this comment

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

can be info, it's not something periodic

cmd/main.go Outdated
@@ -162,6 +163,8 @@ var Options struct {
AllowConvergedFlow bool `envconfig:"ALLOW_CONVERGED_FLOW" default:"true"`
PreprovisioningImageControllerConfig controllers.PreprovisioningImageControllerConfig
BMACConfig controllers.BMACConfig
EnableLocalClusterImport bool `envconfig:"ENABLE_LOCAL_CLUSTER_IMPORT" default:"true"`
LocalClusterImportNamespace string `envconfig:"LOCAL_CLUSTER_IMPORT_NAMESPACE" defualt:"local-cluster"`
Copy link
Contributor

Choose a reason for hiding this comment

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

please make sure with ACM/MCE that they are not using the same namespace

}

func (o *LocalClusterImportOperations) CreateClusterImageSet(clusterImageSet *hivev1.ClusterImageSet) (*hivev1.ClusterImageSet, error) {
err := o.cachedApiClient.Create(o.context, clusterImageSet)
Copy link
Contributor

Choose a reason for hiding this comment

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

what will happen is it's already exists?
same question to all the resources.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would fail to write the cluster image set and the old one would remain in place.
Not sure what the best thing to do is, on one hand, we could delete anything we find when performing this write, but seems to me that this would not be the smart choice until we have looked into the impact of the update ticket.

Copy link
Contributor

Choose a reason for hiding this comment

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

until we handle upgrade it should be good enough


func (i *LocalClusterImport) ImportLocalCluster() error {

shouldImportLocalCluster, err := i.shouldImportLocalCluster()
Copy link
Contributor

Choose a reason for hiding this comment

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

As we talked, this function can be removed and you will try to create all the objects and if they are already exist you will ignore them, using k8serrors.IsAlreadyExists(err) to check the error

@paul-maidment paul-maidment force-pushed the MGMT-15704 branch 4 times, most recently from 9210a94 to 7d5ff3d Compare September 6, 2023 12:43
}
// Fetch the recently stored AgentClusterInstall so that we can obtain the UID
aci, err := i.clusterImportOperations.GetAgentClusterInstall(i.localClusterNamespace, i.localClusterNamespace+"-cluster-install")
if err != nil && !k8serrors.IsAlreadyExists(err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

get cannot return already exist

agentClusterInstall.Namespace = i.localClusterNamespace
agentClusterInstall.Name = i.localClusterNamespace + "-cluster-install"
err := i.clusterImportOperations.CreateAgentClusterInstall(agentClusterInstall)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

it can return already exist

}

err = i.createNamespace(i.localClusterNamespace)
if err != nil && !k8serrors.IsAlreadyExists(err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

minor comment - you already handling already exist error inside createNamespace

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 actually changed this, I need to be able to mock this so I moved the handling of this stuff into import_local_cluster


if kubeConfigSecret != nil {
err = i.createAdminKubeConfig(kubeConfigSecret)
if err != nil && !k8serrors.IsAlreadyExists(err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

minor comment - you already handling already exist error inside createAdminKubeConfig

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 actually changed this, I need to be able to mock this so I moved the handling of this stuff into import_local_cluster

…ster.

When using assisted-service in KubeAPI mode, we want to import the local cluster automatically, allowing it to be managed in a similar fashion to the spoke cluster.

The intent is to allow the user to perform day2 operations on the local cluster, to allow the addition of workers and so on.

Presently this is only possible via manual efforts and is not very customer friendly.

This PR aims to resolve this by adding functionality to import the local cluster as described above.
@paul-maidment
Copy link
Contributor Author

/retest

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 6, 2023
@openshift-ci
Copy link

openshift-ci bot commented Sep 6, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: filanov, paul-maidment

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:
  • OWNERS [filanov,paul-maidment]

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

@openshift-ci
Copy link

openshift-ci bot commented Sep 6, 2023

@paul-maidment: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@openshift-merge-robot openshift-merge-robot merged commit 05bc6d8 into openshift:master Sep 6, 2023
16 checks passed
@paul-maidment
Copy link
Contributor Author

/cherry-pick release-ocm-2.8

@openshift-cherrypick-robot

@paul-maidment: #5459 failed to apply on top of branch "release-ocm-2.8":

Applying: MGMT-15704: Assisted service should create Day2 import CR for hub cluster.
Using index info to reconstruct a base tree...
M	cmd/main.go
M	deploy/olm-catalog/manifests/assisted-service-operator.clusterserviceversion.yaml
M	go.mod
M	internal/controller/controllers/clusterdeployments_controller.go
Falling back to patching base and 3-way merge...
Auto-merging internal/controller/controllers/clusterdeployments_controller.go
Auto-merging go.mod
CONFLICT (content): Merge conflict in go.mod
Auto-merging deploy/olm-catalog/manifests/assisted-service-operator.clusterserviceversion.yaml
Auto-merging cmd/main.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 MGMT-15704: Assisted service should create Day2 import CR for hub cluster.
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

In response to this:

/cherry-pick release-ocm-2.8

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

danielerez pushed a commit to danielerez/assisted-service that referenced this pull request Oct 15, 2023
…ster. (openshift#5459)

When using assisted-service in KubeAPI mode, we want to import the local cluster automatically, allowing it to be managed in a similar fashion to the spoke cluster.

The intent is to allow the user to perform day2 operations on the local cluster, to allow the addition of workers and so on.

Presently this is only possible via manual efforts and is not very customer friendly.

This PR aims to resolve this by adding functionality to import the local cluster as described above.
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. lgtm 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

5 participants