Commit f0a20b9d authored by Waleed Akbar's avatar Waleed Akbar
Browse files

cleanup for merge

parent f0c99c8d
Loading
Loading
Loading
Loading
+99 −0
Original line number Diff line number Diff line
# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: kpi-value-apiservice
spec:
  selector:
    matchLabels:
      app: kpi-value-apiservice
  #replicas: 1
  template:
    metadata:
      annotations:
        config.linkerd.io/skip-outbound-ports: "4222"
      labels:
        app: kpi-value-apiservice
    spec:
      terminationGracePeriodSeconds: 5
      containers:
        - name: server
          image: labs.etsi.org:5050/tfs/controller/kpi_manager:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 30020
            - containerPort: 9192
          env:
            - name: LOG_LEVEL
              value: "INFO"
          # envFrom:
          #   - secretRef:
          #       name: crdb-data
          readinessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:30020"]
          livenessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:30020"]
          resources:
            requests:
              cpu: 250m
              memory: 128Mi
            limits:
              cpu: 1000m
              memory: 1024Mi
---
apiVersion: v1
kind: Service
metadata:
  name: kpi-value-apiservice
  labels:
    app: kpi-value-apiservice
spec:
  type: ClusterIP
  selector:
    app: kpi-value-apiservice
  ports:
    - name: grpc
      protocol: TCP
      port: 30020
      targetPort: 30020
    - name: metrics
      protocol: TCP
      port: 9192
      targetPort: 9192
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: kpi-value-apiservice-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: kpi-value-apiservice
  minReplicas: 1
  maxReplicas: 20
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 80
  #behavior:
  #  scaleDown:
  #    stabilizationWindowSeconds: 30
+99 −0
Original line number Diff line number Diff line
# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: kpi-value-writerservice
spec:
  selector:
    matchLabels:
      app: kpi-value-writerservice
  #replicas: 1
  template:
    metadata:
      annotations:
        config.linkerd.io/skip-outbound-ports: "4222"
      labels:
        app: kpi-value-writerservice
    spec:
      terminationGracePeriodSeconds: 5
      containers:
        - name: server
          image: labs.etsi.org:5050/tfs/controller/kpi_manager:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 30030
            - containerPort: 9192
          env:
            - name: LOG_LEVEL
              value: "INFO"
          envFrom:
            - secretRef:
                name: crdb-data
          readinessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:30030"]
          livenessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:30030"]
          resources:
            requests:
              cpu: 250m
              memory: 128Mi
            limits:
              cpu: 1000m
              memory: 1024Mi
---
apiVersion: v1
kind: Service
metadata:
  name: kpi-value-writerservice
  labels:
    app: kpi-value-writerservice
spec:
  type: ClusterIP
  selector:
    app: kpi-value-writerservice
  ports:
    - name: grpc
      protocol: TCP
      port: 30030
      targetPort: 30030
    - name: metrics
      protocol: TCP
      port: 9192
      targetPort: 9192
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: kpi-value-writerservice-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: kpi-value-writerservice
  minReplicas: 1
  maxReplicas: 20
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 80
  #behavior:
  #  scaleDown:
  #    stabilizationWindowSeconds: 30
+5 −3
Original line number Diff line number Diff line
@@ -43,9 +43,6 @@ class ServiceNameEnum(Enum):
    ZTP                    = 'ztp'
    POLICY                 = 'policy'
    MONITORING             = 'monitoring'
    KPIMANAGER             = 'kpi-manager'
    KPIVALUEAPI            = 'kpi-value-api'
    TELEMETRYFRONTEND      = 'telemetry-frontend'
    DLT                    = 'dlt'
    NBI                    = 'nbi'
    CYBERSECURITY          = 'cybersecurity'
@@ -64,6 +61,10 @@ class ServiceNameEnum(Enum):
    E2EORCHESTRATOR        = 'e2e-orchestrator'
    OPTICALCONTROLLER      = 'opticalcontroller'
    BGPLS                  = 'bgpls-speaker'
    KPIMANAGER             = 'kpi-manager'
    KPIVALUEAPI            = 'kpi-value-api'
    KPIVALUEWRITER         = 'kpi-value-writer'
    TELEMETRYFRONTEND      = 'telemetry-frontend'

    # Used for test and debugging only
    DLT_GATEWAY    = 'dltgateway'
