Skip to content

Commit

Permalink
Remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
MacroPower committed Jan 3, 2025
1 parent 6e38b77 commit 0e1f55b
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 248 deletions.
20 changes: 0 additions & 20 deletions pkg/argoutil/config/reader.go

This file was deleted.

62 changes: 12 additions & 50 deletions pkg/argoutil/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ package exec

import (
"bytes"
"crypto/rand"
"encoding/hex"
"errors"
"fmt"
"log/slog"
"os"
"os/exec"
"runtime"
"strings"
"syscall"
"time"

"github.com/MacroPower/kclx/pkg/argoutil/rand"
)

var (
Expand Down Expand Up @@ -81,10 +79,19 @@ func Redact(items []string) func(text string) string {
}
}

// randString returns a cryptographically-secure pseudo-random alpha-numeric string of a given length
func randString(n int) (string, error) {
bytes := make([]byte, n/2+1) // we need one extra letter to discard
if _, err := rand.Read(bytes); err != nil {
return "", err
}
return hex.EncodeToString(bytes)[0:n], nil
}

// RunCommandExt is a convenience function to run/log a command and return/log stderr in an error upon
// failure.
func RunCommandExt(cmd *exec.Cmd, opts CmdOpts) (string, error) {
execId, err := rand.RandString(5)
execId, err := randString(5)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -172,48 +179,3 @@ func RunCommandExt(cmd *exec.Cmd, opts CmdOpts) (string, error) {
func RunCommand(name string, opts CmdOpts, arg ...string) (string, error) {
return RunCommandExt(exec.Command(name, arg...), opts)
}

// WaitPIDOpts are options to WaitPID
type WaitPIDOpts struct {
PollInterval time.Duration
Timeout time.Duration
}

// WaitPID waits for a non-child process id to exit
func WaitPID(pid int, opts ...WaitPIDOpts) error {
if runtime.GOOS != "linux" {
return fmt.Errorf("platform '%s' unsupported", runtime.GOOS)
}
var timeout time.Duration
pollInterval := time.Second
if len(opts) > 0 {
if opts[0].PollInterval != 0 {
pollInterval = opts[0].PollInterval
}
if opts[0].Timeout != 0 {
timeout = opts[0].Timeout
}
}
path := fmt.Sprintf("/proc/%d", pid)

ticker := time.NewTicker(pollInterval)
defer ticker.Stop()
var timoutCh <-chan time.Time
if timeout != 0 {
timoutCh = time.NewTimer(timeout).C
}
for {
select {
case <-ticker.C:
_, err := os.Stat(path)
if err != nil {
if os.IsNotExist(err) {
return nil
}
return err
}
case <-timoutCh:
return ErrWaitPIDTimeout
}
}
}
1 change: 0 additions & 1 deletion pkg/argoutil/executil/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"unicode"

argoexec "github.com/MacroPower/kclx/pkg/argoutil/exec"

"github.com/MacroPower/kclx/pkg/argoutil/log"
"github.com/MacroPower/kclx/pkg/tracing"
)
Expand Down
34 changes: 0 additions & 34 deletions pkg/argoutil/helm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ type Creds struct {
InsecureSkipVerify bool
}

type indexCache interface {
SetHelmIndex(repo string, indexData []byte) error
GetHelmIndex(repo string, indexData *[]byte) error
}

type Client interface {
CleanChartCache(chart string, version string, project string) error
ExtractChart(chart string, version string, project string, passCredentials bool, manifestMaxExtractedSize int64, disableManifestMaxExtractedSize bool) (string, argoio.Closer, error)
Expand All @@ -61,12 +56,6 @@ type Client interface {

type ClientOpts func(c *nativeHelmChart)

func WithIndexCache(indexCache indexCache) ClientOpts {
return func(c *nativeHelmChart) {
c.indexCache = indexCache
}
}

func WithChartPaths(chartPaths argoio.TempPaths) ClientOpts {
return func(c *nativeHelmChart) {
c.chartCachePaths = chartPaths
Expand Down Expand Up @@ -101,7 +90,6 @@ type nativeHelmChart struct {
creds Creds
repoLock sync.KeyLock
enableOci bool
indexCache indexCache
proxy string
noProxy string
}
Expand Down Expand Up @@ -237,11 +225,6 @@ func (c *nativeHelmChart) GetIndex(noCache bool, maxIndexSize int64) (*Index, er
defer indexLock.Unlock(c.repoURL)

var data []byte
// if !noCache && c.indexCache != nil {
// if err := c.indexCache.GetHelmIndex(c.repoURL, &data); err != nil && !errors.Is(err, cache.ErrCacheMiss) {
// log.Warnf("Failed to load index cache for repo: %s: %v", c.repoURL, err)
// }
// }

if len(data) == 0 {
start := time.Now()
Expand All @@ -251,12 +234,6 @@ func (c *nativeHelmChart) GetIndex(noCache bool, maxIndexSize int64) (*Index, er
return nil, fmt.Errorf("error loading repo index: %w", err)
}
slog.Info("got index data", "seconds", time.Since(start).Seconds())

// if c.indexCache != nil {
// if err := c.indexCache.SetHelmIndex(c.repoURL, data); err != nil {
// log.Warnf("Failed to store index cache for repo: %s: %v", c.repoURL, err)
// }
// }
}

index := &Index{}
Expand Down Expand Up @@ -415,11 +392,6 @@ func (c *nativeHelmChart) GetTags(chart string, noCache bool) (*TagsList, error)
defer indexLock.Unlock(tagsURL)

var data []byte
// if !noCache && c.indexCache != nil {
// if err := c.indexCache.GetHelmIndex(tagsURL, &data); err != nil && !errors.Is(err, cache.ErrCacheMiss) {
// log.Warnf("Failed to load index cache for repo: %s: %v", tagsURL, err)
// }
// }

tags := &TagsList{}
if len(data) == 0 {
Expand Down Expand Up @@ -462,12 +434,6 @@ func (c *nativeHelmChart) GetTags(chart string, noCache bool) (*TagsList, error)
return nil, fmt.Errorf("failed to get tags: %w", err)
}
slog.Info("got tags", "seconds", time.Since(start).Seconds(), "chart", chart, "repo", c.repoURL)

// if c.indexCache != nil {
// if err := c.indexCache.SetHelmIndex(tagsURL, data); err != nil {
// log.Warnf("Failed to store tags list cache for repo: %s: %v", tagsURL, err)
// }
// }
} else {
err := json.Unmarshal(data, tags)
if err != nil {
Expand Down
19 changes: 17 additions & 2 deletions pkg/argoutil/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package helm
import (
"errors"
"fmt"
"io"
"log/slog"
"net/http"
"net/url"
"os"
"os/exec"
Expand All @@ -12,7 +14,6 @@ import (

"sigs.k8s.io/yaml"

"github.com/MacroPower/kclx/pkg/argoutil/config"
"github.com/MacroPower/kclx/pkg/argoutil/executil"
pathutil "github.com/MacroPower/kclx/pkg/argoutil/io/path"
)
Expand Down Expand Up @@ -148,7 +149,7 @@ func (h *helm) GetParameters(valuesFiles []pathutil.ResolvedFilePath, appPath, r
var fileValues []byte
parsedURL, err := url.ParseRequestURI(file)
if err == nil && (parsedURL.Scheme == "http" || parsedURL.Scheme == "https") {
fileValues, err = config.ReadRemoteFile(file)
fileValues, err = readRemoteFile(file)
} else {
_, fileReadErr := os.Stat(file)
if os.IsNotExist(fileReadErr) {
Expand Down Expand Up @@ -194,3 +195,17 @@ func flatVals(input interface{}, output map[string]string, prefixes ...string) {
output[strings.Join(prefixes, ".")] = fmt.Sprintf("%v", i)
}
}

// readRemoteFile issues a GET request to retrieve the contents of the specified URL as a byte array.
// The caller is responsible for checking error return values.
func readRemoteFile(url string) ([]byte, error) {
var data []byte
resp, err := http.Get(url)
if err == nil {
defer func() {
_ = resp.Body.Close()
}()
data, err = io.ReadAll(resp.Body)
}
return data, err
}
38 changes: 0 additions & 38 deletions pkg/argoutil/io/bytereadseeker.go

This file was deleted.

72 changes: 0 additions & 72 deletions pkg/argoutil/io/bytereadseeker_test.go

This file was deleted.

15 changes: 0 additions & 15 deletions pkg/argoutil/rand/rand.go

This file was deleted.

16 changes: 0 additions & 16 deletions pkg/argoutil/rand/rand_test.go

This file was deleted.

0 comments on commit 0e1f55b

Please sign in to comment.