-
Notifications
You must be signed in to change notification settings - Fork 8
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
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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{} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
|
9ac2f9d
to
6899845
Compare
/test pre-compass-manager-presubmit-scanner |
Description
Changes proposed in this pull request:
Compass Manager is capable of refreshing Compass one-time tokencommented -> moved to different PRRelated issue(s)