Skip to content

Commit

Permalink
Merge branch 'main' into adjust_quote_style_for_yaml_in_localization_…
Browse files Browse the repository at this point in the history
…as_needed
  • Loading branch information
dee0sap committed Jun 3, 2024
2 parents 4512e41 + 2f02322 commit 83c3afd
Show file tree
Hide file tree
Showing 261 changed files with 4,931 additions and 1,729 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/flake_vendorhash.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: "Flake vendorHash Updater"
on:
push:
branches:
- main
paths:
- 'go.mod'
- 'go.sum'
workflow_dispatch:
workflow_call:

jobs:
updateVendorHash:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.OCMBOT_APP_ID }}
private_key: ${{ secrets.OCMBOT_PRIV_KEY }}
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.generate_token.outputs.token }}
- name: Setup git config
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<41898282+github-actions[bot]@users.noreply.github.com>"
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main
- name: Update ocm vendor hash
run: nix run .#nixpkgs.nix-update -- --flake --version=skip ocm
- name: Check diff
id: check-diff
run: |
diff=$(git diff)
if [[ -z "$diff" ]]; then
echo "Everything is tidy."
exit 0
fi
cat << EOF >> "${GITHUB_STEP_SUMMARY}"
\`\`\`diff
${diff}
\`\`\`
EOF
echo "push='true'" >> $GITHUB_ENV
- name: Push changes
if: github.event.pull_request.head.repo.fork == false && env.push == 'true'
run: |
diff=$(git diff)
if [[ ! -z "$diff" ]]; then
git config --global user.name "ocm-vendorhash"
git config --global user.email "[email protected]"
git commit -am "flake: update ocm vendorHash"
git push
fi
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ jobs:
go-version-file: '${{ github.workspace }}/go.mod'

- name: Setup Syft
uses: anchore/sbom-action/download-syft@7ccf588e3cf3cc2611714c2eeae48550fbc17552 # v0.15.11
uses: anchore/sbom-action/download-syft@e8d2a6937ecead383dfe75190d104edd1f9c5751 # v0.16.0

- name: Setup Cosign
uses: sigstore/[email protected]
Expand Down
3 changes: 3 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ linters-settings:
line-length: 120
gosec:
exclude-generated: true
gocritic:
disabled-checks:
- elseif

issues:
exclude:
Expand Down
19 changes: 19 additions & 0 deletions cmds/ocm/commands/controllercmds/common/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package common

import (
"fmt"

"github.com/open-component-model/ocm/pkg/out"
)

func Outf(ctx out.Context, dryRun bool, msg string, args ...any) (int, error) {
if dryRun {
return -1, nil
}

if len(args) == 0 {
return fmt.Fprint(ctx.StdOut(), msg)
}

return fmt.Fprintf(ctx.StdOut(), msg, args...)
}
13 changes: 7 additions & 6 deletions cmds/ocm/commands/controllercmds/common/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"path/filepath"

"github.com/fluxcd/pkg/ssa"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"

"github.com/open-component-model/ocm/pkg/contexts/clictx"
"github.com/open-component-model/ocm/pkg/out"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

func Install(ctx context.Context, octx clictx.Context, sm *ssa.ResourceManager, releaseURL, baseURL, manifest, filename, version string, dryRun bool) error {
Expand All @@ -27,7 +28,7 @@ func Install(ctx context.Context, octx clictx.Context, sm *ssa.ResourceManager,
return fmt.Errorf("✗ failed to apply manifests: %w", err)
}

out.Outf(octx, "► waiting for ocm deployment to be ready\n")
Outf(octx, dryRun, "► waiting for ocm deployment to be ready\n")
if err = sm.Wait(objects, ssa.DefaultWaitOptions()); err != nil {
return fmt.Errorf("✗ failed to wait for objects to be ready: %w", err)
}
Expand All @@ -50,7 +51,7 @@ func Uninstall(ctx context.Context, octx clictx.Context, sm *ssa.ResourceManager
return fmt.Errorf("✗ failed to delete manifests: %w", err)
}

out.Outf(octx, "► waiting for ocm deployment to be deleted\n")
Outf(octx, dryRun, "► waiting for ocm deployment to be deleted\n")
if err = sm.WaitForTermination(objects, ssa.DefaultWaitOptions()); err != nil {
return fmt.Errorf("✗ failed to wait for objects to be deleted: %w", err)
}
Expand All @@ -64,7 +65,7 @@ func fetchObjects(ctx context.Context, octx clictx.Context, releaseURL, baseURL,
if err != nil {
return nil, fmt.Errorf("✗ failed to retrieve latest version for %s: %w", manifest, err)
}
out.Outf(octx, "► got latest version %q\n", latest)
Outf(octx, dryRun, "► got latest version %q\n", latest)
version = latest
} else {
exists, err := existingVersion(ctx, releaseURL, version)
Expand All @@ -90,7 +91,7 @@ func fetchObjects(ctx context.Context, octx clictx.Context, releaseURL, baseURL,
if _, err := os.Stat(path); os.IsNotExist(err) {
return nil, fmt.Errorf("✗ failed to find %s file at location: %w", filename, err)
}
out.Outf(octx, "✔ successfully fetched install file\n")
Outf(octx, dryRun, "✔ successfully fetched install file\n")
if dryRun {
content, err := os.ReadFile(path)
if err != nil {
Expand All @@ -101,7 +102,7 @@ func fetchObjects(ctx context.Context, octx clictx.Context, releaseURL, baseURL,

return nil, nil
}
out.Outf(octx, "► applying to cluster...\n")
Outf(octx, dryRun, "► applying to cluster...\n")

objects, err := ReadObjects(path)
if err != nil {
Expand Down
13 changes: 6 additions & 7 deletions cmds/ocm/commands/controllercmds/install/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/fluxcd/pkg/ssa"
"github.com/open-component-model/ocm/cmds/ocm/commands/controllercmds/common"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
corev1 "k8s.io/api/core/v1"
Expand All @@ -15,11 +14,11 @@ import (
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/open-component-model/ocm/cmds/ocm/commands/controllercmds/common"
"github.com/open-component-model/ocm/cmds/ocm/commands/controllercmds/names"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs"
"github.com/open-component-model/ocm/cmds/ocm/pkg/utils"
"github.com/open-component-model/ocm/pkg/contexts/clictx"
"github.com/open-component-model/ocm/pkg/out"
)

var (
Expand Down Expand Up @@ -97,22 +96,22 @@ func (o *Command) Run() (err error) {

ctx := context.Background()
if !o.SkipPreFlightCheck {
out.Outf(o.Context, "► running pre-install check\n")
common.Outf(o.Context, o.DryRun, "► running pre-install check\n")
if err := o.RunPreFlightCheck(ctx); err != nil {
if o.InstallPrerequisites {
out.Outf(o.Context, "► installing prerequisites\n")
common.Outf(o.Context, o.DryRun, "► installing prerequisites\n")
if err := o.installPrerequisites(ctx); err != nil {
return err
}

out.Outf(o.Context, "✔ successfully installed prerequisites\n")
common.Outf(o.Context, o.DryRun, "✔ successfully installed prerequisites\n")
} else {
return fmt.Errorf("✗ failed to run pre-flight check: %w\n", err)
}
}
}

out.Outf(o.Context, "► installing ocm-controller with version %s\n", o.Version)
common.Outf(o.Context, o.DryRun, "► installing ocm-controller with version %s\n", o.Version)
version := o.Version
if err := common.Install(
ctx,
Expand All @@ -128,7 +127,7 @@ func (o *Command) Run() (err error) {
return err
}

out.Outf(o.Context, "✔ ocm-controller successfully installed\n")
common.Outf(o.Context, o.DryRun, "✔ ocm-controller successfully installed\n")
return nil
}

Expand Down
11 changes: 2 additions & 9 deletions cmds/ocm/commands/controllercmds/install/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,14 @@ var _ = Describe("Test Environment", func() {
It("install latest version", func() {
buf := bytes.NewBuffer(nil)
Expect(env.CatchOutput(buf).Execute("controller", "install", "-d", "-s", "-u", testServer.URL, "-a", testServer.URL)).To(Succeed())
Expect(buf.String()).To(StringEqualTrimmedWithContext(`► installing ocm-controller with version latest
► got latest version "v0.0.1-test"
✔ successfully fetched install file
test: content
✔ ocm-controller successfully installed
Expect(buf.String()).To(StringEqualTrimmedWithContext(`test: content
`))
})

