Skip to content

Commit d08c753

Browse files
authored
Merge pull request #6 from andrey-parkhomets/custom_namespace
fix: #5
2 parents 3ef2a7f + 9469463 commit d08c753

File tree

16 files changed

+443
-506
lines changed

16 files changed

+443
-506
lines changed

Makefile

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,61 @@
1-
21
export GO111MODULE=on
32

3+
# Build variables
4+
BINARY_NAME=argo-apps-viz
5+
BINARY_PATH=$(HOME)/go/bin/$(BINARY_NAME)
6+
GO_MODULE=argo-apps-viz
7+
GO_FILES=$(shell find . -type f -name '*.go')
8+
9+
# Version information
10+
VERSION=$(shell git describe --tags --always --dirty)
11+
COMMIT=$(shell git rev-parse --short HEAD)
12+
BUILD_TIME=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
13+
14+
# Go build flags
15+
LDFLAGS=-ldflags "-X main.Version=$(VERSION) -X main.Commit=$(COMMIT) -X main.BuildTime=$(BUILD_TIME)"
16+
17+
.PHONY: all
18+
all: clean test build
19+
20+
.PHONY: build
21+
build: fmt vet
22+
go build $(LDFLAGS) -o $(BINARY_PATH) $(GO_MODULE)/cmd/plugin
23+
424
.PHONY: test
525
test:
6-
go test ./pkg/... ./cmd/... -coverprofile cover.out
7-
8-
.PHONY: bin
9-
bin: fmt vet
10-
go build -o bin/argo-apps-viz github.com/syndlex/argo-apps-viz/cmd/plugin
26+
go test -v -race -cover ./pkg/... ./cmd/... -coverprofile cover.out
27+
go tool cover -html=cover.out -o coverage.html
1128

1229
.PHONY: fmt
1330
fmt:
1431
go fmt ./pkg/... ./cmd/...
1532

1633
.PHONY: vet
1734
vet:
18-
go vet ./pkg/... ./cmd/...
35+
@echo "Running go vet..."
36+
@go vet ./pkg/... ./cmd/... || (echo "Go vet failed. Please fix the issues above."; exit 1)
37+
38+
.PHONY: lint
39+
lint:
40+
@if ! command -v golangci-lint &> /dev/null; then \
41+
echo "Installing golangci-lint..."; \
42+
brew install golangci-lint; \
43+
fi
44+
golangci-lint run
45+
46+
.PHONY: clean
47+
clean:
48+
rm -rf bin/ cover.out coverage.html
49+
50+
51+
.PHONY: help
52+
help:
53+
@echo "Available targets:"
54+
@echo " all - Clean, run tests, and build"
55+
@echo " build - Build the binary"
56+
@echo " test - Run tests with coverage"
57+
@echo " fmt - Format code"
58+
@echo " vet - Run go vet"
59+
@echo " lint - Run golangci-lint"
60+
@echo " clean - Clean build artifacts"
61+

cmd/plugin/cli/argo-aoa.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package cli
33
import (
44
"context"
55
_ "embed"
6-
"github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned/typed/application/v1alpha1"
6+
7+
"argo-apps-viz/pkg/logger"
8+
"argo-apps-viz/pkg/model/appsofapps"
9+
10+
"github.com/argoproj/argo-cd/v3/pkg/client/clientset/versioned/typed/application/v1alpha1"
711
"github.com/go-echarts/go-echarts/v2/components"
812
"github.com/spf13/cobra"
913
"github.com/spf13/pflag"
10-
"github.com/syndlex/argo-apps-viz/pkg/logger"
11-
"github.com/syndlex/argo-apps-viz/pkg/model/appsofapps"
1214
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1315
)
1416

@@ -66,15 +68,22 @@ func runAoa(flags *pflag.FlagSet) (components.Charter, error) {
6668
log.Error(err)
6769
return nil, err
6870
}
71+
72+
// Get namespace from flags
73+
namespace, err := flags.GetString("namespace")
74+
if err != nil {
75+
namespace = "argocd" // fallback to default
76+
}
77+
6978
var ctx = context.Background()
70-
applicationList, err := argoclient.Applications("argocd").List(ctx, v1.ListOptions{})
79+
applicationList, err := argoclient.Applications(namespace).List(ctx, v1.ListOptions{})
7180
if err != nil {
7281
log.Info("Problem while getting ArgoCd domains")
7382
log.Error(err)
7483
return nil, err
7584
}
7685

77-
applicationSetList, err := argoclient.ApplicationSets("argocd").List(ctx, v1.ListOptions{})
86+
applicationSetList, err := argoclient.ApplicationSets(namespace).List(ctx, v1.ListOptions{})
7887
if err != nil {
7988
log.Info("Problem while getting ArgoCd domains")
8089
log.Error(err)
@@ -94,7 +103,7 @@ func runAoa(flags *pflag.FlagSet) (components.Charter, error) {
94103
if len(starts) != 0 {
95104
log.Info("Using applications as starting points of graph:")
96105
for i, start := range starts {
97-
log.Info(" %v, %v", i, start)
106+
log.Info(" %d, %s", i, start)
98107
}
99108
}
100109
stops, err := flags.GetStringArray("stop")
@@ -105,7 +114,7 @@ func runAoa(flags *pflag.FlagSet) (components.Charter, error) {
105114
if len(stops) != 0 {
106115
log.Info("Using applications as stopping points of graph:")
107116
for i, stop := range stops {
108-
log.Info(" %v, %v", i, stop)
117+
log.Info(" %d, %s", i, stop)
109118
}
110119
}
111120

cmd/plugin/cli/graph-deps.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package cli
33
import (
44
"context"
55
"fmt"
6-
"github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned/typed/application/v1alpha1"
6+
7+
"argo-apps-viz/pkg/logger"
8+
"argo-apps-viz/pkg/model/dependencies"
9+
10+
"github.com/argoproj/argo-cd/v3/pkg/client/clientset/versioned/typed/application/v1alpha1"
711
"github.com/go-echarts/go-echarts/v2/charts"
812
"github.com/spf13/cobra"
9-
"github.com/syndlex/argo-apps-viz/pkg/logger"
10-
"github.com/syndlex/argo-apps-viz/pkg/model/dependencies"
1113
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1214
)
1315

@@ -30,7 +32,7 @@ var graphdepsCmd = &cobra.Command{
3032
if err != nil {
3133
return err
3234
}
33-
logger.Info("Finished look in: " + dependenciesFile)
35+
logger.Info("Finished look in: %s", dependenciesFile)
3436
return err
3537
},
3638
}
@@ -58,14 +60,21 @@ func runPlugin() (*charts.Tree, error) {
5860
if err != nil {
5961
return nil, err
6062
}
63+
64+
// Get namespace from flags
65+
namespace := rootCmd.Flags().Lookup("namespace").Value.String()
66+
if namespace == "" {
67+
namespace = "argocd" // fallback to default
68+
}
69+
6170
var ctx = context.Background()
62-
applicationList, err := argoclient.Applications("argocd").List(ctx, v1.ListOptions{})
71+
applicationList, err := argoclient.Applications(namespace).List(ctx, v1.ListOptions{})
6372
if err != nil {
6473
fmt.Println("Problem while getting ArgoCD domains")
6574
return nil, err
6675
}
6776

68-
applicationSetList, err := argoclient.ApplicationSets("argocd").List(ctx, v1.ListOptions{})
77+
applicationSetList, err := argoclient.ApplicationSets(namespace).List(ctx, v1.ListOptions{})
6978
if err != nil {
7079
fmt.Println("Problem while getting ArgoCd domains")
7180
return nil, err

cmd/plugin/cli/root.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package cli
22

33
import (
44
"fmt"
5+
"os"
6+
"strings"
7+
58
"github.com/spf13/cobra"
69
"github.com/spf13/viper"
710
"k8s.io/cli-runtime/pkg/genericclioptions"
8-
"os"
9-
"strings"
1011
)
1112

1213
var (
@@ -27,12 +28,14 @@ var (
2728
)
2829

2930
func RootCmd() *cobra.Command {
30-
3131
cobra.OnInitialize(initConfig)
3232

3333
KubernetesConfigFlags = genericclioptions.NewConfigFlags(false)
3434
KubernetesConfigFlags.AddFlags(rootCmd.Flags())
3535

36+
// Add namespace flag with default value
37+
rootCmd.PersistentFlags().String("namespace", "argocd", "ArgoCD namespace (default: argocd)")
38+
3639
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
3740
return rootCmd
3841
}

cmd/plugin/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package main
22

33
import (
4-
"github.com/syndlex/argo-apps-viz/cmd/plugin/cli"
5-
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp" // required for GKE
4+
"argo-apps-viz/cmd/plugin/cli" // Updated import path
5+
6+
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
67
)
78

89
func main() {

0 commit comments

Comments
 (0)