Skip to content

Commit

Permalink
MGMT-16144: Operator - Add extension support
Browse files Browse the repository at this point in the history
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
        }
  • Loading branch information
irinamihai committed Feb 21, 2024
1 parent 702c678 commit 538c341
Show file tree
Hide file tree
Showing 7 changed files with 326 additions and 25 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha1/orano2ims_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ type ORANO2IMSSpec struct {
//+kubebuilder:default=regular-hub
//+kubebuilder:validation:Enum=regular-hub;global-hub
BackendType string `json:"backendType,omitempty"`
// This field allows the addition of extra O-Cloud information
//+optional
Extensions []string `json:"extensions,omitempty"`
}

type DeploymentsStatus struct {
Expand Down
7 changes: 6 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions config/crd/bases/oran.openshift.io_orano2imses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ spec:
deploymentManagerServer:
default: false
type: boolean
extensions:
description: This field allows the addition of extra O-Cloud information
items:
type: string
type: array
ingressHost:
type: string
metadataServer:
Expand Down
27 changes: 3 additions & 24 deletions internal/controllers/orano2ims_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ func (r *ORANO2IMSReconciler) deployManagerServer(ctx context.Context, orano2ims
},
}

deploymentManagerServerContainerArgs := utils.BuildDeploymentManagerServerContainerArgs(orano2ims)

// Build the deployment's spec.
deploymentSpec := appsv1.DeploymentSpec{
Replicas: k8sptr.To(int32(1)),
Expand Down Expand Up @@ -312,30 +314,7 @@ func (r *ORANO2IMSReconciler) deployManagerServer(ctx context.Context, orano2ims
},
},
Command: []string{"/usr/bin/oran-o2ims"},
Args: []string{
"start",
"deployment-manager-server",
"--log-level=debug",
"--log-file=stdout",
"--api-listener-address=0.0.0.0:8000",
"--api-listener-tls-crt=/secrets/tls/tls.crt",
"--api-listener-tls-key=/secrets/tls/tls.key",
"--authn-jwks-url=https://kubernetes.default.svc/openid/v1/jwks",
"--authn-jwks-token-file=/run/secrets/kubernetes.io/serviceaccount/token",
"--authn-jwks-ca-file=/run/secrets/kubernetes.io/serviceaccount/ca.crt",
"--authz-acl-file=/configmaps/authz/acl.yaml",
fmt.Sprintf("--cloud-id=%s", orano2ims.Spec.CloudId),
fmt.Sprintf("--backend-url=%s", orano2ims.Spec.BackendURL),
fmt.Sprintf("--backend-token=%s", orano2ims.Spec.BackendToken),
fmt.Sprintf("--backend-type=%s", orano2ims.Spec.BackendType),
fmt.Sprintln(
// TODO: properly hold the extensions instead of hardcoding them.
"--extensions={\n",
"\"country\": .metadata.labels[\"country\"],\n",
"\"version\": .metadata.labels[\"openshiftVersion\"],\n",
"\"hub\": .metadata.annotations[\"global-hub.open-cluster-management.io/managed-by\"],",
"}"),
},
Args: deploymentManagerServerContainerArgs,
Ports: []corev1.ContainerPort{
{
Name: "api",
Expand Down
17 changes: 17 additions & 0 deletions internal/controllers/utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,20 @@ const (
UPDATE = "Update"
PATCH = "Patch"
)

// Container arguments
var (
DeploymentManagerServerArgs = []string{
"start",
"deployment-manager-server",
"--log-level=debug",
"--log-file=stdout",
"--api-listener-address=0.0.0.0:8000",
"--api-listener-tls-crt=/secrets/tls/tls.crt",
"--api-listener-tls-key=/secrets/tls/tls.key",
"--authn-jwks-url=https://kubernetes.default.svc/openid/v1/jwks",
"--authn-jwks-token-file=/run/secrets/kubernetes.io/serviceaccount/token",
"--authn-jwks-ca-file=/run/secrets/kubernetes.io/serviceaccount/ca.crt",
"--authz-acl-file=/configmaps/authz/acl.yaml",
}
)
28 changes: 28 additions & 0 deletions internal/controllers/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package utils

import (
"context"
"fmt"
"reflect"

ctrl "sigs.k8s.io/controller-runtime"

oranv1alpha1 "github.com/openshift-kni/oran-o2ims/api/v1alpha1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -73,3 +75,29 @@ func DoesK8SResourceExist(ctx context.Context, c client.Client, Name string, Nam
return true, nil
}
}

func extensionsToExtensionArgs(extensions []string) []string {
var extensionsArgsArray []string
for _, crtExt := range extensions {
newExtensionFlag := "--extensions=" + crtExt
extensionsArgsArray = append(extensionsArgsArray, newExtensionFlag)
}

return extensionsArgsArray
}

func BuildDeploymentManagerServerContainerArgs(orano2ims *oranv1alpha1.ORANO2IMS) []string {
containerArgs := DeploymentManagerServerArgs

containerArgs = append(containerArgs,
fmt.Sprintf("--cloud-id=%s", orano2ims.Spec.CloudId),
fmt.Sprintf("--backend-url=%s", orano2ims.Spec.BackendURL),
fmt.Sprintf("--backend-token=%s", orano2ims.Spec.BackendToken),
fmt.Sprintf("--backend-type=%s", orano2ims.Spec.BackendType),
)

extensionsArgsArray := extensionsToExtensionArgs(orano2ims.Spec.Extensions)
containerArgs = append(containerArgs, extensionsArgsArray...)

return containerArgs
}
Loading

0 comments on commit 538c341

Please sign in to comment.