Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

support non-kcp environment #8

Merged
merged 1 commit into from
Jul 8, 2022
Merged

support non-kcp environment #8

merged 1 commit into from
Jul 8, 2022

Conversation

MatousJobanek
Copy link
Contributor

This improves the code to support also non-kcp environment.

it depends on:

the changes introduced in this PR:

  • adds a new overlay called default-crd that includes the CRDs into the manifests to be deployed
  • adds new makefile target deploy-crd to deploy that default-crd overlay
  • adds ClusterRole(Binding) granting permissions to get/list APIExport and its content
  • adds kubebuilder markers to get necessary permissions for namespaces, secrets, and configmaps
  • modifies the ConfigMapReconciler so it doesn't list all configmaps if it runs in a normal cluster
  • modifies the main.go so it:
    • checks if the apis.kcp.dev group is present - if not, then it creates the manager using standard cache & client
    • takes the APIExport from a flag --api-export-name
    • if APIExport name is not set, then it lists all APIExports and takes the one that is found
    • fixes leader election so it uses the original RestConfig (not the one of the VirtualWorkspace)

fixes: kcp-dev/apimachinery#32

Copy link
Member

@ncdc ncdc left a comment

Choose a reason for hiding this comment

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

Please also see #10

return ctrl.Result{}, fmt.Errorf("there should be listed only one configmap with the given name '%s' for the given namespace '%s' when the clusterName is not available", cm.Name, cm.Namespace)
}
found = true
log.Info("Found in listed configmaps", "namespace", cm.Namespace, "name", cm.Name)
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 move this back out (just inside the else block) and change it back to the List: got... log message. There can be multiple configmaps in a cluster across all namespaces, and this is supposed to show all of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but imagine what it looks like when it's "connected" to a normal OpenShift cluster - there are approx. 550 ConfigMaps in the cluster and all of them are printed every time when the leader election updates its own configmap. This makes the whole log unreadable.
That's why I change it so it prints the count of all CMs found either in the cluster or in the workspace, plus:

  • when it's running against kcp cluster (clusterName is set) then it shows all of them (as you requested)
  • when it's running against a normal cluster, then it only finds the right ConfigMap which triggered the reconcile, and prints only that one

go.mod Outdated
@@ -77,6 +77,7 @@ require (
)

replace (
github.com/kcp-dev/apimachinery => github.com/MatousJobanek/apimachinery v0.0.0-20220615142058-8ebeb03b4114
Copy link
Member

Choose a reason for hiding this comment

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

Undo 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I added it because it depends on the changes in my fork - so in case someone would want to try/test it. My plan was to remove it before merging the PR ;-)
removed in b3b512e

main.go Outdated

setupLog.Info("Using virtual workspace URL", "url", cfg.Host)

mgr, err = kcp.NewClusterAwareManager(cfg, ctrl.Options{
Copy link
Member

Choose a reason for hiding this comment

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

Pull ctrl.Options out to a variable so it's not duplicated?

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 made that change, but somehow forgot to push it 🤦‍♂️
changed in a93e0ba

main.go Outdated
@@ -175,3 +212,27 @@ func restConfigForAPIExport(ctx context.Context, cfg *rest.Config, apiExportName

return cfg, nil
}

func apisKcpGroupPresent(restConfig *rest.Config) bool {
Copy link
Member

Choose a reason for hiding this comment

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

(no action required) I'd probably call this kcpAPIsGroupPresent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed 77c8d19

@MatousJobanek
Copy link
Contributor Author

Thanks a lot for your review @ncdc
I've either addressed or answered all your comments

@MatousJobanek
Copy link
Contributor Author

Updated the github.com/kcp-dev/apimachinery dependency in faa7b15 to use the merged latest changes

@MatousJobanek
Copy link
Contributor Author

Is there anything else needed for this PR? @ncdc @fabianvf

Copy link
Collaborator

@fabianvf fabianvf left a comment

Choose a reason for hiding this comment

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

/lgtm

@ncdc ncdc merged commit 8a06878 into kcp-dev:main Jul 8, 2022
@ncdc ncdc mentioned this pull request Jul 8, 2022
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.

RoundTripper should support normal OpenShift cluster
3 participants