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-16144: Operator - Add extension support #65

Merged
merged 1 commit into from
Feb 22, 2024

Conversation

irinamihai
Copy link
Collaborator

@irinamihai irinamihai commented Feb 20, 2024

Description:

  • Add a new array type Spec field called Extensions
  • As per O-RAN.WG6.O2IMS-INTERFACE-R003-v04.00, this new field is of key:value format and it has been implemented as an array of strings
  • In the ORANO2IMS CR definition, the Extensions can be declared as follows:
  spec:
    extensions:
    - "{\"country\": .metadata.labels[\"country\"]}"
    - "{\"my\": {memory: .status.capacity.memory, k8s_version: .status.version.kubernetes}}"
    - |
         .metadata.labels["name"] as $name |
         {
           name: $name,
          alias: $name
         }
  • Each element of Spec.Extensions will be translated in an --extensions argument for the deployment manager server:
"--extensions={\"country\": .metadata.labels[\"country\"]}","--extensions={\"my\": {memory: .status.capacity.memory, k8s_version: .status.version.kubernetes}}","--extensions=.metadata.labels[\"name\"] as $name |\n{\n  name: $name,\n  alias: $name\n}\n"]
  • a request for extensions to the deployment manager server done in a regular hub environment with one managed cluster would return as follows:
# ./get_oran '/o2ims-infrastructureInventory/v1/deploymentManagers?fields=extensions'

[
  {
    "extensions": {
      "country": "Canada",
      "my": {
        "k8s_version": "v1.27.8+4fab27b",
        "memory": "32856932Ki"
      },
      "alias": "spoke-hub-spoke-1",
      "name": "spoke-hub-spoke-1"
    }
  }
]

@openshift-ci-robot
Copy link
Collaborator

openshift-ci-robot commented Feb 20, 2024

@irinamihai: This pull request references MGMT-16144 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.16.0" version, but no target version was set.

In response to this:

Description:

  • Add a new array type Spec field called Extensions
  • As per O-RAN.WG6.O2IMS-INTERFACE-R003-v04.00, this new field is of key:value format and it has been implemented as a structure:
type Extension struct {
  Key   string `json:"key,omitempty"`
  Value string `json:"value,omitempty"`
}
  • In the ORANO2IMS CR definition, the Extensions can be declared as follows:
 spec:
   extensions:
   - key: country
     value: ".metadata.labels[\"country\"]"
   - key: my
     value: "{memory: .status.capacity.memory, k8s_version: .status.version.kubernetes}"

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 openshift-eng/jira-lifecycle-plugin repository.

Copy link

openshift-ci bot commented Feb 20, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from irinamihai. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

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

items:
description: 'EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
NOTE: json tags are required. Any new fields you add must have
json tags for the fields to be serialized.'
Copy link
Collaborator

Choose a reason for hiding this comment

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

You may want to chang or remove this ^ description before merging.

"\"version\": .metadata.labels[\"openshiftVersion\"],\n",
"\"hub\": .metadata.annotations[\"global-hub.open-cluster-management.io/managed-by\"],",
"}"),
fmt.Sprintf("--extensions={%s}", extensions),
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we do this we are forcing the user to put each extension within a dictionary. That limits somehow the flexibility, as there are some jq constructs that don't start with a curly bracket. For example, you can set variables and use them later:

.metadata.labels["name"] as $name |
{
  name: $name,
  alias: $name
}

If we put that between curly brackets it will result in a syntax error.

I think it is better to make the extensions field an array of strings, and translate it into multiple --extensions flag. So the CR could look like this:

extensions:
- |
    .metadata.labels["name"] as $name |
    {
      name: $name,
      alias: $name
    }
- |
    { foo: "bar" }
- ...

That way we can tell users that the syntax of the value of the extensions field is just that of jq, without additional restrictions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, that makes sense. I interpreted the O-RAN standard that is describing the extensions as key:value pair.
Thank you for the clarification, @jhernand.
Kindly take another look when you get the time and please let me know if this approach better suits the extension scenarios.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Your interpretation of the specification is correct, but this is about how we are implementing the addition of configurable extensions with jq. It looks good to me now. Thanks @irinamihai!

})

var _ = Describe("DoesK8SResourceExist", func() {

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do these tests belong here? The aren't related to extensions. May this be a copy & paste error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I included some extra testcases in this PR. I can add them separately in another PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That is fine, keep them.

@openshift-ci-robot
Copy link
Collaborator

openshift-ci-robot commented Feb 21, 2024

@irinamihai: This pull request references MGMT-16144 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.16.0" version, but no target version was set.

In response to this:

Description:

  • Add a new array type Spec field called Extensions
  • As per O-RAN.WG6.O2IMS-INTERFACE-R003-v04.00, this new field is of key:value format and it has been implemented as an array of strings
  • In the ORANO2IMS CR definition, the Extensions can be declared as follows:
 spec:
   extensions:
   - "{\"country\": .metadata.labels[\"country\"]}"
   - "{\"my\": {memory: .status.capacity.memory, k8s_version: .status.version.kubernetes}}"
   - |
        .metadata.labels["name"] as $name |
        {
          name: $name,
         alias: $name
        }
  • Each element of Spec.Extensions will be translated in an --extensions argument for the deployment manager server:
"--extensions={\"country\": .metadata.labels[\"country\"]}","--extensions={\"my\": {memory: .status.capacity.memory, k8s_version: .status.version.kubernetes}}","--extensions=.metadata.labels[\"name\"] as $name |\n{\n  name: $name,\n  alias: $name\n}\n"]
  • a request for extensions to the deployment manager server done in a regular hub environment with one managed cluster would return as follows:
# ./get_oran '/o2ims-infrastructureInventory/v1/deploymentManagers?fields=extensions'

[
 {
   "extensions": {
     "country": "Canada",
     "my": {
       "k8s_version": "v1.27.8+4fab27b",
       "memory": "32856932Ki"
     },
     "alias": "spoke-hub-spoke-1",
     "name": "spoke-hub-spoke-1"
   }
 }
]

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 openshift-eng/jira-lifecycle-plugin repository.

Description:
- Add a new array type Spec field called Extensions
- As per O-RAN.WG6.O2IMS-INTERFACE-R003-v04.00, this new field is of
  key:value format and it has been implemented as an array of strings
- in the ORANO2IMS CR definition, the Extensions can be declared as
  follows:
  spec:
    extensions:
    - "{\"country\": .metadata.labels[\"country\"]}"
    - "{\"aaaa\": {memory: .status.capacity.memory, k8s_version: .status.version.kubernetes}}"
    - |
        .metadata.labels["name"] as $name |
        {
          name: $name,
          alias: $name
        }
@jhernand
Copy link
Collaborator

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Feb 22, 2024
@irinamihai irinamihai merged commit 7bfdd9f into openshift-kni:main Feb 22, 2024
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants