diff --git a/.github/workflows/operator-ci.yaml b/.github/workflows/operator-ci.yaml index 670c3e91..accd24b1 100644 --- a/.github/workflows/operator-ci.yaml +++ b/.github/workflows/operator-ci.yaml @@ -49,7 +49,7 @@ on: env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} - GO_VERSION: 1.23.6 + GO_VERSION: 1.23.7 PLATFORMS: linux/amd64,linux/arm64 # There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. @@ -125,6 +125,8 @@ jobs: - name: Build the operator container image id: build + env: + platforms: ${{ env.PLATFORMS }} run: | apt-get update && apt-get install -y make git jq cd operator diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9d6a5c12..a6837a8e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,7 +21,7 @@ default: tags: - baseos-infra - image: gitlab-master.nvidia.com:5005/dgx/infra/skyhook-operator/ci:latest + image: gitlab-master.nvidia.com:5005/dgx/infra/skyhook-operator/ci:latest ## TODO: this is no longer getting updated, we need to address this variables: KUBERNETES_CPU_LIMIT: "4" @@ -35,10 +35,6 @@ workflow: rules: - if: $CI_COMMIT_TAG -include: - - project: dgx/infra/gitlint-ci - ref: main - file: gitlint.yml ## setup vault creds bootstrap: diff --git a/chart/LICENSE b/chart/LICENSE index 7a694c96..ea5b6064 120000 --- a/chart/LICENSE +++ b/chart/LICENSE @@ -1 +1 @@ -LICENSE \ No newline at end of file +../LICENSE \ No newline at end of file diff --git a/containers/agent.Dockerfile b/containers/agent.Dockerfile index 1b41b1e6..06aec43f 100644 --- a/containers/agent.Dockerfile +++ b/containers/agent.Dockerfile @@ -1,3 +1,22 @@ +# +# LICENSE START +# +# Copyright (c) NVIDIA CORPORATION. All rights reserved. +# +# 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. +# +# LICENSE END +# FROM python:3.12-alpine AS builder ARG AGENT_VERSION diff --git a/containers/agentless/Dockerfile b/containers/agentless/Dockerfile index 744cf657..37c60502 100644 --- a/containers/agentless/Dockerfile +++ b/containers/agentless/Dockerfile @@ -1,16 +1,23 @@ -# Copyright (c) NVIDIA CORPORATION. All rights reserved. +# +# LICENSE START # -# 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 +# Copyright (c) NVIDIA CORPORATION. All rights reserved. # -# http://www.apache.org/licenses/LICENSE-2.0 +# 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 # -# 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. +# 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. +# +# LICENSE END +# + ARG BUSYBOX_TAG=1.36.1 diff --git a/containers/agentless/entrypoint.sh b/containers/agentless/entrypoint.sh index 4ba9374b..c98e69ae 100755 --- a/containers/agentless/entrypoint.sh +++ b/containers/agentless/entrypoint.sh @@ -21,18 +21,6 @@ # - - - - - - - - - - - - SLEEP_LEN=${SLEEP_LEN:-$(($RANDOM % 5 + 5))} echo "agentless ["$@"] sleep for ${SLEEP_LEN} and exit with ${EXIT_CODE}" diff --git a/containers/agentless/versions.sh b/containers/agentless/versions.sh index 1431f1b1..b003dfbe 100644 --- a/containers/agentless/versions.sh +++ b/containers/agentless/versions.sh @@ -21,18 +21,6 @@ # - - - - - - - - - - - - ## This is the list of versions that will be tagged for the test container so it can be ## used in the e2e tests. ## diff --git a/containers/ci.Dockerfile b/containers/ci.Dockerfile index 6caba4e6..7a3454f5 100644 --- a/containers/ci.Dockerfile +++ b/containers/ci.Dockerfile @@ -1,16 +1,22 @@ -# Copyright (c) NVIDIA CORPORATION. All rights reserved. +# +# LICENSE START # -# 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 +# Copyright (c) NVIDIA CORPORATION. All rights reserved. # -# http://www.apache.org/licenses/LICENSE-2.0 +# 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 # -# 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. +# 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. +# +# LICENSE END +# ARG GO_VERSION diff --git a/containers/operator.Dockerfile b/containers/operator.Dockerfile index 62ace625..ddb04ddf 100644 --- a/containers/operator.Dockerfile +++ b/containers/operator.Dockerfile @@ -1,16 +1,22 @@ -# Copyright (c) NVIDIA CORPORATION. All rights reserved. +# +# LICENSE START # -# 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 +# Copyright (c) NVIDIA CORPORATION. All rights reserved. # -# http://www.apache.org/licenses/LICENSE-2.0 +# 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 # -# 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. +# 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. +# +# LICENSE END +# # Build the manager binary ARG GO_VERSION diff --git a/k8s-tests/chainsaw/helm/helm-chart-test/chainsaw-test.yaml b/k8s-tests/chainsaw/helm/helm-chart-test/chainsaw-test.yaml index 19f123b7..de236fee 100644 --- a/k8s-tests/chainsaw/helm/helm-chart-test/chainsaw-test.yaml +++ b/k8s-tests/chainsaw/helm/helm-chart-test/chainsaw-test.yaml @@ -18,24 +18,18 @@ # LICENSE END # - - - - - - # yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json apiVersion: chainsaw.kyverno.io/v1alpha1 kind: Test metadata: name: helm-chart spec: - description: This test asserts that the helm chart is working as expected. Specifcally it asserts that the helm chart works when given a different + description: This test asserts that the helm chart is working as expected. Specifically it asserts that the helm chart works when given a different deployment name than skyhook-operator and that the tolerations that are given to the chart through a values file work as expected. concurrent: false timeouts: - assert: 120s - exec: 120s + assert: 240s + exec: 240s steps: - try: - script: diff --git a/k8s-tests/chainsaw/helm/helm-scale-test/chainsaw-test.yaml b/k8s-tests/chainsaw/helm/helm-scale-test/chainsaw-test.yaml index b5ac8815..e21ab381 100644 --- a/k8s-tests/chainsaw/helm/helm-scale-test/chainsaw-test.yaml +++ b/k8s-tests/chainsaw/helm/helm-scale-test/chainsaw-test.yaml @@ -18,12 +18,6 @@ # LICENSE END # - - - - - - # yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json apiVersion: chainsaw.kyverno.io/v1alpha1 kind: Test @@ -34,8 +28,8 @@ spec: deployment name than skyhook-operator and that the tolerations that are given to the chart through a values file work as expected. concurrent: false timeouts: - assert: 120s - exec: 120s + assert: 240s + exec: 240s steps: - try: - script: diff --git a/operator/Makefile b/operator/Makefile index 55d08743..b4a30f52 100644 --- a/operator/Makefile +++ b/operator/Makefile @@ -223,7 +223,7 @@ merge-coverage: echo "mode: set" > $(REPORTING)/cover.out ## skip first line with +2 tail -n +2 $(REPORTING)/temp-cover.out | sed '/mode: set/d' >> $(REPORTING)/cover.out - $(sedrp) 's/^\/.*(\/skyhook-operator.*)/gitlab-master\.nvidia\.com\/dgx\/infra\1/g' $(REPORTING)/cover.out + $(sedrp) 's|^/.*skyhook/operator/(.*)$$|github\.com/NVIDIA/skyhook/\1|g' $(REPORTING)/cover.out .PHONY: lint lint: golangci-lint license-check ## Run golangci-lint linter & yamllint diff --git a/operator/README.md b/operator/README.md index 68792962..10052481 100644 --- a/operator/README.md +++ b/operator/README.md @@ -27,45 +27,70 @@ spec: interruptionBudget: percent: 33 packages: - nvssh: - version: 2024.05.10 - image: nvcr.io/nvidian/swgpu-baseos/nvssh:2024.05.10 - configInterrupts: - nvssh_vars.sh: - type: service - services: [cron] + something_important: + version: 1.0.0 + image: ghcr.io/nvidia/skyhook-packages/shellscript + depends_on: + tuning: 1.0.0 configMap: - nvssh_vars.sh: |- + apply.sh: |- + #!/bin/bash + echo "hello world" > /skyhook-hello-world + sleep 60 + apply_check.sh: |- + #!/bin/bash + cat /skyhook-hello-world + sleep 30 + config.sh: |- #!/bin/bash - nvssh_allowed_roles=access-azure-nv-ngc-prod-dgxc-admin - nvssh_allowed_sudo_roles=access-azure-nv-ngc-prod-dgxc-admin - echo $0 - bcp: - version: 2024.05.13 - image: nvcr.io/nvidian/swgpu-baseos/bcp:2024.05.13 - env: - - name: CSP - value: azure - interrupt: - type: service - services: [containerd] + echo "a config is run" >> /skyhook-hello-world + sleep 60 + config_check.sh: |- + #!/bin/bash + grep "config" /skyhook-hello-world + sleep 30 + tuning: + version: 1.0.0 + image: ghcr.io/nvidia/skyhook-packages/tuning + interrupt: + type: reboot + configInterrupts: + grub.conf: + type: reboot + sysctl.conf: + type: restart_all_services + configMap: + grub.conf: |- + hugepagesz=1G + hugepages=2 + hugepagesz=2M + hugepages=5128 + sysctl.conf: |- + fs.inotify.max_user_instances=65535 + fs.inotify.max_user_watches=524288 + kernel.threads-max=16512444 + vm.max_map_count=262144 + vm.min_free_kbytes=65536 + ulimit.conf: |- + memlock: 128 + fsize: 1000 ``` -Packages can depend on each other, so if you needed bcp to be installed before nvssh you can define that like this: +Packages can depend on each other, so if you needed `something_important` to be installed after `tuning` you can define that like this: ```yaml - nvssh: + something_important: ... dependsOn: - bcp: "3.0" - bcp: + tuning: "1.0.0" + tuning: ... ``` ## Development ### Prerequisites -- go version v1.23.4+ +- go version v1.23.7+ - docker version 17.03+ or podman 4.9.4+ (project makefile kind of assumes podman) - kubectl version v1.27.3+. - Access to a Kubernetes v1.27+ cluster. (we test on 1.27, should work on older if needed, just not tested.) @@ -130,6 +155,7 @@ Development generate-mocks Generate code for interface mocking license-report Run run license report license-check Run go-licenses check against code. + license-fmt Run add license header to code. fmt Run go fmt against code. vet Run go vet against code. test Run all tests. @@ -149,7 +175,12 @@ Build docker-build Build docker image with the manager. Deployment + create-namespace Create the namespace in the K8s cluster specified in ~/.kube/config. install Install CRDs into the K8s cluster specified in ~/.kube/config. + install-cert-manager Install cert-manager into the K8s cluster specified in ~/.kube/config. + install-helm-chart Install helm chart into the K8s cluster specified in ~/.kube/config. + uninstall-helm-chart Uninstall helm chart from the K8s cluster specified in ~/.kube/config. + uninstall-cert-manager Uninstall cert-manager from the K8s cluster specified in ~/.kube/config. uninstall Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. deploy Deploy controller to the K8s cluster specified in ~/.kube/config. generate-helm Generates new helm chart using helmify. Be-careful, this can break things, it overwrites files, make sure to look at you git diff. @@ -167,7 +198,6 @@ Build Dependencies chainsaw Download chainsaw locally if necessary. helm Download helm locally if necessary. helmify Download helmify locally if necessary. - go-license Download go-license locally if necessary. go-licenses Download go-licenses locally if necessary. ``` diff --git a/operator/api/v1alpha1/groupversion_info.go b/operator/api/v1alpha1/groupversion_info.go index c257d6b8..9051f1cc 100644 --- a/operator/api/v1alpha1/groupversion_info.go +++ b/operator/api/v1alpha1/groupversion_info.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - // Package v1alpha1 contains API Schema definitions for the skyhook v1alpha1 API group // +kubebuilder:object:generate=true // +groupName=skyhook.nvidia.com diff --git a/operator/api/v1alpha1/skyhook_types.go b/operator/api/v1alpha1/skyhook_types.go index 4d1dba31..4076d859 100644 --- a/operator/api/v1alpha1/skyhook_types.go +++ b/operator/api/v1alpha1/skyhook_types.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package v1alpha1 import ( diff --git a/operator/api/v1alpha1/skyhook_types_test.go b/operator/api/v1alpha1/skyhook_types_test.go index d327012f..ae0f18aa 100644 --- a/operator/api/v1alpha1/skyhook_types_test.go +++ b/operator/api/v1alpha1/skyhook_types_test.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package v1alpha1 import ( diff --git a/operator/api/v1alpha1/skyhook_webhook.go b/operator/api/v1alpha1/skyhook_webhook.go index 7964f5ee..ea5b6cf4 100644 --- a/operator/api/v1alpha1/skyhook_webhook.go +++ b/operator/api/v1alpha1/skyhook_webhook.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package v1alpha1 import ( diff --git a/operator/api/v1alpha1/skyhook_webhook_test.go b/operator/api/v1alpha1/skyhook_webhook_test.go index c4ed6091..9b81c09d 100644 --- a/operator/api/v1alpha1/skyhook_webhook_test.go +++ b/operator/api/v1alpha1/skyhook_webhook_test.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package v1alpha1 import ( diff --git a/operator/api/v1alpha1/webhook_suite_test.go b/operator/api/v1alpha1/webhook_suite_test.go index f4641644..3ce9fffb 100644 --- a/operator/api/v1alpha1/webhook_suite_test.go +++ b/operator/api/v1alpha1/webhook_suite_test.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package v1alpha1 import ( diff --git a/operator/api/v1alpha1/zz_generated.deepcopy.go b/operator/api/v1alpha1/zz_generated.deepcopy.go index aafe7045..6c29ceae 100644 --- a/operator/api/v1alpha1/zz_generated.deepcopy.go +++ b/operator/api/v1alpha1/zz_generated.deepcopy.go @@ -1,3 +1,5 @@ +//go:build !ignore_autogenerated + /* * LICENSE START * @@ -18,14 +20,6 @@ * LICENSE END */ - - - - -//go:build !ignore_autogenerated - - - // Code generated by controller-gen. DO NOT EDIT. package v1alpha1 diff --git a/operator/cmd/main.go b/operator/cmd/main.go index 684dc9b5..e04613db 100644 --- a/operator/cmd/main.go +++ b/operator/cmd/main.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package main import ( diff --git a/operator/config/crd/bases/skyhook.nvidia.com_skyhooks.yaml b/operator/config/crd/bases/skyhook.nvidia.com_skyhooks.yaml index 06183079..959fd951 100644 --- a/operator/config/crd/bases/skyhook.nvidia.com_skyhooks.yaml +++ b/operator/config/crd/bases/skyhook.nvidia.com_skyhooks.yaml @@ -17,13 +17,6 @@ # # LICENSE END # - - - - - - - --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/operator/config/rbac/role.yaml b/operator/config/rbac/role.yaml index 416bb840..06033f26 100644 --- a/operator/config/rbac/role.yaml +++ b/operator/config/rbac/role.yaml @@ -17,13 +17,6 @@ # # LICENSE END # - - - - - - - --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole diff --git a/operator/config/samples/skyhook_v1alpha1_skyhook.yaml b/operator/config/samples/skyhook_v1alpha1_skyhook.yaml index 3021eb36..d041964f 100644 --- a/operator/config/samples/skyhook_v1alpha1_skyhook.yaml +++ b/operator/config/samples/skyhook_v1alpha1_skyhook.yaml @@ -19,11 +19,6 @@ # - - - - - apiVersion: skyhook.nvidia.com/v1alpha1 kind: Skyhook metadata: @@ -38,39 +33,59 @@ spec: additionalTolerations: - key: nvidia.com/gpu operator: Exists - serial: true + nodeSelectors: + matchLabels: + agentpool: gpu podNonInterruptLabels: matchLabels: key: value interruptionBudget: percent: 33 packages: - spenser: - version: "3.1.1" + something_important: + version: 1.0.0 + image: ghcr.io/nvidia/skyhook-packages/shellscript + depends_on: + tuning: 1.0.0 configMap: - nvssh_vars.sh: |- + apply.sh: |- + #!/bin/bash + echo "hello world" > /skyhook-hello-world + sleep 60 + apply_check.sh: |- + #!/bin/bash + cat /skyhook-hello-world + sleep 30 + config.sh: |- #!/bin/bash - nvssh_allowed_roles=access-azure-nv-ngc-prod-dgxc-admin - nvssh_allowed_sudo_roles=access-azure-nv-ngc-prod-dgxc-admin - echo $0 - interrupt: - type: reboot - image: ghcr.io/nvidia/skyhook/agentless:latest - ssh: - version: "3.0" - image: ghcr.io/nvidia/skyhook/agentless:latest - phoenix: - version: "2.1.4" - env: - - key: foo - value: bar - interrupt: - type: service - services: [cron] - image: ghcr.io/nvidia/skyhook/agentless:latest - dax: - version: "1.2.3" - image: ghcr.io/nvidia/skyhook/agentless:latest - dependsOn: - spenser: "3.1.1" - ssh: "3.0" \ No newline at end of file + echo "a config is run" >> /skyhook-hello-world + sleep 60 + config_check.sh: |- + #!/bin/bash + grep "config" /skyhook-hello-world + sleep 30 + tuning: + version: 1.0.0 + image: ghcr.io/nvidia/skyhook-packages/tuning + interrupt: + type: reboot + configInterrupts: + grub.conf: + type: reboot + sysctl.conf: + type: restart_all_services + configMap: + grub.conf: |- + hugepagesz=1G + hugepages=2 + hugepagesz=2M + hugepages=5128 + sysctl.conf: |- + fs.inotify.max_user_instances=65535 + fs.inotify.max_user_watches=524288 + kernel.threads-max=16512444 + vm.max_map_count=262144 + vm.min_free_kbytes=65536 + ulimit.conf: |- + memlock: 128 + fsize: 1000 \ No newline at end of file diff --git a/operator/config/webhook/kustomization.yaml b/operator/config/webhook/kustomization.yaml index 055b078a..a88fc528 100644 --- a/operator/config/webhook/kustomization.yaml +++ b/operator/config/webhook/kustomization.yaml @@ -18,12 +18,6 @@ # LICENSE END # - - - - - - resources: - manifests.yaml - service.yaml diff --git a/operator/config/webhook/kustomizeconfig.yaml b/operator/config/webhook/kustomizeconfig.yaml index 160471cf..08686586 100644 --- a/operator/config/webhook/kustomizeconfig.yaml +++ b/operator/config/webhook/kustomizeconfig.yaml @@ -18,12 +18,6 @@ # LICENSE END # - - - - - - # the following config is for teaching kustomize where to look at when substituting nameReference. # It requires kustomize v2.1.0 or newer to work properly. nameReference: diff --git a/operator/config/webhook/manifests.yaml b/operator/config/webhook/manifests.yaml index 9f1cba42..e7b42a80 100644 --- a/operator/config/webhook/manifests.yaml +++ b/operator/config/webhook/manifests.yaml @@ -17,13 +17,6 @@ # # LICENSE END # - - - - - - - --- apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration diff --git a/operator/config/webhook/service.yaml b/operator/config/webhook/service.yaml index 63a42ce1..54d2cc8b 100644 --- a/operator/config/webhook/service.yaml +++ b/operator/config/webhook/service.yaml @@ -18,12 +18,6 @@ # LICENSE END # - - - - - - apiVersion: v1 kind: Service metadata: diff --git a/operator/internal/controller/annotations.go b/operator/internal/controller/annotations.go index c9816751..bc2952ef 100644 --- a/operator/internal/controller/annotations.go +++ b/operator/internal/controller/annotations.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package controller import ( diff --git a/operator/internal/controller/cluster_state_v2.go b/operator/internal/controller/cluster_state_v2.go index d8ae3437..c07686d4 100644 --- a/operator/internal/controller/cluster_state_v2.go +++ b/operator/internal/controller/cluster_state_v2.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package controller import ( diff --git a/operator/internal/controller/cluster_state_v2_test.go b/operator/internal/controller/cluster_state_v2_test.go index 2ac0b333..bb06b2de 100644 --- a/operator/internal/controller/cluster_state_v2_test.go +++ b/operator/internal/controller/cluster_state_v2_test.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package controller import ( diff --git a/operator/internal/controller/event_handler.go b/operator/internal/controller/event_handler.go index d1a859d6..9542dd87 100644 --- a/operator/internal/controller/event_handler.go +++ b/operator/internal/controller/event_handler.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package controller import ( diff --git a/operator/internal/controller/event_handler_test.go b/operator/internal/controller/event_handler_test.go index dea6fbd9..4e5200da 100644 --- a/operator/internal/controller/event_handler_test.go +++ b/operator/internal/controller/event_handler_test.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package controller import ( diff --git a/operator/internal/controller/mock/SkyhookNodes.go b/operator/internal/controller/mock/SkyhookNodes.go index a34b2ebe..bea4f817 100644 --- a/operator/internal/controller/mock/SkyhookNodes.go +++ b/operator/internal/controller/mock/SkyhookNodes.go @@ -18,11 +18,6 @@ * LICENSE END */ - - - - - // Code generated by mockery v2.42.3. DO NOT EDIT. package controller diff --git a/operator/internal/controller/pod_controller.go b/operator/internal/controller/pod_controller.go index e2bd180f..d4cc75c1 100644 --- a/operator/internal/controller/pod_controller.go +++ b/operator/internal/controller/pod_controller.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package controller import ( diff --git a/operator/internal/controller/skyhook_controller.go b/operator/internal/controller/skyhook_controller.go index ed82db24..b68542ce 100644 --- a/operator/internal/controller/skyhook_controller.go +++ b/operator/internal/controller/skyhook_controller.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package controller import ( diff --git a/operator/internal/controller/skyhook_controller_test.go b/operator/internal/controller/skyhook_controller_test.go index 33d5ef7d..1a3212fd 100644 --- a/operator/internal/controller/skyhook_controller_test.go +++ b/operator/internal/controller/skyhook_controller_test.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package controller import ( diff --git a/operator/internal/controller/suite_test.go b/operator/internal/controller/suite_test.go index d55a8bd9..64543613 100644 --- a/operator/internal/controller/suite_test.go +++ b/operator/internal/controller/suite_test.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package controller import ( diff --git a/operator/internal/controller/zz.migration.0.5.0.go b/operator/internal/controller/zz.migration.0.5.0.go index 0b8dad4e..1161f122 100644 --- a/operator/internal/controller/zz.migration.0.5.0.go +++ b/operator/internal/controller/zz.migration.0.5.0.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package controller import "github.com/go-logr/logr" diff --git a/operator/internal/dal/dal.go b/operator/internal/dal/dal.go index ec7f57c9..3e20c7cd 100644 --- a/operator/internal/dal/dal.go +++ b/operator/internal/dal/dal.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package dal import ( diff --git a/operator/internal/dal/mock/DAL.go b/operator/internal/dal/mock/DAL.go index 291afbf6..95c18858 100644 --- a/operator/internal/dal/mock/DAL.go +++ b/operator/internal/dal/mock/DAL.go @@ -18,11 +18,6 @@ * LICENSE END */ - - - - - // Code generated by mockery v2.42.3. DO NOT EDIT. package dal diff --git a/operator/internal/graph/dependency_graph.go b/operator/internal/graph/dependency_graph.go index 5e238eac..49d2f673 100644 --- a/operator/internal/graph/dependency_graph.go +++ b/operator/internal/graph/dependency_graph.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package graph import ( diff --git a/operator/internal/graph/dependency_graph_test.go b/operator/internal/graph/dependency_graph_test.go index 5942e32f..4f6be9ec 100644 --- a/operator/internal/graph/dependency_graph_test.go +++ b/operator/internal/graph/dependency_graph_test.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package graph import ( diff --git a/operator/internal/mocks/client/Client.go b/operator/internal/mocks/client/Client.go index b11003d5..4ec3445f 100644 --- a/operator/internal/mocks/client/Client.go +++ b/operator/internal/mocks/client/Client.go @@ -18,11 +18,6 @@ * LICENSE END */ - - - - - // Code generated by mockery v2.42.3. DO NOT EDIT. package client diff --git a/operator/internal/mocks/record/EventRecorder.go b/operator/internal/mocks/record/EventRecorder.go index 3e9d6ce8..55f9d55b 100644 --- a/operator/internal/mocks/record/EventRecorder.go +++ b/operator/internal/mocks/record/EventRecorder.go @@ -18,11 +18,6 @@ * LICENSE END */ - - - - - // Code generated by mockery v2.42.3. DO NOT EDIT. package record diff --git a/operator/internal/mocks/workqueue/RateLimitingInterface.go b/operator/internal/mocks/workqueue/RateLimitingInterface.go index 0f6463b8..0b896aec 100644 --- a/operator/internal/mocks/workqueue/RateLimitingInterface.go +++ b/operator/internal/mocks/workqueue/RateLimitingInterface.go @@ -18,11 +18,6 @@ * LICENSE END */ - - - - - // Code generated by mockery v2.42.3. DO NOT EDIT. package workqueue diff --git a/operator/internal/version/version.go b/operator/internal/version/version.go index ea9efa3a..53948952 100644 --- a/operator/internal/version/version.go +++ b/operator/internal/version/version.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package version import "golang.org/x/mod/semver" diff --git a/operator/internal/wrapper/node.go b/operator/internal/wrapper/node.go index f7810db1..4fefa72d 100644 --- a/operator/internal/wrapper/node.go +++ b/operator/internal/wrapper/node.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package wrapper import ( diff --git a/operator/internal/wrapper/skyhook.go b/operator/internal/wrapper/skyhook.go index 8539f9d4..75f44616 100644 --- a/operator/internal/wrapper/skyhook.go +++ b/operator/internal/wrapper/skyhook.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package wrapper import ( diff --git a/operator/internal/wrapper/skyhook_test.go b/operator/internal/wrapper/skyhook_test.go index aeaf31ef..5e7b83c5 100644 --- a/operator/internal/wrapper/skyhook_test.go +++ b/operator/internal/wrapper/skyhook_test.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package wrapper import ( diff --git a/operator/internal/wrapper/wrapper_suite_test.go b/operator/internal/wrapper/wrapper_suite_test.go index 44f9d14d..0fa2f888 100644 --- a/operator/internal/wrapper/wrapper_suite_test.go +++ b/operator/internal/wrapper/wrapper_suite_test.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package wrapper_test import ( diff --git a/operator/internal/wrapper/zz.migration.0.5.0.go b/operator/internal/wrapper/zz.migration.0.5.0.go index f2e1d9c5..9467e13f 100644 --- a/operator/internal/wrapper/zz.migration.0.5.0.go +++ b/operator/internal/wrapper/zz.migration.0.5.0.go @@ -18,9 +18,6 @@ * LICENSE END */ - - - package wrapper import ( diff --git a/scripts/find-skyhook-resources.sh b/scripts/find-skyhook-resources.sh deleted file mode 100755 index 79f32e19..00000000 --- a/scripts/find-skyhook-resources.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -# -# LICENSE START -# -# Copyright (c) NVIDIA CORPORATION. All rights reserved. -# -# 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. -# -# LICENSE END -# - - - - - - - - - - - - - - -## prints out all resources that are namespaced -## can be helpful for debuging - -ns=${1:-skyhook} - -for resource in $(kubectl api-resources --verbs=list --namespaced -o name); do - echo "resource: ${resource}" - kubectl get --show-kind -n ${ns} ${resource} -done \ No newline at end of file diff --git a/scripts/format_license.py b/scripts/format_license.py index a305ecee..4624338d 100755 --- a/scripts/format_license.py +++ b/scripts/format_license.py @@ -22,37 +22,22 @@ import os import argparse +import re from typing import Dict, List, Tuple import fnmatch -import re -# Comment style definitions for different file types +# Comment style definitions for different file types with regex patterns COMMENT_STYLES = { - '.py': { + r'.*\.py$|.*\.sh$|.*\.ya?ml$|.*\.Dockerfile$|^Dockerfile$': { 'start': '# ', 'line': '# ', 'end': '# ' }, - '.sh': { - 'start': '# ', - 'line': '# ', - 'end': '# ' - }, - '.go': { + r'.*\.go$': { 'start': '/*', 'line': ' * ', 'end': ' */' }, - '.yml': { - 'start': '# ', - 'line': '# ', - 'end': '# ' - }, - '.yaml': { - 'start': '# ', - 'line': '# ', - 'end': '# ' - } } # Built-in ignore patterns @@ -121,8 +106,8 @@ def format_license(license_text: str, comment_style: Dict[str, str]) -> str: ]) return '\n'.join(formatted) -def find_files(root_dir: str, extensions: List[str], ignore_patterns: List[str]) -> List[str]: - """Find all files with the given extensions recursively, respecting ignore patterns.""" +def find_files(root_dir: str, patterns: List[str], ignore_patterns: List[str]) -> List[str]: + """Find all files matching the regex patterns recursively, respecting ignore patterns.""" matches = [] for root, _, filenames in os.walk(root_dir): # Get relative path from root_dir @@ -132,15 +117,19 @@ def find_files(root_dir: str, extensions: List[str], ignore_patterns: List[str]) if should_ignore(rel_root, ignore_patterns): continue - for ext in extensions: - for filename in fnmatch.filter(filenames, f'*{ext}'): - rel_path = os.path.join(rel_root, filename) + for filename in filenames: + rel_path = os.path.join(rel_root, filename) + + # Skip if the file should be ignored + if should_ignore(rel_path, ignore_patterns): + continue - # Skip if the file should be ignored - if should_ignore(rel_path, ignore_patterns): - continue + # Check if the file matches any of our patterns + for pattern in patterns: + if re.match(pattern, filename): + matches.append(os.path.join(root, filename)) + break # No need to check other patterns once we have a match - matches.append(os.path.join(root, filename)) return matches def find_existing_license(content: str) -> Tuple[int, int]: @@ -159,7 +148,7 @@ def find_existing_license(content: str) -> Tuple[int, int]: return start_line, end_line -def insert_license(file_path: str, formatted_license: str) -> None: +def insert_license(file_path: str, formatted_license: str, verbose: bool = False) -> None: """Insert the formatted license at the beginning of the file.""" with open(file_path, 'r') as f: content = f.read() @@ -172,7 +161,8 @@ def insert_license(file_path: str, formatted_license: str) -> None: # Check if the found license is the same as the formatted license existing_license = "\n".join(lines[start_line:end_line]) if existing_license == formatted_license: - print(f"License is already formatted in {file_path}") + if verbose: + print(f"License is already formatted in {file_path}") return # Remove existing license @@ -198,45 +188,45 @@ def main(): """License Header Formatting Tool for Multiple File Types. This script formats and applies NVIDIA's Apache 2.0 license headers to source code files. - It supports multiple file types (Python, Shell, Go, YAML) and handles each with appropriate - comment styles. The script will: + It supports multiple file types and handles each with appropriate comment styles. + The script will: 1. Add license headers to files that don't have them 2. Replace existing license headers with the standardized format 3. Preserve shebang lines in scripts - 4. Skip vendor directories and files matching .gitignore patterns + 4. Skip vendor directories and files matching ignore patterns 5. Add LICENSE START/END markers for easier detection and replacement Supported file types: - - Python (.py) : Uses # comments - - Shell (.sh) : Uses # comments - - Go (.go) : Uses /* */ block comments - - YAML (.yml) : Uses # comments - - YAML (.yaml) : Uses # comments + - Python (.py) : Uses # comments + - Shell (.sh) : Uses # comments + - Go (.go) : Uses /* */ block comments + - YAML (.yml/.yaml) : Uses # comments + - Dockerfile : Uses # comments (includes both "Dockerfile" and files ending in ".Dockerfile") Usage: - ./format_license.py [--license-file PATH] [--root-dir PATH] + ./format_license.py [--license-file PATH] [--root-dir PATH] [--verbose] Arguments: --license-file : Path to the Apache 2.0 license file (default: LICENSE) - --root-dir : Root directory to search for files (default: current directory) + --root-dir : Root directory to search for files (default: current directory) + --verbose : Show detailed messages, including when licenses are already formatted Example: # Format all supported files in the current directory ./format_license.py - # Format files using a specific license file and directory - ./format_license.py --license-file /path/to/LICENSE --root-dir /path/to/project + # Format files using a specific license file and directory with verbose output + ./format_license.py --license-file /path/to/LICENSE --root-dir /path/to/project --verbose Note: The script automatically ignores common vendor directories. The chart/ directory is also ignored by default. See BUILT_IN_IGNORE_PATTERNS for more details. """ parser = argparse.ArgumentParser(description='Format and apply license headers to source files') - parser.add_argument('--license-file', default='LICENSE', - help='Path to the license template file') - parser.add_argument('--root-dir', default='.', - help='Root directory to search for files') + parser.add_argument('--license-file', default='LICENSE', help='Path to the license template file') + parser.add_argument('--root-dir', default='.', help='Root directory to search for files') + parser.add_argument('--verbose', action='store_true', help='Show detailed messages, including when licenses are already formatted') args = parser.parse_args() # Read the license template @@ -258,15 +248,15 @@ def main(): # Read .gitignore patterns ignore_patterns = BUILT_IN_IGNORE_PATTERNS - # Process each file type - for ext, comment_style in COMMENT_STYLES.items(): + # Process each file pattern + for pattern, comment_style in COMMENT_STYLES.items(): # Format the license for this file type formatted_license = format_license(license_text, comment_style) - # Find and process all files of this type - files = find_files(args.root_dir, [ext], ignore_patterns) + # Find and process all files matching this pattern + files = find_files(args.root_dir, [pattern], ignore_patterns) for file_path in files: - insert_license(file_path, formatted_license) + insert_license(file_path, formatted_license, args.verbose) if __name__ == '__main__': main() \ No newline at end of file diff --git a/scripts/monitor.sh b/scripts/monitor.sh deleted file mode 100755 index e88ce727..00000000 --- a/scripts/monitor.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -# -# LICENSE START -# -# Copyright (c) NVIDIA CORPORATION. All rights reserved. -# -# 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. -# -# LICENSE END -# - - - - - - - -if [ -f $PWD/monitor.txt ]; then - echo "cpu" - cut -d" " -f1 ~/git_repos/dgx/infra/skyhook-operator/monitor.txt |sed 's/m//g'| sort -rn | head -5 - echo "memory" - cut -d" " -f2 ~/git_repos/dgx/infra/skyhook-operator/monitor.txt |sed 's/Mi//g'| sort -rn | head -5 - rm $PWD/monitor.txt -fi - - -pods=$(kubectl get pods -n skyhook-operator | grep skyhook-operator-controller-manager | awk '{print $1}') -while true; do - for pod in ${pods}; do - kubectl top pod $pod -n skyhook-operator --no-headers | tr -s ' ' | cut -d" " -f2,3 >> $PWD/monitor.txt - done - sleep 2 -done