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

Creation of CompassManagerMapping CRD after successfull registration Runtime in Compass #27

Merged
merged 23 commits into from
Oct 4, 2023

Conversation

mvshao
Copy link
Contributor

@mvshao mvshao commented Sep 19, 2023

Description

Changes proposed in this pull request:

  • reconcile triggers only while the Application Connector module is present in Kyma CR
  • changed the way of marking Runtime as connected to Compass from labeling Kyma CR to creating Compass Manager Mapping CRD with all the data needed
  • added WhiteSource and Protecode scans for module
  • Compass Manager is capable of refreshing Compass one-time token commented -> moved to different PR

Related issue(s)

@mvshao mvshao added the area/application-connector Issues or PRs related to application connectivity label Sep 19, 2023
@mvshao mvshao requested a review from a team as a code owner September 19, 2023 12:53
@kyma-bot kyma-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Sep 19, 2023
@mvshao mvshao changed the title Creation of CompassManagerMapping CRD after succesfull registration Runetime in Compass Creation of CompassManagerMapping CRD after successfull registration Runtime in Compass Sep 19, 2023
@kyma-bot kyma-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 21, 2023
Copy link
Contributor

@akgalwas akgalwas 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 the PR is ok, we are close to finalise it.

func (cm *CompassManagerReconciler) createCompassMappingResource(compassRuntimeID string, kymaLabels map[string]string) error {
compassMapping := &v1beta1.CompassManagerMapping{}
compassMapping.Name = kymaLabels[KymaNameLabel]
compassMapping.Namespace = DefaultResourceNamespace
Copy link
Contributor

Choose a reason for hiding this comment

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

Namespace name for the Compass Manager Mapping is hardcoded. Please consider using namespace name from Kyma CR.

func (cm *CompassManagerReconciler) markRuntimeRegistered(objKey types.NamespacedName, compassID string) error {
instance := &kyma.Kyma{}
func (cm *CompassManagerReconciler) createCompassMappingResource(compassRuntimeID string, kymaLabels map[string]string) error {
compassMapping := &v1beta1.CompassManagerMapping{}
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 wondering whether we should add operator.kyma-project.io/managed-by label with Compass Manager value to determine that Compass Manager controls the CRs lifecycle.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, I will add this

BrokerInstanceIDLabel = "kyma-project.io/instance-id"
ShootNameLabel = "kyma-project.io/shoot-name"
SubaccountIDLabel = "kyma-project.io/subaccount-id"
KymaIDLabel = "kyma-project.io/kyma-id"
Copy link
Contributor

Choose a reason for hiding this comment

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

In the original version of the specification we use kyma-id. This was my mistake, let's consistently use operator.kyma-project.io/kyma-name. Its better to have the same label on Kyma, and Compass Manager to avoid confusion.

}
}

// If kcp-system Namespace contains Compass Manager CR with compass-id and runtime-id correlated with given in Kyma CR, skip reconciliation. Cluster is already connected
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this comment is outdated.

// KubeconfigKey is the name of the key in the secret storing cluster credentials.
// The secret is created by KEB: https://github.com/kyma-project/control-plane/blob/main/components/kyma-environment-broker/internal/process/steps/lifecycle_manager_kubeconfig.go
KubeconfigKey = "config"
)

//+kubebuilder:rbac:groups=apiextensions.k8s.io,resources=customresourcedefinitions,verbs=get;list;watch
//+kubebuilder:rbac:groups=operator.kyma-project.io,resources=kymas,verbs=get;list;watch;update
//+kubebuilder:rbac:groups=operator.kyma-project.io,resources=kymas,verbs=get;list;watch
//+kubebuilder:rbac:groups=operator.kyma-project.io,resources=compassmanagermappings,verbs=create;get;list;watch;update;delete
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably we could limit privileges for Compass Manager Mappings to the following: create;get;list;delete

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The watch privilege is required. Because the controller returns an error

[reflector.go:148] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:231: Failed to watch *v1beta1.CompassManagerMapping: unknown (get compassmanagermappings.operator.kyma-project.io)

@@ -94,7 +105,7 @@ func (cm *CompassManagerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
return ctrl.Result{RequeueAfter: requeueTime}, err
}

compassRuntimeID, err := cm.Configurator.RegisterInCompass(createCompassRuntimeLabels(kymaLabels))
compassRuntimeID, err := cm.Registrator.RegisterInCompass(createCompassRuntimeLabels(kymaLabels))
Copy link
Contributor

Choose a reason for hiding this comment

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

Before registration is done, we should check if the Compass Manager Mapping already exists.

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 have this feature uncommited, but implemetned.

app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/created-by: compass-manager
name: compassmanagermapping-sample
spec:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could have missed one thing here. As noted in the issue concerning resource watching we should consider setting statuses for operations. As we can't set status on the Kyma resource, CompassManagerMapping seems to be the right place.

Why this is needed?

Let's imagine situation when we have Compass outage. It will we surely visible in the logs, as Compass Manager will constantly retry requests. If we had proper alerting/monitoring we could also be notified that some problem occurred.
I see the following benefits of adding the status property:

  • We would get additional insight into the system:
    • We could see how many runtimes that have module enabled cannot be registered due to Compass failures.
    • We could see when Compass Manager noticed module is enabled, and when runtime was registered, and secret with configuration created
  • We could add some dashboards

You can see the example of status structures here.

I think this needs some discussions before we decide to implement it. If we decide to go with statuses let's do that in the separate PR.

@@ -108,7 +119,7 @@ func (cm *CompassManagerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
}
cm.Log.Infof("Compass Runtime Agent for Runtime %s configured.", compassRuntimeID)

return ctrl.Result{}, cm.markRuntimeRegistered(req.NamespacedName, compassRuntimeID)
return ctrl.Result{}, cm.createCompassMappingResource(compassRuntimeID, kymaLabels)
Copy link
Contributor

Choose a reason for hiding this comment

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

One note: if we decide to provide statuses on the CR we should create it even in case the Compass registration failed. This is just a reminder, I think we should discuss if we go with the status field, and then create a new PR.

@@ -88,13 +101,25 @@ func (cm *CompassManagerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
return ctrl.Result{RequeueAfter: requeueTime}, nil
}

compassMappingLabels, err := cm.getCompassMappingLabels(req.Name)
Copy link
Contributor

@akgalwas akgalwas Sep 28, 2023

Choose a reason for hiding this comment

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

I'm confused a bit. I though we will implement obtaining token in other PR.

return err
}

func (cm *CompassManagerReconciler) getCompassMappingLabels(mappingName string) (map[string]string, 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 would rename mappingName to kymaName to avoid confusion.

@kyma-bot kyma-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 28, 2023
@CLAassistant
Copy link

CLAassistant commented Sep 29, 2023

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ mvshao
❌ akgalwas
You have signed the CLA already but the status is still pending? Let us recheck it.

@mvshao
Copy link
Contributor Author

mvshao commented Oct 2, 2023

/test pre-compass-manager-presubmit-scanner

@kyma-bot kyma-bot added the lgtm Looks good to me! label Oct 4, 2023
@kyma-bot kyma-bot merged commit f50ad5a into kyma-project:main Oct 4, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/application-connector Issues or PRs related to application connectivity lgtm Looks good to me! 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.

4 participants