It("install specific version", func() {
buf := bytes.NewBuffer(nil)
Expect(env.CatchOutput(buf).Execute("controller", "install", "-d", "-s", "-u", testServer.URL, "-a", testServer.URL, "-v", "v0.1.0-test-2")).To(Succeed())
Expect(buf.String()).To(StringEqualTrimmedWithContext(`► installing ocm-controller with version v0.1.0-test-2
✔ successfully fetched install file
test: content
✔ ocm-controller successfully installed
Expect(buf.String()).To(StringEqualTrimmedWithContext(`test: content
`))
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,25 @@ import (
"github.com/mandelsoft/filepath/pkg/filepath"

"github.com/open-component-model/ocm/cmds/ocm/commands/controllercmds/common"
"github.com/open-component-model/ocm/pkg/out"
)

//go:embed issuer/registry_certificate.yaml
var issuer []byte

func (o *Command) installPrerequisites(ctx context.Context) error {
out.Outf(o.Context, "► installing cert-manager with version %s\n", o.CertManagerVersion)
common.Outf(o.Context, o.DryRun, "► installing cert-manager with version %s\n", o.CertManagerVersion)

if err := common.Install(ctx, o.Context, o.SM, o.CertManagerReleaseAPIURL, o.CertManagerBaseURL, "cert-manager", "cert-manager.yaml", o.CertManagerVersion, o.DryRun); err != nil {
return err
}

out.Outf(o.Context, "✔ cert-manager successfully installed\n")
common.Outf(o.Context, o.DryRun, "✔ cert-manager successfully installed\n")

if o.DryRun {
return nil
}

out.Outf(o.Context, "► creating certificate for internal registry\n")
common.Outf(o.Context, o.DryRun, "► creating certificate for internal registry\n")

if err := o.createRegistryCertificate(); err != nil {
return fmt.Errorf("✗ failed to create registry certificate: %w", err)
Expand Down
7 changes: 4 additions & 3 deletions cmds/ocm/commands/controllercmds/uninstall/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import (
"time"

"github.com/fluxcd/pkg/ssa"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/cli-runtime/pkg/genericclioptions"

"github.com/open-component-model/ocm/cmds/ocm/commands/controllercmds/common"
"github.com/open-component-model/ocm/cmds/ocm/commands/controllercmds/names"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs"
"github.com/open-component-model/ocm/cmds/ocm/pkg/utils"
"github.com/open-component-model/ocm/pkg/contexts/clictx"
"github.com/open-component-model/ocm/pkg/out"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/cli-runtime/pkg/genericclioptions"
)

var (
Expand Down
5 changes: 2 additions & 3 deletions cmds/ocm/commands/controllercmds/uninstall/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ var _ = Describe("Test Environment", func() {
It("uninstall latest version", func() {
buf := bytes.NewBuffer(nil)
Expect(env.CatchOutput(buf).Execute("controller", "uninstall", "-d", "-u", testServer.URL, "-a", testServer.URL)).To(Succeed())
fmt.Println(buf.String())
Expect(buf.String()).To(StringEqualTrimmedWithContext(`► uninstalling ocm-controller with version latest
► got latest version "v0.0.1-test"
✔ successfully fetched install file
test: content
✔ ocm-controller successfully uninstalled
`))
Expand All @@ -61,8 +60,8 @@ test: content
It("uninstall specific version", func() {
buf := bytes.NewBuffer(nil)
Expect(env.CatchOutput(buf).Execute("controller", "uninstall", "-d", "-u", testServer.URL, "-a", testServer.URL, "-v", "v0.1.0-test-2")).To(Succeed())
fmt.Println(buf.String())
Expect(buf.String()).To(StringEqualTrimmedWithContext(`► uninstalling ocm-controller with version v0.1.0-test-2
✔ successfully fetched install file
test: content
✔ ocm-controller successfully uninstalled
`))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package uninstall

import (
"context"
_ "embed"
"fmt"
"os"

_ "embed"

"github.com/fluxcd/pkg/ssa"
"github.com/mandelsoft/filepath/pkg/filepath"

"github.com/open-component-model/ocm/cmds/ocm/commands/controllercmds/common"
"github.com/open-component-model/ocm/pkg/out"
)
Expand Down
2 changes: 1 addition & 1 deletion cmds/ocm/commands/misccmds/credentials/get/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"strings"

"github.com/mandelsoft/goutils/errors"
"github.com/open-component-model/ocm/pkg/listformat"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

Expand All @@ -15,6 +14,7 @@ import (
"github.com/open-component-model/ocm/cmds/ocm/pkg/utils"
"github.com/open-component-model/ocm/pkg/contexts/clictx"
"github.com/open-component-model/ocm/pkg/contexts/credentials"
"github.com/open-component-model/ocm/pkg/listformat"
"github.com/open-component-model/ocm/pkg/out"
)

Expand Down
3 changes: 2 additions & 1 deletion cmds/ocm/commands/misccmds/hash/sign/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/open-component-model/ocm/cmds/ocm/testhelper"
"github.com/open-component-model/ocm/pkg/contexts/ocm/signing/signingtest"
. "github.com/open-component-model/ocm/pkg/testutils"
)

Expand All @@ -15,7 +16,7 @@ var _ = Describe("Test Environment", func() {
var env *TestEnv

BeforeEach(func() {
env = NewTestEnv(TestData("../../../../../../pkg/contexts/ocm/signing/testdata"))
env = NewTestEnv(signingtest.TestData())
})

AfterEach(func() {
Expand Down
2 changes: 1 addition & 1 deletion cmds/ocm/commands/ocmcmds/common/addhdlrs/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/mandelsoft/goutils/errors"
"github.com/mandelsoft/vfs/pkg/vfs"
"github.com/open-component-model/ocm/pkg/errkind"
"gopkg.in/yaml.v3"
"k8s.io/apimachinery/pkg/util/validation/field"

Expand All @@ -18,6 +17,7 @@ import (
"github.com/open-component-model/ocm/pkg/common/accessio"
"github.com/open-component-model/ocm/pkg/contexts/clictx"
"github.com/open-component-model/ocm/pkg/contexts/ocm"
"github.com/open-component-model/ocm/pkg/errkind"
"github.com/open-component-model/ocm/pkg/runtime"
utils2 "github.com/open-component-model/ocm/pkg/utils"
"github.com/open-component-model/ocm/pkg/utils/template"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strings"

"github.com/mandelsoft/goutils/errors"

"github.com/open-component-model/ocm/cmds/ocm/pkg/output"
"github.com/open-component-model/ocm/cmds/ocm/pkg/utils"
"github.com/open-component-model/ocm/pkg/contexts/clictx"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"sort"

"github.com/Masterminds/semver/v3"

"github.com/mandelsoft/goutils/errors"

"github.com/open-component-model/ocm/cmds/ocm/pkg/output"
"github.com/open-component-model/ocm/cmds/ocm/pkg/utils"
"github.com/open-component-model/ocm/pkg/contexts/clictx"
Expand Down
Loading

0 comments on commit 83c3afd

Please sign in to comment.