Skip to content

Introduce explicit Kyma ID type #2939

@c-pius

Description

@c-pius

Description

Kyma CRs are named according to their runtimeId. In many places in our code, we use the Kyma name and therefore runtimeId as identifier. Currently, almost anything in KLM depends somehow on the Kyma name:

  • Kyma CRs (obviously)
  • SKR clients (getting the right one)
  • Manifests belonging to that Kyma
  • Certificate + Secret belonging to that Kyma
  • kube access secret belongig to that Kyma
  • ...

We also often use the Kyma name slightly different, e.g.:

  • ClientCache uses client.ObjectKey:
    func (c *ClientCache) Get(key client.ObjectKey) client.Client {
    cachedClient := c.internal.Get(key)
    if cachedClient != nil {
    return cachedClient.Value()
    }
    return nil
    }
    • we pass the kyma.NamespacedName
  • KCP Kyma Repo uses distinct name and namespace strings:
    func (r *Repository) Get(ctx context.Context, kymaName string, kymaNamespace string) (*v1beta2.Kyma, error) {
    kyma := &v1beta2.Kyma{}
    err := r.client.Get(ctx, client.ObjectKey{Name: kymaName, Namespace: kymaNamespace}, kyma)
    if err != nil {
    return nil, fmt.Errorf("failed to get Kyma %s in namespace %s: %w", kymaName, kymaNamespace, err)
    }
    return kyma, nil
    }
  • SKR Repos (new) use types.NamespacedName:
    func (r *Repository) Exists(ctx context.Context, kymaName types.NamespacedName) (bool, error) {
    skrClient, err := r.getSkrClient(kymaName)
    if err != nil {
    return false, err
    }
    • (only needed to get the required SKR client from the cache)
  • CertificateService uses it to determine how the related certs and secrets are called:
    func (c *Service) DeleteSkrCertificate(ctx context.Context, kymaName string) error {
    err := c.certRepo.Delete(ctx, name.SkrCertificate(kymaName))
    if err != nil {
    return fmt.Errorf("failed to delete SKR certificate: %w", err)
    }
    err = c.secretRepo.Delete(ctx, name.SkrCertificate(kymaName))
    if err != nil {
    return fmt.Errorf("failed to delete SKR certificate secret: %w", err)
    }
    return nil
    }

We should consider to introduce an explicit type for and pass it uniformly to all functionality that somehow depends on this id.

Reasons

This will make it easier for us (and newcomers) to understand what our key identifier is and how we use it.

Acceptance Criteria

  • type KymaId defined (or we explicitily use a RuntimeId type?)
  • Kyma type provides a method Id() KymaId
  • KymaId uniformly passed to all funcs depending on it

Feature Testing

No response

Testing approach

No response

Attachments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions