...

Text file src/edge-infra.dev/cmd/edge/device-registrar/justfile

Documentation: edge-infra.dev/cmd/edge/device-registrar

     1kustomize := "bazel run //hack/tools:kustomize --"
     2kubectl := "bazel run //hack/tools:kubectl --"
     3just := "just --justfile=" + justfile_directory() + "/../../../justfile"
     4
     5# build the operator, provider and web/identity
     6build:
     7    bazel build ...
     8
     9# push the containers to your local repo
    10push registry="localhost:21700":
    11    #!/usr/bin/env bash
    12    echo "🔨 pushing images and building if necessary"
    13    bazel run //cmd/tools/pusha -- --repo={{registry}} --insecure-repository=true cmd/edge/device-registrar/... 
    14
    15wait-for-deploy namespace="device-registrar" name="device-registrar" :
    16    #!/usr/bin/env bash
    17    echo "⏳ hang on, waiting for {{name}} deployment.."
    18    while true; do
    19        kubectl rollout status deployment/{{name}} -n {{namespace}}
    20        if [ $? -eq 0 ]; then
    21            break
    22        else
    23            echo "💪 trying again.. "
    24            sleep 5
    25        fi
    26    done
    27
    28fwd:
    29    #!/usr/bin/env bash
    30    echo "🔁 forwarding device-registrar-service on 8080"
    31    kubectl port-forward service/device-registrar-svc -n device-registrar 8080:80 > /dev/null 2>&1 &
    32
    33stopfwd port="8080":
    34    #!/usr/bin/env bash
    35    kill $(ps aux | grep kubectl | grep port-forward | grep {{port}} | awk '{print $2}')
    36    exit 0
    37
    38# apply the CRDs to a cluster
    39crds:
    40    #!/usr/bin/env bash
    41    echo "📦 deploying all required crds"
    42    kubectl apply -k {{invocation_directory()}}/config/pallets/edge/device-registrar/base/crds
    43    kubectl apply -f {{invocation_directory()}}/config/components/edge-iam-v2/crds/iam.edge-infra.dev_clients.yaml
    44    kubectl apply -f {{invocation_directory()}}/config/pallets/sds/nodeagent/base/crds/dsds.edge.ncr.com_ienodes.yaml
    45
    46cert-manager:
    47    #!/usr/bin/env bash
    48    echo "🚀 deploying cert manager"
    49    kubectl apply -f {{invocation_directory()}}/third_party/k8s/certmanager/manifests.yaml  
    50
    51deploy:
    52    #!/usr/bin/env bash
    53    echo "🚀 deploying the crds, cronjob and sample external Application"
    54    kubectl apply -k {{invocation_directory()}}/config/pallets/edge/device-registrar/kind
    55
    56reset:
    57    #!/usr/bin/env bash
    58    echo "🔥 deleting all resources"
    59    kubectl delete -k {{invocation_directory()}}/config/pallets/edge/device-registrar/kind || true
    60    sleep 5
    61  
    62label-kind-nodes:
    63    #!/usr/bin/env bash
    64    kubectl label node edge-worker node.ncr.com/role=controlplane --overwrite
    65
    66kind: stopfwd reset crds push label-kind-nodes deploy wait-for-deploy fwd
    67
    68update: gen-code update-manifests
    69  {{just}} gazelle
    70
    71update-manifests: gen-crds gen-rbac
    72  {{just}} fmt-manifests
    73
    74gen-crds:
    75  {{just}} run pkg/edge/device-registrar/api:gen_crds 
    76
    77gen-rbac:
    78  {{just}} run pkg/edge/device-registrar/controller:gen_rbac
    79
    80gen-code:
    81  {{just}} run pkg/edge/device-registrar/api:gen_code
    82
    83docs:
    84  docker pull swaggerapi/swagger-ui
    85  echo "🚀 swagger-ui will be running on http://localhost:8082"
    86  docker run -p 8082:8080 -e SWAGGER_JSON=/docs/spec.json -v {{invocation_directory()}}/docs/edge/components/device-registrar:/docs swaggerapi/swagger-ui
    87
    88gen-docs: swagger-linter-fix swagger-gen swagger-linter-revert
    89
    90swagger-gen:
    91  #!/usr/bin/env bash
    92  RED='\033[31m'
    93  BOLD='\033[1m'
    94  NC='\033[0m'
    95  echo "📝 To change the ordering of the tags or the tag descriptions, please edit this justfile command."
    96  echo -e "\n${BOLD}${RED}NOTE:${NC} The goimports linter changes the array index symbol in the go-swagger parameters list from a ${BOLD}${RED}+${NC} to a - symbol, which will cause the ${BOLD}swagger generate ${NC}command to fail."
    97  echo -e "If your swagger updates involve adding a parameter list, please modify to the ${BOLD}swagger-linter-fix${NC} justfile command with your changes.\n"
    98
    99  go install github.com/go-swagger/go-swagger/cmd/swagger@latest
   100  swagger generate spec -w {{invocation_directory()}}/pkg/edge/device-registrar/services -o {{invocation_directory()}}/docs/edge/components/device-registrar/spec.json -m 
   101
   102  # Define the TAGS JSON snippet
   103  TAGS='{
   104    "tags": [
   105      {
   106        "name": "core",
   107        "description": "Core device registration endpoints"
   108      },
   109      {
   110        "name": "additional",
   111        "description": "Additional device registration endpoints"
   112      },
   113      {
   114        "name": "legacy",
   115        "description": "Legacy device registration endpoints"
   116      }
   117    ]
   118  }'
   119
   120  # Use jq to insert the TAGS after the "info" field
   121  jq --argjson tags "$TAGS" '. + $tags' {{invocation_directory()}}/docs/edge/components/device-registrar/spec.json > {{invocation_directory()}}/docs/edge/components/device-registrar/spec_with_tags.json
   122
   123  # Replace the original spec file with the modified one
   124  mv {{invocation_directory()}}/docs/edge/components/device-registrar/spec_with_tags.json {{invocation_directory()}}/docs/edge/components/device-registrar/spec.json
   125  echo "🎉 Swagger spec generated at {{invocation_directory()}}/docs/edge/components/device-registrar/spec.json"
   126
   127gen-code-coverage:
   128  #!/usr/bin/env bash
   129  go test -coverprofile=coverage.out {{invocation_directory()}}/pkg/edge/device-registrar/services
   130  go tool cover -html=coverage.out -o coverage.html
   131  open coverage.html
   132
   133# This is a temporary fix for the linter issue where goimports changes the + symbol to a - symbol in the swagger spec.
   134# The first command changes the - symbol to a + symbol, and the second command reverts the changes after the swagger spec is generated
   135swagger-linter-fix:
   136  #!/usr/bin/env bash
   137  sed -i '' 's/- name: X-Client-DN/+ name: X-Client-DN/g' {{invocation_directory()}}/pkg/edge/device-registrar/services/device_discovery_service.go
   138
   139swagger-linter-revert:
   140  #!/usr/bin/env bash
   141  sed -i '' 's/+ name: X-Client-DN/- name: X-Client-DN/g' {{invocation_directory()}}/pkg/edge/device-registrar/services/device_discovery_service.go

View as plain text