diff --git a/.github/actions/setup-go/action.yaml b/.github/actions/setup-go/action.yaml index fdb423ce..e287e42f 100644 --- a/.github/actions/setup-go/action.yaml +++ b/.github/actions/setup-go/action.yaml @@ -4,28 +4,8 @@ runs: using: "composite" steps: - name: Install go - uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 + uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 with: - go-version: "1.25" go-version-file: "go.mod" cache: true cache-dependency-path: go.sum - - id: go-cache-paths - shell: bash - run: | - echo "::set-output name=go-build::$(go env GOCACHE)" - echo "::set-output name=go-mod::$(go env GOMODCACHE)" - - name: Go Mod Cache - uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4 - with: - path: ${{ steps.go-cache-paths.outputs.go-mod }} - key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go-mod- - - name: Go Build Cache - uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4 - with: - path: ${{ steps.go-cache-paths.outputs.go-build }} - key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go-build- diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1b30251a..d05cdfa3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,7 +28,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: fetch-depth: 0 - uses: ./.github/actions/setup-go @@ -65,7 +65,7 @@ jobs: # Load Golang cache build from GitHub - name: Load cso Golang cache build from GitHub - uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 id: cache with: path: /tmp/.cache/cso diff --git a/.github/workflows/kubebuilder-markers-checker.yml b/.github/workflows/kubebuilder-markers-checker.yml index 0239b71b..ef331b02 100644 --- a/.github/workflows/kubebuilder-markers-checker.yml +++ b/.github/workflows/kubebuilder-markers-checker.yml @@ -16,7 +16,7 @@ jobs: name: check for kubebuilder markers runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4 + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 # go is required for building controller-gen - uses: ./.github/actions/setup-go diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml index e62fbc02..4a309927 100644 --- a/.github/workflows/pr-lint.yml +++ b/.github/workflows/pr-lint.yml @@ -27,7 +27,7 @@ jobs: password: ${{ secrets.github_token }} steps: - name: Checkout repository - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: ref: ${{ github.event.pull_request.head.sha }} diff --git a/.github/workflows/pr-verify.yml b/.github/workflows/pr-verify.yml index 0b6d3284..5964ac3b 100644 --- a/.github/workflows/pr-verify.yml +++ b/.github/workflows/pr-verify.yml @@ -9,14 +9,31 @@ jobs: name: Verify Pull Request if: github.event_name != 'pull_request' || !github.event.pull_request.draft steps: - - name: Verifier action - id: verifier - uses: kubernetes-sigs/kubebuilder-release-tools@012269a88fa4c034a0acf1ba84c26b195c0dbab4 # v0.4.3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} + - name: Validate PR Title Format + env: + TITLE: ${{ github.event.pull_request.title }} + run: | + if [[ -z "$TITLE" ]]; then + echo "Error: PR title cannot be empty." + exit 1 + fi + + if ! [[ "$TITLE" =~ ^($'\u26A0'|$'\u2728'|$'\U0001F41B'|$'\U0001F4D6'|$'\U0001F680'|$'\U0001F331') ]]; then + echo "Error: Invalid PR title format." + echo "Your PR title must start with one of the following indicators:" + echo "- Breaking change: ⚠ (U+26A0)" + echo "- Non-breaking feature: ✨ (U+2728)" + echo "- Patch fix: 🐛 (U+1F41B)" + echo "- Docs: 📖 (U+1F4D6)" + echo "- Release: 🚀 (U+1F680)" + echo "- Infra/Tests/Other: 🌱 (U+1F331)" + exit 1 + fi + + echo "PR title is valid: '$TITLE'" - name: Checkout repository - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: ref: ${{ github.event.pull_request.head.sha }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fea7bc43..cafd5fa7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: fetch-depth: 0 - uses: ./.github/actions/setup-go @@ -135,7 +135,7 @@ jobs: run: echo "RELEASE_TAG=${GITHUB_REF:10}" >> $GITHUB_ENV - name: checkout code - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: fetch-depth: 0 diff --git a/.github/workflows/schedule-cache-cleaner-cso-image.yml b/.github/workflows/schedule-cache-cleaner-cso-image.yml index fed5b5b3..c86f067e 100644 --- a/.github/workflows/schedule-cache-cleaner-cso-image.yml +++ b/.github/workflows/schedule-cache-cleaner-cso-image.yml @@ -15,7 +15,7 @@ jobs: steps: # Load Golang cache build from GitHub - name: Load cso Golang cache build from GitHub - uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 id: cache with: path: /tmp/.cache/cso diff --git a/.github/workflows/schedule-scan-image.yml b/.github/workflows/schedule-scan-image.yml index 386428ac..54862874 100644 --- a/.github/workflows/schedule-scan-image.yml +++ b/.github/workflows/schedule-scan-image.yml @@ -15,7 +15,7 @@ jobs: password: ${{ secrets.github_token }} steps: - name: Checkout repository - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Fixup git permissions # https://github.com/actions/checkout/issues/766 shell: bash diff --git a/.github/workflows/schedule-update-bot.yaml b/.github/workflows/schedule-update-bot.yaml index 6f4c4ec9..0cbca4d7 100644 --- a/.github/workflows/schedule-update-bot.yaml +++ b/.github/workflows/schedule-update-bot.yaml @@ -30,7 +30,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Generate Token uses: actions/create-github-app-token@67018539274d69449ef7c02e8e71183d1719ab42 # v2 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a43eb5fe..ed72dab5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,7 +30,7 @@ jobs: timeout-minutes: 10 steps: - name: Checkout repository - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Coverage result name id: name run: | diff --git a/internal/clusterstackrelease/util.go b/internal/clusterstackrelease/util.go index 99ffd1c1..e89e12a1 100644 --- a/internal/clusterstackrelease/util.go +++ b/internal/clusterstackrelease/util.go @@ -55,6 +55,7 @@ func Summary(csr *csov1alpha1.ClusterStackRelease) (csov1alpha1.ClusterStackRele summary.Phase = csov1alpha1.ClusterStackReleasePhaseProviderSpecificWork case conditions.IsFalse(csr, csov1alpha1.ClusterStackReleaseAssetsReadyCondition): summary.Phase = csov1alpha1.ClusterStackReleasePhaseDownloadingAssets + default: } return summary, nil diff --git a/internal/controller/clusteraddon_controller.go b/internal/controller/clusteraddon_controller.go index e31b66c3..6b447106 100644 --- a/internal/controller/clusteraddon_controller.go +++ b/internal/controller/clusteraddon_controller.go @@ -529,7 +529,7 @@ func (r *ClusterAddonReconciler) getNewReleaseObjects(ctx context.Context, in *t } } - helmTemplate, err := helmTemplateClusterAddon(filepath.Join(in.newDestinationClusterAddonChartDir, stage.Name), newBuildTemplate, in.kubernetesVersion) + helmTemplate, err := helmTemplateClusterAddon(ctx, filepath.Join(in.newDestinationClusterAddonChartDir, stage.Name), newBuildTemplate, in.kubernetesVersion) if err != nil { return nil, fmt.Errorf("failed to template new helm chart of the latest cluster stack: %w", err) } @@ -568,7 +568,7 @@ func (r *ClusterAddonReconciler) getOldReleaseObjects(ctx context.Context, in *t return nil, fmt.Errorf("failed to build template from the old cluster stack cluster addon values: %w", err) } - helmTemplate, err := helmTemplateClusterAddon(oldRelease.ClusterAddonChartPath(), buildTemplate, oldRelease.Meta.Versions.Kubernetes) + helmTemplate, err := helmTemplateClusterAddon(ctx, oldRelease.ClusterAddonChartPath(), buildTemplate, oldRelease.Meta.Versions.Kubernetes) if err != nil { return nil, fmt.Errorf("failed to template helm chart: %w", err) } @@ -605,7 +605,7 @@ func (r *ClusterAddonReconciler) getOldReleaseObjects(ctx context.Context, in *t } } - helmTemplate, err := helmTemplateClusterAddon(filepath.Join(in.oldDestinationClusterAddonChartDir, stage.Name), newBuildTemplate, oldRelease.Meta.Versions.Kubernetes) + helmTemplate, err := helmTemplateClusterAddon(ctx, filepath.Join(in.oldDestinationClusterAddonChartDir, stage.Name), newBuildTemplate, oldRelease.Meta.Versions.Kubernetes) if err != nil { return nil, fmt.Errorf("failed to template new helm chart: %w", err) } @@ -746,7 +746,7 @@ func (r *ClusterAddonReconciler) templateAndApplyClusterAddonHelmChart(ctx conte return false, fmt.Errorf("failed to build template from cluster addon values: %w", err) } - helmTemplate, err := helmTemplateClusterAddon(clusterAddonChart, buildTemplate, in.kubernetesVersion) + helmTemplate, err := helmTemplateClusterAddon(ctx, clusterAddonChart, buildTemplate, in.kubernetesVersion) if err != nil { return false, fmt.Errorf("failed to template helm chart: %w", err) } @@ -863,7 +863,7 @@ check: } // Delete part logger.V(1).Info("starting to template helm chart", "clusterStack", in.clusterAddon.Spec.ClusterStack, "name", stage.Name, "hook", in.clusterAddon.Spec.Hook) - helmTemplate, err := helmTemplateNewClusterStack(in, stage.Name) + helmTemplate, err := helmTemplateNewClusterStack(ctx, in, stage.Name) if err != nil { conditions.MarkFalse( in.clusterAddon, @@ -931,6 +931,7 @@ check: } in.clusterAddon.SetStagePhase(stage.Name, stage.Action, csov1alpha1.StagePhaseDone) + default: } return false, nil @@ -1038,7 +1039,7 @@ func (r *ClusterAddonReconciler) templateNewClusterStackAddonHelmChart(ctx conte return true, nil, nil, nil } - oldHelmTemplate, err = helmTemplateClusterAddon(oldClusterStackSubDirPath, oldBuildTemplate, in.oldKubernetesVersion) + oldHelmTemplate, err = helmTemplateClusterAddon(ctx, oldClusterStackSubDirPath, oldBuildTemplate, in.oldKubernetesVersion) if err != nil { conditions.MarkFalse( in.clusterAddon, @@ -1082,7 +1083,7 @@ func (r *ClusterAddonReconciler) templateNewClusterStackAddonHelmChart(ctx conte } } - newHelmTemplate, err = helmTemplateClusterAddon(newClusterStackSubDirPath, newBuildTemplate, in.kubernetesVersion) + newHelmTemplate, err = helmTemplateClusterAddon(ctx, newClusterStackSubDirPath, newBuildTemplate, in.kubernetesVersion) if err != nil { conditions.MarkFalse( in.clusterAddon, @@ -1105,11 +1106,11 @@ func (r *ClusterAddonReconciler) templateNewClusterStackAddonHelmChart(ctx conte return false, oldHelmTemplate, newHelmTemplate, nil } -func helmTemplateNewClusterStack(in *templateAndApplyClusterAddonInput, name string) (newTemplate []byte, err error) { +func helmTemplateNewClusterStack(ctx context.Context, in *templateAndApplyClusterAddonInput, name string) (newTemplate []byte, err error) { var buildTemplate []byte newClusterStackSubDirPath := filepath.Join(in.newDestinationClusterAddonChartDir, name) - newHelmTemplate, err := helmTemplateClusterAddon(newClusterStackSubDirPath, buildTemplate, in.kubernetesVersion) + newHelmTemplate, err := helmTemplateClusterAddon(ctx, newClusterStackSubDirPath, buildTemplate, in.kubernetesVersion) if err != nil { return nil, fmt.Errorf("failed to template new helm chart: %w", err) } @@ -1252,7 +1253,7 @@ func buildTemplateFromClusterAddonValues(ctx context.Context, addonValuePath str // Then it returns the path of the generated yaml file. // Example: helm template /tmp/downloads/cluster-stacks/myprovider-myclusterstack-1-26-v2/myprovider-myclusterstack-1-26-v2.tgz // The return yaml file path will be /tmp/downloads/cluster-stacks/myprovider-myclusterstack-1-26-v2/myprovider-myclusterstack-1-26-v2.tgz.yaml. -func helmTemplateClusterAddon(chartPath string, helmTemplate []byte, kubernetesVersion string) ([]byte, error) { +func helmTemplateClusterAddon(ctx context.Context, chartPath string, helmTemplate []byte, kubernetesVersion string) ([]byte, error) { helmCommand := "helm" helmArgs := []string{"template", "--include-crds", "--dependency-update"} @@ -1261,7 +1262,7 @@ func helmTemplateClusterAddon(chartPath string, helmTemplate []byte, kubernetesV var cmdOutput bytes.Buffer helmArgs = append(helmArgs, "--kube-version", kubernetesVersion, "cluster-addon", filepath.Base(chartPath), "--namespace", clusterAddonNamespace, "-f", "-") - helmTemplateCmd := exec.Command(helmCommand, helmArgs...) + helmTemplateCmd := exec.CommandContext(ctx, helmCommand, helmArgs...) helmTemplateCmd.Stderr = os.Stderr helmTemplateCmd.Dir = filepath.Dir(chartPath) helmTemplateCmd.Stdout = &cmdOutput diff --git a/internal/controller/clusterstackrelease_controller.go b/internal/controller/clusterstackrelease_controller.go index 107a6e5f..c6ffe9af 100644 --- a/internal/controller/clusterstackrelease_controller.go +++ b/internal/controller/clusterstackrelease_controller.go @@ -224,7 +224,7 @@ func (r *ClusterStackReleaseReconciler) reconcileDelete(ctx context.Context, rel } } - template, err := r.templateClusterClassHelmChart(releaseAssets, clusterStackReleaseCR.Name, clusterStackReleaseCR.Namespace) + template, err := r.templateClusterClassHelmChart(ctx, releaseAssets, clusterStackReleaseCR.Name, clusterStackReleaseCR.Namespace) if err != nil { return reconcile.Result{}, fmt.Errorf("failed to perform helm template: %w", err) } @@ -297,7 +297,7 @@ func (r *ClusterStackReleaseReconciler) updateProviderClusterStackRelease(ctx co func (r *ClusterStackReleaseReconciler) templateAndApply(ctx context.Context, releaseAssets *release.Release, clusterStackRelease *csov1alpha1.ClusterStackRelease, kubeClient kube.Client) (bool, error) { // template helm chart and apply objects - template, err := r.templateClusterClassHelmChart(releaseAssets, clusterStackRelease.Name, clusterStackRelease.Namespace) + template, err := r.templateClusterClassHelmChart(ctx, releaseAssets, clusterStackRelease.Name, clusterStackRelease.Namespace) if err != nil { return false, fmt.Errorf("failed to template clusterClass helm chart: %w", err) } @@ -318,7 +318,7 @@ func (r *ClusterStackReleaseReconciler) templateAndApply(ctx context.Context, re } // templateClusterClassHelmChart templates the clusterClass helm chart. -func (*ClusterStackReleaseReconciler) templateClusterClassHelmChart(releaseAssets *release.Release, name, namespace string) ([]byte, error) { +func (*ClusterStackReleaseReconciler) templateClusterClassHelmChart(ctx context.Context, releaseAssets *release.Release, name, namespace string) ([]byte, error) { clusterClassChart, e := releaseAssets.ClusterClassChartPath() if e != nil { return nil, fmt.Errorf("failed to template clusterClass helm chart: %w", e) @@ -327,7 +327,7 @@ func (*ClusterStackReleaseReconciler) templateClusterClassHelmChart(releaseAsset splittedName := strings.Split(name, clusterstack.Separator) releaseName := strings.Join(splittedName[0:4], clusterstack.Separator) - template, err := helmTemplate(clusterClassChart, releaseName, namespace) + template, err := helmTemplate(ctx, clusterClassChart, releaseName, namespace) if err != nil { return nil, fmt.Errorf("failed to template clusterClass helm chart: %w", err) } @@ -335,14 +335,14 @@ func (*ClusterStackReleaseReconciler) templateClusterClassHelmChart(releaseAsset return template, nil } -func helmTemplate(chartPath, releaseName, namespace string) ([]byte, error) { +func helmTemplate(ctx context.Context, chartPath, releaseName, namespace string) ([]byte, error) { helmCommand := "helm" helmArgs := []string{"template"} var cmdOutput bytes.Buffer helmArgs = append(helmArgs, releaseName, filepath.Base(chartPath), "--namespace", namespace) - helmTemplateCmd := exec.Command(helmCommand, helmArgs...) + helmTemplateCmd := exec.CommandContext(ctx, helmCommand, helmArgs...) helmTemplateCmd.Stderr = os.Stderr helmTemplateCmd.Dir = filepath.Dir(chartPath) helmTemplateCmd.Stdout = &cmdOutput diff --git a/internal/test/helpers/webhook.go b/internal/test/helpers/webhook.go index 35f84b2c..ee2bdc32 100644 --- a/internal/test/helpers/webhook.go +++ b/internal/test/helpers/webhook.go @@ -17,6 +17,7 @@ limitations under the License. package helpers import ( + "context" "fmt" "net" "os" @@ -113,7 +114,8 @@ func (*TestEnvironment) WaitForWebhooks() { timeout := 1 * time.Second for { time.Sleep(1 * time.Second) - conn, err := net.DialTimeout("tcp", net.JoinHostPort("127.0.0.1", strconv.Itoa(port)), timeout) + dialer := &net.Dialer{Timeout: timeout} + conn, err := dialer.DialContext(context.Background(), "tcp", net.JoinHostPort("127.0.0.1", strconv.Itoa(port))) if err != nil { klog.V(2).Infof("Webhook port is not ready, will retry in %v: %s", timeout, err) continue diff --git a/pkg/kube/helpers.go b/pkg/kube/helpers.go index c9fa762b..dc2a7c3b 100644 --- a/pkg/kube/helpers.go +++ b/pkg/kube/helpers.go @@ -172,7 +172,9 @@ func setLabel(target *unstructured.Unstructured, key, val string) error { return fmt.Errorf("error setting labels on .spec.selector for apps/extensions group: %w", err) } } + default: } + default: } case "batch": if gvk.Kind == JobKind { diff --git a/pkg/version/version.go b/pkg/version/version.go index 4e05d1ad..de048c22 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -193,18 +193,17 @@ func (csv Version) Compare(input Version) (int, error) { return 1, nil case csv.Major < input.Major: return -1, nil - case csv.Major == input.Major: + default: switch { case csv.Patch > input.Patch: return 1, nil case csv.Patch < input.Patch: return -1, nil - case csv.Patch == input.Patch: + default: return 0, nil } } - return 0, nil } // String converts a Version struct to a string representation.