@@ -95,6 +96,7 @@ DEFAULT_SERVICE_GRPC_PORTS = {
    ServiceNameEnum.BGPLS                  .value : 20030,
    ServiceNameEnum.KPIMANAGER             .value : 30010,
    ServiceNameEnum.KPIVALUEAPI            .value : 30020,
    ServiceNameEnum.KPIVALUEWRITER         .value : 30030,
    ServiceNameEnum.TELEMETRYFRONTEND      .value : 30050,

    # Used for test and debugging only
+6 −6
Original line number Diff line number Diff line
@@ -13,9 +13,9 @@
# limitations under the License.

# Build, tag, and push the Docker image to the GitLab Docker registry
build kpi_manager:
build kpi-manager:
  variables:
    IMAGE_NAME: 'kpi_manager' # name of the microservice
    IMAGE_NAME: 'kpi-manager' # name of the microservice
    IMAGE_TAG: 'latest' # tag of the container image (production, development, etc)
  stage: build
  before_script:
@@ -39,13 +39,13 @@ build kpi_manager:
      - .gitlab-ci.yml

# Apply unit test to the component
unit_test context:
unit_test kpi-manager:
  variables:
    IMAGE_NAME: 'kpi_manager' # name of the microservice
    IMAGE_NAME: 'kpi-manager' # name of the microservice
    IMAGE_TAG: 'latest' # tag of the container image (production, development, etc)
  stage: unit_test
  needs:
    - build context
    - build kpi-manager
  before_script:
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
    - if docker network list | grep teraflowbridge; then echo "teraflowbridge is already created"; else docker network create -d bridge teraflowbridge; fi
@@ -71,7 +71,7 @@ unit_test context:
    - NATS_ADDRESS=$(docker inspect nats --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}")
    - echo $NATS_ADDRESS
    - >
      docker run --name $IMAGE_NAME -d -p 1010:1010
      docker run --name $IMAGE_NAME -d -p 30010:30010
      --env "CRDB_URI=cockroachdb://tfs:tfs123@${CRDB_ADDRESS}:26257/tfs_test?sslmode=require"
      --volume "$PWD/src/$IMAGE_NAME/tests:/opt/results"
      --network=teraflowbridge
+109 −0
Original line number Diff line number Diff line
# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Build, tag, and push the Docker image to the GitLab Docker registry
build kpi-value-api:
  variables:
    IMAGE_NAME: 'kpi-value-api' # name of the microservice
    IMAGE_TAG: 'latest' # tag of the container image (production, development, etc)
  stage: build
  before_script:
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
  script:
    - docker buildx build -t "$IMAGE_NAME:$IMAGE_TAG" -f ./src/$IMAGE_NAME/Dockerfile .
    - docker tag "$IMAGE_NAME:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
    - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
  after_script:
    - docker images --filter="dangling=true" --quiet | xargs -r docker rmi
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"'
    - changes:
      - src/common/**/*.py
      - proto/*.proto
      - src/$IMAGE_NAME/**/*.{py,in,yml}
      - src/$IMAGE_NAME/Dockerfile
      - src/$IMAGE_NAME/tests/*.py
      - manifests/${IMAGE_NAME}service.yaml
      - .gitlab-ci.yml

# Apply unit test to the component
unit_test kpi-value-api:
  variables:
    IMAGE_NAME: 'kpi-value-api' # name of the microservice
    IMAGE_TAG: 'latest' # tag of the container image (production, development, etc)
  stage: unit_test
  needs:
    - build kpi-value-api
  before_script:
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
    - if docker network list | grep teraflowbridge; then echo "teraflowbridge is already created"; else docker network create -d bridge teraflowbridge; fi
    - if docker container ls | grep $IMAGE_NAME; then docker rm -f $IMAGE_NAME; else echo "$IMAGE_NAME container is not in the system"; fi
    - docker container prune -f
  script:
    - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
    - docker run --name $IMAGE_NAME -d -p 30020:30020 -v "$PWD/src/$IMAGE_NAME/tests:/opt/results" --network=teraflowbridge $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG
    - sleep 5
    - docker ps -a
    - docker logs $IMAGE_NAME
    - >
      docker exec -i $IMAGE_NAME bash -c
      "coverage run -m pytest --log-level=INFO --verbose --junitxml=/opt/results/${IMAGE_NAME}_report.xml $IMAGE_NAME/tests/test_*.py"
    - docker exec -i $IMAGE_NAME bash -c "coverage report --include='${IMAGE_NAME}/*' --show-missing"
  coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/'
  after_script:
    - docker rm -f $IMAGE_NAME
    - docker network rm teraflowbridge
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"'
    - changes:
      - src/common/**/*.py
      - proto/*.proto
      - src/$IMAGE_NAME/**/*.{py,in,yml}
      - src/$IMAGE_NAME/Dockerfile
      - src/$IMAGE_NAME/tests/*.py
      - src/$IMAGE_NAME/tests/Dockerfile
      - manifests/${IMAGE_NAME}service.yaml
      - .gitlab-ci.yml
  artifacts:
      when: always
      reports:
        junit: src/$IMAGE_NAME/tests/${IMAGE_NAME}_report.xml

## Deployment of the service in Kubernetes Cluster
#deploy context:
#  variables:
#    IMAGE_NAME: 'context' # name of the microservice
#    IMAGE_TAG: 'latest' # tag of the container image (production, development, etc)
#  stage: deploy
#  needs:
#    - unit test context
#    # - integ_test execute
#  script:
#    - 'sed -i "s/$IMAGE_NAME:.*/$IMAGE_NAME:$IMAGE_TAG/" manifests/${IMAGE_NAME}service.yaml'
#    - kubectl version
#    - kubectl get all
#    - kubectl apply -f "manifests/${IMAGE_NAME}service.yaml"
#    - kubectl get all
#  # environment:
#  #   name: test
#  #   url: https://example.com
#  #   kubernetes:
#  #     namespace: test
#  rules:
#    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
#      when: manual    
#    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"'
#      when: manual
Loading