Skip to content

Commit

Permalink
chore: separate goods package (#1731)
Browse files Browse the repository at this point in the history
* chore: separate goods package

* f

* f

* f

* f

* f

* f

* Trigger Build
  • Loading branch information
emosbaugh authored Jan 23, 2025
1 parent e84003d commit 4e008d4
Show file tree
Hide file tree
Showing 34 changed files with 223 additions and 255 deletions.
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
bundle
pkg/goods/bins/*
!pkg/goods/bins/.placeholder
pkg/goods/internal/bins/*
!pkg/goods/internal/bins/.placeholder
pkg/goods/images
cmd/installer/goods/bins/*
!cmd/installer/goods/bins/.placeholder
cmd/installer/goods/internal/bins/*
!cmd/installer/goods/internal/bins/.placeholder
cmd/installer/goods/images
.pre-commit-config.yaml
vendor
e2e/kots-release-install/license.yaml
Expand Down
86 changes: 43 additions & 43 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ default: build-ttl.sh
split-hyphen = $(word $2,$(subst -, ,$1))
random-string = $(shell LC_ALL=C tr -dc 'A-Za-z0-9' < /dev/urandom | head -c6)

.PHONY: pkg/goods/bins/k0s
pkg/goods/bins/k0s:
.PHONY: cmd/installer/goods/bins/k0s
cmd/installer/goods/bins/k0s:
$(MAKE) output/bins/k0s-$(K0S_VERSION)-$(ARCH)
mkdir -p pkg/goods/bins
mkdir -p cmd/installer/goods/bins
cp output/bins/k0s-$(K0S_VERSION)-$(ARCH) $@

output/bins/k0s-%:
Expand All @@ -85,10 +85,10 @@ output/bins/k0s-%:
chmod +x $@
touch $@

.PHONY: pkg/goods/bins/kubectl-support_bundle
pkg/goods/bins/kubectl-support_bundle:
.PHONY: cmd/installer/goods/bins/kubectl-support_bundle
cmd/installer/goods/bins/kubectl-support_bundle:
$(MAKE) output/bins/kubectl-support_bundle-$(TROUBLESHOOT_VERSION)-$(ARCH)
mkdir -p pkg/goods/bins
mkdir -p cmd/installer/goods/bins
cp output/bins/kubectl-support_bundle-$(TROUBLESHOOT_VERSION)-$(ARCH) $@

output/bins/kubectl-support_bundle-%:
Expand All @@ -100,10 +100,10 @@ output/bins/kubectl-support_bundle-%:
rm -rf output/tmp
touch $@

.PHONY: pkg/goods/bins/kubectl-preflight
pkg/goods/bins/kubectl-preflight:
.PHONY: cmd/installer/goods/bins/kubectl-preflight
cmd/installer/goods/bins/kubectl-preflight:
$(MAKE) output/bins/kubectl-preflight-$(TROUBLESHOOT_VERSION)-$(ARCH)
mkdir -p pkg/goods/bins
mkdir -p cmd/installer/goods/bins
cp output/bins/kubectl-preflight-$(TROUBLESHOOT_VERSION)-$(ARCH) $@

output/bins/kubectl-preflight-%:
Expand All @@ -115,9 +115,9 @@ output/bins/kubectl-preflight-%:
rm -rf output/tmp
touch $@

.PHONY: pkg/goods/bins/local-artifact-mirror
pkg/goods/bins/local-artifact-mirror:
mkdir -p pkg/goods/bins
.PHONY: cmd/installer/goods/bins/local-artifact-mirror
cmd/installer/goods/bins/local-artifact-mirror:
mkdir -p cmd/installer/goods/bins
$(MAKE) -C local-artifact-mirror build OS=$(OS) ARCH=$(ARCH)
cp local-artifact-mirror/bin/local-artifact-mirror-$(OS)-$(ARCH) $@
touch $@
Expand All @@ -134,24 +134,24 @@ output/bins/fio-%:
docker rm -f fio
touch $@

.PHONY: pkg/goods/bins/fio
pkg/goods/bins/fio:
.PHONY: cmd/installer/goods/bins/fio
cmd/installer/goods/bins/fio:
ifneq ($(DISABLE_FIO_BUILD),1)
$(MAKE) output/bins/fio-$(FIO_VERSION)-$(ARCH)
mkdir -p pkg/goods/bins
mkdir -p cmd/installer/goods/bins
cp output/bins/fio-$(FIO_VERSION)-$(ARCH) $@
endif

.PHONY: pkg/goods/bins/manager
pkg/goods/bins/manager:
mkdir -p pkg/goods/bins
.PHONY: cmd/installer/goods/bins/manager
cmd/installer/goods/bins/manager:
mkdir -p cmd/installer/goods/bins
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -ldflags="-s -w $(LD_FLAGS) -extldflags=-static" -o output/bins/manager ./cmd/manager
cp output/bins/manager $@
touch $@

.PHONY: pkg/goods/internal/bins/kubectl-kots
pkg/goods/internal/bins/kubectl-kots:
mkdir -p pkg/goods/internal/bins
.PHONY: cmd/installer/goods/internal/bins/kubectl-kots
cmd/installer/goods/internal/bins/kubectl-kots:
mkdir -p cmd/installer/goods/internal/bins
if [ "$(KOTS_BINARY_URL_OVERRIDE)" != "" ]; then \
$(MAKE) output/bins/kubectl-kots-override ; \
cp output/bins/kubectl-kots-override $@ ; \
Expand Down Expand Up @@ -218,24 +218,24 @@ go.mod: Makefile
go mod tidy

.PHONY: static
static: pkg/goods/bins/k0s \
pkg/goods/bins/kubectl-preflight \
pkg/goods/bins/kubectl-support_bundle \
pkg/goods/bins/local-artifact-mirror \
pkg/goods/bins/fio \
pkg/goods/bins/manager \
pkg/goods/internal/bins/kubectl-kots
static: cmd/installer/goods/bins/k0s \
cmd/installer/goods/bins/kubectl-preflight \
cmd/installer/goods/bins/kubectl-support_bundle \
cmd/installer/goods/bins/local-artifact-mirror \
cmd/installer/goods/bins/fio \
cmd/installer/goods/bins/manager \
cmd/installer/goods/internal/bins/kubectl-kots

.PHONY: static-dryrun
static-dryrun:
@mkdir -p pkg/goods/bins pkg/goods/internal/bins
@touch pkg/goods/bins/k0s \
pkg/goods/bins/kubectl-preflight \
pkg/goods/bins/kubectl-support_bundle \
pkg/goods/bins/local-artifact-mirror \
pkg/goods/bins/fio \
pkg/goods/bins/manager \
pkg/goods/internal/bins/kubectl-kots
@mkdir -p cmd/installer/goods/bins cmd/installer/goods/internal/bins
@touch cmd/installer/goods/bins/k0s \
cmd/installer/goods/bins/kubectl-preflight \
cmd/installer/goods/bins/kubectl-support_bundle \
cmd/installer/goods/bins/local-artifact-mirror \
cmd/installer/goods/bins/fio \
cmd/installer/goods/bins/manager \
cmd/installer/goods/internal/bins/kubectl-kots

.PHONY: embedded-cluster-linux-amd64
embedded-cluster-linux-amd64: export OS = linux
Expand Down Expand Up @@ -272,8 +272,8 @@ envtest:

.PHONY: unit-tests
unit-tests: envtest
mkdir -p pkg/goods/bins pkg/goods/internal/bins
touch pkg/goods/bins/BUILD pkg/goods/internal/bins/BUILD # compilation will fail if no files are present
mkdir -p cmd/installer/goods/bins cmd/installer/goods/internal/bins
touch cmd/installer/goods/bins/BUILD cmd/installer/goods/internal/bins/BUILD # compilation will fail if no files are present
KUBEBUILDER_ASSETS="$(shell ./operator/bin/setup-envtest use $(ENVTEST_K8S_VERSION) --bin-dir $(shell pwd)/operator/bin -p path)" \
go test -tags exclude_graphdriver_btrfs -v ./pkg/... ./cmd/...
$(MAKE) -C operator test
Expand Down Expand Up @@ -305,8 +305,8 @@ build-ttl.sh:
.PHONY: clean
clean:
rm -rf output
rm -rf pkg/goods/bins/*
rm -rf pkg/goods/internal/bins/*
rm -rf cmd/installer/goods/bins/*
rm -rf cmd/installer/goods/internal/bins/*
rm -rf build
rm -rf bin

Expand All @@ -329,8 +329,8 @@ scan:

.PHONY: buildtools
buildtools:
mkdir -p pkg/goods/bins pkg/goods/internal/bins
touch pkg/goods/bins/BUILD pkg/goods/internal/bins/BUILD # compilation will fail if no files are present
mkdir -p cmd/installer/goods/bins cmd/installer/goods/internal/bins
touch cmd/installer/goods/bins/BUILD cmd/installer/goods/internal/bins/BUILD # compilation will fail if no files are present
go build -tags exclude_graphdriver_btrfs -o ./output/bin/buildtools ./cmd/buildtools

.PHONY: list-distros
Expand Down Expand Up @@ -373,7 +373,7 @@ delete-node%:
@dev/scripts/down.sh $*

.PHONY: test-lam-e2e
test-lam-e2e: pkg/goods/bins/local-artifact-mirror
test-lam-e2e: cmd/installer/goods/bins/local-artifact-mirror
sudo go test ./cmd/local-artifact-mirror/e2e/... -v

.PHONY: bin/installer
Expand Down
2 changes: 1 addition & 1 deletion cmd/installer/cli/adminconsole_resetpassword.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"

"github.com/replicatedhq/embedded-cluster/pkg/kotscli"
"github.com/replicatedhq/embedded-cluster/cmd/installer/kotscli"
rcutil "github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig/util"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down
2 changes: 1 addition & 1 deletion cmd/installer/cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

k0sconfig "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
"github.com/replicatedhq/embedded-cluster/cmd/installer/goods"
eckinds "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
"github.com/replicatedhq/embedded-cluster/kinds/types"
Expand All @@ -21,7 +22,6 @@ import (
"github.com/replicatedhq/embedded-cluster/pkg/config"
"github.com/replicatedhq/embedded-cluster/pkg/configutils"
"github.com/replicatedhq/embedded-cluster/pkg/dryrun"
"github.com/replicatedhq/embedded-cluster/pkg/goods"
"github.com/replicatedhq/embedded-cluster/pkg/helpers"
"github.com/replicatedhq/embedded-cluster/pkg/helpers/systemd"
"github.com/replicatedhq/embedded-cluster/pkg/k0s"
Expand Down
15 changes: 13 additions & 2 deletions cmd/installer/cli/install2.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (

k0sconfig "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
k0sv1beta1 "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
"github.com/replicatedhq/embedded-cluster/cmd/installer/kotscli"
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
"github.com/replicatedhq/embedded-cluster/pkg/addons2"
"github.com/replicatedhq/embedded-cluster/pkg/configutils"
"github.com/replicatedhq/embedded-cluster/pkg/extensions"
"github.com/replicatedhq/embedded-cluster/pkg/helpers"
"github.com/replicatedhq/embedded-cluster/pkg/k0s"
"github.com/replicatedhq/embedded-cluster/pkg/kotscli"
"github.com/replicatedhq/embedded-cluster/pkg/kubeutils"
"github.com/replicatedhq/embedded-cluster/pkg/metrics"
"github.com/replicatedhq/embedded-cluster/pkg/netutils"
Expand All @@ -24,6 +24,7 @@ import (
"github.com/replicatedhq/embedded-cluster/pkg/release"
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
"github.com/replicatedhq/embedded-cluster/pkg/spinner"
"github.com/replicatedhq/embedded-cluster/pkg/support"
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -250,6 +251,16 @@ func runInstall2(cmd *cobra.Command, args []string, name string, flags Install2C
ConfigValuesFile: flags.configValues,
ServiceCIDR: flags.cidrCfg.ServiceCIDR,
DisasterRecoveryEnabled: disasterRecoveryEnabled,
KotsInstaller: func(msg *spinner.MessageWriter) error {
opts := kotscli.InstallOptions{
AppSlug: flags.license.Spec.AppSlug,
LicenseFile: flags.licenseFile,
Namespace: runtimeconfig.KotsadmNamespace,
AirgapBundle: flags.airgapBundle,
ConfigValuesFile: flags.configValues,
}
return kotscli.Install(opts, msg)
},
}); err != nil {
metrics.ReportApplyFinished(cmd.Context(), "", flags.license, err)
return err
Expand All @@ -267,7 +278,7 @@ func runInstall2(cmd *cobra.Command, args []string, name string, flags Install2C
return err
}

if err = kotscli.CreateHostSupportBundle(); err != nil {
if err = support.CreateHostSupportBundle(); err != nil {
logrus.Warnf("unable to create host support bundle: %v", err)
}

Expand Down
15 changes: 13 additions & 2 deletions cmd/installer/cli/install_runpreflights.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (
"strings"
"time"

"github.com/replicatedhq/embedded-cluster/cmd/installer/goods"
"github.com/replicatedhq/embedded-cluster/cmd/installer/kotscli"
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
"github.com/replicatedhq/embedded-cluster/pkg/addons"
"github.com/replicatedhq/embedded-cluster/pkg/airgap"
"github.com/replicatedhq/embedded-cluster/pkg/configutils"
"github.com/replicatedhq/embedded-cluster/pkg/dryrun"
"github.com/replicatedhq/embedded-cluster/pkg/goods"
"github.com/replicatedhq/embedded-cluster/pkg/helpers"
"github.com/replicatedhq/embedded-cluster/pkg/metrics"
"github.com/replicatedhq/embedded-cluster/pkg/preflights"
Expand Down Expand Up @@ -279,7 +280,17 @@ func getAddonsApplier(cmd *cobra.Command, opts addonsApplierOpts, adminConsolePw
}

addonOpts = append(addonOpts, addons.WithLicense(license))
addonOpts = append(addonOpts, addons.WithLicenseFile(opts.license))

addonOpts = append(addonOpts, addons.WithKotsInstaller(func(msg *spinner.MessageWriter) error {
opts := kotscli.InstallOptions{
AppSlug: license.Spec.AppSlug,
LicenseFile: opts.license,
Namespace: runtimeconfig.KotsadmNamespace,
AirgapBundle: opts.airgapBundle,
ConfigValuesFile: opts.configValues,
}
return kotscli.Install(opts, msg)
}))
}

if opts.airgapBundle != "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/installer/cli/materialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"os"

"github.com/replicatedhq/embedded-cluster/cmd/installer/goods"
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
"github.com/replicatedhq/embedded-cluster/pkg/goods"
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
"github.com/spf13/cobra"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/installer/cli/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
k0sv1beta1 "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
"github.com/replicatedhq/embedded-cluster/cmd/installer/kotscli"
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
"github.com/replicatedhq/embedded-cluster/pkg/addons"
"github.com/replicatedhq/embedded-cluster/pkg/addons/adminconsole"
Expand All @@ -28,7 +29,6 @@ import (
"github.com/replicatedhq/embedded-cluster/pkg/disasterrecovery"
"github.com/replicatedhq/embedded-cluster/pkg/helpers"
"github.com/replicatedhq/embedded-cluster/pkg/k0s"
"github.com/replicatedhq/embedded-cluster/pkg/kotscli"
"github.com/replicatedhq/embedded-cluster/pkg/kubeutils"
"github.com/replicatedhq/embedded-cluster/pkg/netutils"
"github.com/replicatedhq/embedded-cluster/pkg/prompts"
Expand Down
2 changes: 1 addition & 1 deletion cmd/installer/cli/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"

"github.com/replicatedhq/embedded-cluster/pkg/kotscli"
"github.com/replicatedhq/embedded-cluster/cmd/installer/kotscli"
"github.com/replicatedhq/embedded-cluster/pkg/release"
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
rcutil "github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig/util"
Expand Down
File renamed without changes.
File renamed without changes.
20 changes: 0 additions & 20 deletions pkg/goods/goods.go → cmd/installer/goods/goods.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/hex"
"fmt"
"io"
"strings"
)

var (
Expand Down Expand Up @@ -37,22 +36,3 @@ func K0sBinarySHA256() (string, error) {
}
return hex.EncodeToString(hasher.Sum(nil)), nil
}

func GetSupportBundleSpec(name string) ([]byte, error) {
entries, err := supportfs.ReadDir("support")
if err != nil {
return nil, fmt.Errorf("unable to read embedded-cluster support dir: %w", err)
}
for _, entry := range entries {
srcpath := fmt.Sprintf("support/%s", entry.Name())
if !strings.Contains(entry.Name(), name) {
continue
}
srcfile, err := supportfs.ReadFile(srcpath)
if err != nil {
return nil, fmt.Errorf("unable to read asset: %w", err)
}
return srcfile, nil
}
return nil, fmt.Errorf("unable to find support file %s", name)
}
File renamed without changes.
Loading

0 comments on commit 4e008d4

Please sign in to comment.