Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: kubernetes #36

Merged
merged 2 commits into from
Oct 26, 2024
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
7 changes: 6 additions & 1 deletion pkg/commands/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path/filepath"
"runtime"
"strings"
"time"

"github.com/apex/log"
"github.com/urfave/cli/v2"
Expand All @@ -16,6 +17,8 @@ import (
)

func Execute(c *cli.Context) error {
start := time.Now().UTC()

cfg, err := config.New(c.String("config"))
if err != nil {
return err
Expand Down Expand Up @@ -61,7 +64,9 @@ func Execute(c *cli.Context) error {
return err
}

log.Infof("installation complete")
elapsed := time.Since(start)

log.Infof("installation complete in %s", elapsed)

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/source/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (s *GitHub) Run(ctx context.Context) error {
}

// sourceRun - run the source specific logic
func (s *GitHub) sourceRun(ctx context.Context) error {
func (s *GitHub) sourceRun(ctx context.Context) error { //nolint:dupl
cacheFile := filepath.Join(s.Options.Config.GetMetadataPath(), fmt.Sprintf("cache-%s", s.GetID()))

s.client = github.NewClient(httpcache.NewTransport(diskcache.New(cacheFile)).Client())
Expand Down
29 changes: 28 additions & 1 deletion pkg/source/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import (
"fmt"
"path/filepath"

"github.com/apex/log"
"github.com/google/go-github/v66/github"
"github.com/gregjones/httpcache"
"github.com/gregjones/httpcache/diskcache"

"github.com/ekristen/distillery/pkg/asset"
)

Expand All @@ -26,7 +31,7 @@ func (s *Kubernetes) GetRepo() string {
return s.Repo
}
func (s *Kubernetes) GetApp() string {
return fmt.Sprintf("%s/%s", s.Owner, s.Repo)
return fmt.Sprintf("%s/%s", s.Owner, s.AppName)
}
func (s *Kubernetes) GetID() string {
return fmt.Sprintf("%s-%s", s.GetSource(), s.GetRepo())
Expand All @@ -36,6 +41,28 @@ func (s *Kubernetes) GetDownloadsDir() string {
return filepath.Join(s.Options.Config.GetDownloadsPath(), s.GetSource(), s.GetOwner(), s.GetRepo(), s.Version)
}

// sourceRun - run the source specific logic (note this is duplicate because of the GetReleaseAssets override)
func (s *Kubernetes) sourceRun(ctx context.Context) error { //nolint:dupl
cacheFile := filepath.Join(s.Options.Config.GetMetadataPath(), fmt.Sprintf("cache-%s", s.GetID()))

s.client = github.NewClient(httpcache.NewTransport(diskcache.New(cacheFile)).Client())
githubToken := s.Options.Settings["github-token"].(string)
if githubToken != "" {
log.Debug("auth token provided")
s.client = s.client.WithAuthToken(githubToken)
}

if err := s.FindRelease(ctx); err != nil {
return err
}

if err := s.GetReleaseAssets(ctx); err != nil {
return err
}

return nil
}

func (s *Kubernetes) GetReleaseAssets(_ context.Context) error {
binName := fmt.Sprintf("%s-%s-%s-%s", s.AppName, s.Version, s.GetOS(), s.GetArch())
s.Assets = append(s.Assets, &KubernetesAsset{
Expand Down