Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/r3labs/diff/v3 v3.0.1
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
github.com/shirou/gopsutil/v3 v3.24.5
github.com/sighupio/fury-distribution v1.29.4
github.com/sighupio/fury-distribution v1.30.0-rc.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,8 @@ github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU=
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
github.com/sighupio/fury-distribution v1.29.4 h1:AA/GSBUYQx0/NobWBTxiZveoPNPCiy4G1PkJmd+kOCo=
github.com/sighupio/fury-distribution v1.29.4/go.mod h1:iYBnl0N/6zGPz3j3L2X6nzFC3nzNQtIkAzmaPfnO0zA=
github.com/sighupio/fury-distribution v1.30.0-rc.0 h1:yCTviS/9JwkFg59L8Q13EofvvNGm+h7n1L+6sPavkxA=
github.com/sighupio/fury-distribution v1.30.0-rc.0/go.mod h1:iYBnl0N/6zGPz3j3L2X6nzFC3nzNQtIkAzmaPfnO0zA=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
Expand Down
4 changes: 2 additions & 2 deletions internal/apis/kfd/v1alpha2/ekscluster/common/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ func (d *Distribution) injectDataPreTf(fMerger *merge.Merger) (*merge.Merger, er
Data: private.SpecDistribution{
Modules: private.SpecDistributionModules{
Ingress: private.SpecDistributionModulesIngress{
Dns: private.SpecDistributionModulesIngressDNS{
Private: private.SpecDistributionModulesIngressDNSPrivate{
Dns: &private.SpecDistributionModulesIngressDNS{
Private: &private.SpecDistributionModulesIngressDNSPrivate{
VpcId: vpcID,
},
},
Expand Down
4 changes: 4 additions & 0 deletions internal/cluster/phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ type OperationPhase struct {
YqPath string
HelmPath string
HelmfilePath string
KappPath string
TerraformPlanPath string
TerraformLogsPath string
TerraformOutputsPath string
Expand All @@ -181,6 +182,7 @@ func NewOperationPhase(folder string, kfdTools config.KFDTools, binPath string)
yqPath := path.Join(binPath, "yq", kfdTools.Common.Yq.Version, "yq")
helmPath := path.Join(binPath, "helm", kfdTools.Common.Helm.Version, "helm")
helmfilePath := path.Join(binPath, "helmfile", kfdTools.Common.Helmfile.Version, "helmfile")
kappPath := path.Join(binPath, "kapp", kfdTools.Common.Kapp.Version, "kapp")

planPath := path.Join(basePath, "terraform", "plan")
logsPath := path.Join(basePath, "terraform", "logs")
Expand All @@ -200,6 +202,7 @@ func NewOperationPhase(folder string, kfdTools config.KFDTools, binPath string)
YqPath: yqPath,
HelmPath: helmPath,
HelmfilePath: helmfilePath,
KappPath: kappPath,
}
}

Expand Down Expand Up @@ -300,6 +303,7 @@ func (op *OperationPhase) CopyPathsToConfig(cfg *template.Config) {
"terraform": op.TerraformPath,
"vendorPath": path.Join(op.Path, "..", "vendor"),
"yq": op.YqPath,
"kapp": op.KappPath,
}
}

Expand Down
74 changes: 74 additions & 0 deletions internal/dependencies/tools/kapp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (c) 2017-present SIGHUP s.r.l All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package tools

import (
"fmt"
"path/filepath"
"regexp"
"runtime"
"strings"

"github.com/sighupio/furyctl/internal/semver"
"github.com/sighupio/furyctl/internal/tool/kapp"
iox "github.com/sighupio/furyctl/internal/x/io"
)

func NewKapp(runner *kapp.Runner, version string) *Kapp {
return &Kapp{
arch: runtime.GOARCH,
os: runtime.GOOS,
version: version,
checker: &checker{
regex: regexp.MustCompile("kapp version " + semver.Regex),
runner: runner,
splitFn: func(version string) []string {
return strings.Split(version, " ")
},
trimFn: func(tokens []string) string {
return tokens[len(tokens)-1]
},
},
}
}

type Kapp struct {
arch string
checker *checker
os string
version string
}

func (*Kapp) SupportsDownload() bool {
return true
}

func (k *Kapp) SrcPath() string {
return fmt.Sprintf(
"https://github.com/carvel-dev/kapp/releases/download/%s/kapp-%s-%s",
semver.EnsurePrefix(k.version),
k.os,
k.arch,
)
}

func (k *Kapp) Rename(basePath string) error {
oldPath := filepath.Join(basePath, fmt.Sprintf("kapp-%s-%s", k.os, k.arch))
newPath := filepath.Join(basePath, "kapp")

if err := iox.CopyFile(oldPath, newPath); err != nil {
return fmt.Errorf("error while renaming kapp: %w", err)
}

return nil
}

func (k *Kapp) CheckBinVersion() error {
if err := k.checker.version(k.version); err != nil {
return fmt.Errorf("kapp: %w", err)
}

return nil
}
137 changes: 137 additions & 0 deletions internal/dependencies/tools/kapp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// Copyright (c) 2017-present SIGHUP s.r.l All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build unit

package tools_test

import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"testing"

"github.com/sighupio/furyctl/internal/dependencies/tools"
"github.com/sighupio/furyctl/internal/tool/kapp"
execx "github.com/sighupio/furyctl/internal/x/exec"
)

func Test_Kapp_SupportsDownload(t *testing.T) {
a := tools.NewKapp(newKappRunner(), "3.5.3")

if a.SupportsDownload() != true {
t.Errorf("kapp download must be supported")
}
}

func Test_Kapp_SrcPath(t *testing.T) {
wantSrcPath := fmt.Sprintf(
"https://github.com/carvel-dev/kapp/releases/download/v3.5.3/kapp-%s-%s",
runtime.GOOS,
runtime.GOARCH,
)

testCases := []struct {
desc string
version string
}{
{
desc: "3.5.3",
version: "3.5.3",
},
{
desc: "v3.5.3",
version: "v3.5.3",
},
}
for _, tC := range testCases {
t.Run(tC.desc, func(t *testing.T) {
fa := tools.NewKapp(newKappRunner(), tC.version)
if fa.SrcPath() != wantSrcPath {
t.Errorf("Wrong kapp src path: want = %s, got = %s", wantSrcPath, fa.SrcPath())
}
})
}
}

func Test_Kapp_Rename(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "furyctl-test-")
if err != nil {
t.Fatalf("error creating temp dir: %v", err)
}

binaryName := fmt.Sprintf("kapp-%s-%s", runtime.GOOS, runtime.GOARCH)

if _, err := os.Create(filepath.Join(tmpDir, binaryName)); err != nil {
t.Fatalf("error creating temp file: %v", err)
}

fa := tools.NewKapp(newKappRunner(), "3.5.3")

if err := fa.Rename(tmpDir); err != nil {
t.Fatalf("Error renaming kapp binary: %v", err)
}

info, err := os.Stat(filepath.Join(tmpDir, "kapp"))
if err != nil {
t.Fatalf("Error stating kapp binary: %v", err)
}

if info.IsDir() {
t.Errorf("kapp binary is a directory")
}
}

func Test_Kapp_CheckBinVersion(t *testing.T) {
t.Parallel()

testCases := []struct {
desc string
wantVersion string
wantErrMsg string
wantErr bool
}{
{
desc: "correct version installed",
wantVersion: "0.62.0",
},
{
desc: "wrong version installed",
wantVersion: "3.5.3",
wantErr: true,
wantErrMsg: "installed = 0.62.0, expected = 3.5.3",
},
}
for _, tC := range testCases {
tC := tC

t.Run(tC.desc, func(t *testing.T) {
t.Parallel()

fa := tools.NewKapp(newKappRunner(), tC.wantVersion)

err := fa.CheckBinVersion()

if tC.wantErr && err == nil {
t.Errorf("expected error, got nil")
}

if !tC.wantErr && err != nil {
t.Errorf("expected no error, got %v", err)
}

if tC.wantErr && err != nil && !strings.Contains(err.Error(), tC.wantErrMsg) {
t.Errorf("expected error message '%s' to contain '%s'", err.Error(), tC.wantErrMsg)
}
})
}
}

func newKappRunner() *kapp.Runner {
return kapp.NewRunner(execx.NewFakeExecutor("TestHelperProcess"), kapp.Paths{
Kapp: "kapp",
}, false)
}
7 changes: 7 additions & 0 deletions internal/dependencies/tools/test_data/kapp/0.61.0/kapp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

cat <<EOF
kapp version 0.61.0

Succeeded
EOF
7 changes: 7 additions & 0 deletions internal/dependencies/tools/test_data/kapp/0.62.0/kapp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

cat <<EOF
kapp version 0.62.0

Succeeded
EOF
9 changes: 9 additions & 0 deletions internal/dependencies/tools/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/sighupio/furyctl/internal/tool/git"
"github.com/sighupio/furyctl/internal/tool/helm"
"github.com/sighupio/furyctl/internal/tool/helmfile"
"github.com/sighupio/furyctl/internal/tool/kapp"
"github.com/sighupio/furyctl/internal/tool/kubectl"
"github.com/sighupio/furyctl/internal/tool/kustomize"
"github.com/sighupio/furyctl/internal/tool/openvpn"
Expand Down Expand Up @@ -173,6 +174,14 @@ func (f *Factory) Create(name tool.Name, version string) Tool {

return NewHelmfile(hfr, version)

case tool.Kapp:
ka, ok := t.(*kapp.Runner)
if !ok {
panic(fmt.Sprintf("expected kapp.Runner, got %T", t))
}

return NewKapp(ka, version)

default:
return nil
}
Expand Down
11 changes: 11 additions & 0 deletions internal/dependencies/tools/tool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func Test_Factory_Create(t *testing.T) {
desc: "kubectl",
wantTool: true,
},
{
desc: "kapp",
wantTool: true,
},
{
desc: "kustomize",
wantTool: true,
Expand Down Expand Up @@ -175,6 +179,13 @@ func TestHelperProcess(t *testing.T) {
case "version":
fmt.Fprintf(os.Stdout, "v0.156.0")
}
case "kapp":
switch subcmd {
case "version":
fmt.Fprintf(os.Stdout, "kapp version 0.62.0\n"+
"\n"+
"Succeeded\n")
}
default:
fmt.Fprintf(os.Stdout, "command not found")
}
Expand Down
4 changes: 4 additions & 0 deletions internal/dependencies/tools/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func (tv *Validator) validateTools(i any, kfdManifest config.KFD) ([]string, []e
continue
}

if (toolName == "kapp") && !distribution.HasFeature(kfdManifest, distribution.FeatureKappSupport) {
continue
}

tool := tv.toolFactory.Create(itool.Name(toolName), toolCfg.Version)
if err := tool.CheckBinVersion(); err != nil {
errs = append(errs, err)
Expand Down
Loading