Skip to content

Commit

Permalink
Move references for kube, image, registry to registry-scanner (#998)
Browse files Browse the repository at this point in the history
Signed-off-by: Ishita Sequeira <[email protected]>
  • Loading branch information
ishitasequeira authored Jan 7, 2025
1 parent 9a20452 commit 1a998b1
Show file tree
Hide file tree
Showing 46 changed files with 248 additions and 5,892 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type ImageUpdaterConfig struct {
CheckInterval time.Duration
ArgoClient argocd.ArgoCD
LogLevel string
KubeClient *kube.KubernetesClient
KubeClient *kube.ImageUpdaterKubernetesClient
MaxConcurrency int
HealthPort int
MetricsPort int
Expand Down
4 changes: 2 additions & 2 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
"github.com/argoproj-labs/argocd-image-updater/pkg/common"
"github.com/argoproj-labs/argocd-image-updater/pkg/health"
"github.com/argoproj-labs/argocd-image-updater/pkg/metrics"
"github.com/argoproj-labs/argocd-image-updater/pkg/registry"
"github.com/argoproj-labs/argocd-image-updater/pkg/version"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/env"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/log"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/registry"

"github.com/argoproj/argo-cd/v2/reposerver/askpass"

Expand Down Expand Up @@ -115,7 +115,7 @@ func newRunCommand() *cobra.Command {
log.Fatalf("could not create K8s client: %v", err)
}
if cfg.ClientOpts.ServerAddr == "" {
cfg.ClientOpts.ServerAddr = fmt.Sprintf("argocd-server.%s", cfg.KubeClient.Namespace)
cfg.ClientOpts.ServerAddr = fmt.Sprintf("argocd-server.%s", cfg.KubeClient.KubeClient.Namespace)
}
}
if cfg.ClientOpts.ServerAddr == "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/argoproj-labs/argocd-image-updater/pkg/argocd"
"github.com/argoproj-labs/argocd-image-updater/pkg/common"
"github.com/argoproj-labs/argocd-image-updater/pkg/image"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/image"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/tag"

"github.com/spf13/cobra"
Expand Down
10 changes: 5 additions & 5 deletions cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"fmt"
"runtime"

"github.com/argoproj-labs/argocd-image-updater/pkg/image"
"github.com/argoproj-labs/argocd-image-updater/pkg/kube"
"github.com/argoproj-labs/argocd-image-updater/pkg/registry"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/image"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/log"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/options"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/registry"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -64,7 +64,7 @@ argocd-image-updater test nginx --allow-tags '^1.19.\d+(\-.*)*$' --update-strate
log.Fatalf("could not set log level to %s: %v", logLevel, err)
}

var kubeClient *kube.KubernetesClient
var kubeClient *kube.ImageUpdaterKubernetesClient
var err error
if !disableKubernetes {
ctx := context.Background()
Expand Down Expand Up @@ -118,7 +118,7 @@ argocd-image-updater test nginx --allow-tags '^1.19.\d+(\-.*)*$' --update-strate
logCtx.Fatalf("could not get registry endpoint: %v", err)
}

if err := ep.SetEndpointCredentials(kubeClient); err != nil {
if err := ep.SetEndpointCredentials(kubeClient.KubeClient); err != nil {
logCtx.Fatalf("could not set registry credentials: %v", err)
}

Expand All @@ -138,7 +138,7 @@ argocd-image-updater test nginx --allow-tags '^1.19.\d+(\-.*)*$' --update-strate
if err != nil {
logCtx.Fatalf("could not parse credential definition '%s': %v", credentials, err)
}
creds, err = credSrc.FetchCredentials(ep.RegistryAPI, kubeClient)
creds, err = credSrc.FetchCredentials(ep.RegistryAPI, kubeClient.KubeClient)
if err != nil {
logCtx.Fatalf("could not fetch credentials: %v", err)
}
Expand Down
10 changes: 7 additions & 3 deletions cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/argoproj-labs/argocd-image-updater/pkg/kube"
registryKube "github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/kube"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/log"
)

Expand All @@ -26,9 +27,9 @@ func getPrintableHealthPort(port int) string {
}
}

func getKubeConfig(ctx context.Context, namespace string, kubeConfig string) (*kube.KubernetesClient, error) {
func getKubeConfig(ctx context.Context, namespace string, kubeConfig string) (*kube.ImageUpdaterKubernetesClient, error) {
var fullKubeConfigPath string
var kubeClient *kube.KubernetesClient
var kubeClient *kube.ImageUpdaterKubernetesClient
var err error

if kubeConfig != "" {
Expand All @@ -44,10 +45,13 @@ func getKubeConfig(ctx context.Context, namespace string, kubeConfig string) (*k
log.Debugf("Creating in-cluster Kubernetes client")
}

kubeClient, err = kube.NewKubernetesClientFromConfig(ctx, namespace, fullKubeConfigPath)
kubernetesClient, err := registryKube.NewKubernetesClientFromConfig(ctx, namespace, fullKubeConfigPath)
if err != nil {
return nil, err
}
kubeClient = &kube.ImageUpdaterKubernetesClient{
KubeClient: kubernetesClient,
}

return kubeClient, nil
}
2 changes: 1 addition & 1 deletion cmd/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestGetKubeConfig(t *testing.T) {
} else {
require.NoError(t, err)
assert.NotNil(t, client)
assert.Equal(t, tt.expectedNS, client.Namespace)
assert.Equal(t, tt.expectedNS, client.KubeClient.Namespace)
}
})
}
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ go 1.22.0
toolchain go1.23.0

require (
github.com/Masterminds/semver/v3 v3.3.1
github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20241218013735-14e60b8a83a4
github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20250106213822-5ae9a451b57d
github.com/argoproj/argo-cd/v2 v2.13.1
github.com/argoproj/gitops-engine v0.7.1-0.20240905010810-bd7681ae3f8b
github.com/argoproj/pkg v0.13.7-0.20230627120311-a4dd357b057e
Expand All @@ -15,8 +14,6 @@ require (
github.com/distribution/distribution/v3 v3.0.0-20230722181636-7b502560cad4
github.com/go-git/go-git/v5 v5.13.0
github.com/google/uuid v1.6.0
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/prometheus/client_golang v1.20.5
github.com/sirupsen/logrus v1.9.3
Expand All @@ -42,6 +39,7 @@ require (
dario.cat/mergo v1.0.1 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/Masterminds/semver/v3 v3.3.1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v1.1.3 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
Expand Down Expand Up @@ -115,6 +113,8 @@ require (
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ github.com/alicebob/miniredis/v2 v2.33.0/go.mod h1:MhP4a3EU7aENRi9aO+tHfTBZicLqQ
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20241218013735-14e60b8a83a4 h1:B6z7t09pdODcT4dJ2Rndata6+OFZOWjYlOXynyexFNc=
github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20241218013735-14e60b8a83a4/go.mod h1:GJD+hNHt9KbYFo1+OddD3vvqys7ct5ZIOx5yHFCBAXg=
github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20250106213822-5ae9a451b57d h1:Ut4/EiaiTDeuchus+bgq3pYu5nIgqMwpBI3+2Znw/VA=
github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20250106213822-5ae9a451b57d/go.mod h1:GJD+hNHt9KbYFo1+OddD3vvqys7ct5ZIOx5yHFCBAXg=
github.com/argoproj/argo-cd/v2 v2.13.1 h1:qoa8LD5suPCAYtoDNHp+BuqODf46hl5gCuXNj2oiAy0=
github.com/argoproj/argo-cd/v2 v2.13.1/go.mod h1:RC23V2744nhZstZVpLCWTQLT2gR0+IXGC3GTBCI6M+I=
github.com/argoproj/gitops-engine v0.7.1-0.20240905010810-bd7681ae3f8b h1:wOPWJ5MBScQO767WpU55oUJDXObfvPL0EfAYWxogbSw=
Expand Down
6 changes: 3 additions & 3 deletions pkg/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"time"

"github.com/argoproj-labs/argocd-image-updater/pkg/common"
"github.com/argoproj-labs/argocd-image-updater/pkg/image"
"github.com/argoproj-labs/argocd-image-updater/pkg/kube"
"github.com/argoproj-labs/argocd-image-updater/pkg/metrics"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/env"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/image"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/log"

argocdclient "github.com/argoproj/argo-cd/v2/pkg/apiclient"
Expand All @@ -24,7 +24,7 @@ import (

// Kubernetes based client
type k8sClient struct {
kubeClient *kube.KubernetesClient
kubeClient *kube.ImageUpdaterKubernetesClient
}

// GetApplication retrieves an application by name across all namespaces.
Expand Down Expand Up @@ -99,7 +99,7 @@ func (client *k8sClient) UpdateSpec(ctx context.Context, spec *application.Appli
}

// NewK8SClient creates a new kubernetes client to interact with kubernetes api-server.
func NewK8SClient(kubeClient *kube.KubernetesClient) (ArgoCD, error) {
func NewK8SClient(kubeClient *kube.ImageUpdaterKubernetesClient) (ArgoCD, error) {
return &k8sClient{kubeClient: kubeClient}, nil
}

Expand Down
21 changes: 12 additions & 9 deletions pkg/argocd/argocd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"testing"

"github.com/argoproj-labs/argocd-image-updater/pkg/common"
"github.com/argoproj-labs/argocd-image-updater/pkg/image"
"github.com/argoproj-labs/argocd-image-updater/pkg/kube"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/image"
registryKube "github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/kube"

"github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
Expand Down Expand Up @@ -1015,8 +1016,10 @@ func TestKubernetesClient(t *testing.T) {
ObjectMeta: v1.ObjectMeta{Name: "test-app2", Namespace: "testns2"},
}

client, err := NewK8SClient(&kube.KubernetesClient{
Namespace: "testns1",
client, err := NewK8SClient(&kube.ImageUpdaterKubernetesClient{
KubeClient: &registryKube.KubernetesClient{
Namespace: "testns1",
},
ApplicationsClientset: fake.NewSimpleClientset(app1, app2),
})

Expand Down Expand Up @@ -1057,7 +1060,7 @@ func TestKubernetesClient(t *testing.T) {
})

// Create the Kubernetes client
client, err := NewK8SClient(&kube.KubernetesClient{
client, err := NewK8SClient(&kube.ImageUpdaterKubernetesClient{
ApplicationsClientset: clientset,
})
require.NoError(t, err)
Expand Down Expand Up @@ -1087,7 +1090,7 @@ func TestKubernetesClient(t *testing.T) {
)

// Create the Kubernetes client
client, err := NewK8SClient(&kube.KubernetesClient{
client, err := NewK8SClient(&kube.ImageUpdaterKubernetesClient{
ApplicationsClientset: clientset,
})
require.NoError(t, err)
Expand Down Expand Up @@ -1117,7 +1120,7 @@ func TestKubernetesClientUpdateSpec(t *testing.T) {
}
})

client, err := NewK8SClient(&kube.KubernetesClient{
client, err := NewK8SClient(&kube.ImageUpdaterKubernetesClient{
ApplicationsClientset: clientset,
})
require.NoError(t, err)
Expand All @@ -1138,7 +1141,7 @@ func TestKubernetesClientUpdateSpec(t *testing.T) {
// Create a fake empty clientset
clientset := fake.NewSimpleClientset()

client, err := NewK8SClient(&kube.KubernetesClient{
client, err := NewK8SClient(&kube.ImageUpdaterKubernetesClient{
ApplicationsClientset: clientset,
})
require.NoError(t, err)
Expand All @@ -1162,7 +1165,7 @@ func TestKubernetesClientUpdateSpec(t *testing.T) {
Spec: v1alpha1.ApplicationSpec{},
})

client, err := NewK8SClient(&kube.KubernetesClient{
client, err := NewK8SClient(&kube.ImageUpdaterKubernetesClient{
ApplicationsClientset: clientset,
})
require.NoError(t, err)
Expand Down Expand Up @@ -1191,7 +1194,7 @@ func TestKubernetesClientUpdateSpec(t *testing.T) {
Spec: v1alpha1.ApplicationSpec{},
})

client, err := NewK8SClient(&kube.KubernetesClient{
client, err := NewK8SClient(&kube.ImageUpdaterKubernetesClient{
ApplicationsClientset: clientset,
})
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/argocd/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"sigs.k8s.io/kustomize/kyaml/order"
kyaml "sigs.k8s.io/kustomize/kyaml/yaml"

"github.com/argoproj-labs/argocd-image-updater/pkg/image"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/image"

"github.com/argoproj-labs/argocd-image-updater/ext/git"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/log"
Expand Down
2 changes: 1 addition & 1 deletion pkg/argocd/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/argoproj-labs/argocd-image-updater/pkg/common"
"github.com/argoproj-labs/argocd-image-updater/pkg/image"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/image"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/tag"

"sigs.k8s.io/kustomize/api/types"
Expand Down
12 changes: 6 additions & 6 deletions pkg/argocd/gitcreds.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

// getGitCredsSource returns git credentials source that loads credentials from the secret or from Argo CD settings
func getGitCredsSource(creds string, kubeClient *kube.KubernetesClient, wbc *WriteBackConfig) (GitCredsSource, error) {
func getGitCredsSource(creds string, kubeClient *kube.ImageUpdaterKubernetesClient, wbc *WriteBackConfig) (GitCredsSource, error) {
switch {
case creds == "repocreds":
return func(app *v1alpha1.Application) (git.Creds, error) {
Expand All @@ -33,12 +33,12 @@ func getGitCredsSource(creds string, kubeClient *kube.KubernetesClient, wbc *Wri
}

// getCredsFromArgoCD loads repository credentials from Argo CD settings
func getCredsFromArgoCD(wbc *WriteBackConfig, kubeClient *kube.KubernetesClient, project string) (git.Creds, error) {
func getCredsFromArgoCD(wbc *WriteBackConfig, kubeClient *kube.ImageUpdaterKubernetesClient, project string) (git.Creds, error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

settingsMgr := settings.NewSettingsManager(ctx, kubeClient.Clientset, kubeClient.Namespace)
argocdDB := db.NewDB(kubeClient.Namespace, settingsMgr, kubeClient.Clientset)
settingsMgr := settings.NewSettingsManager(ctx, kubeClient.KubeClient.Clientset, kubeClient.KubeClient.Namespace)
argocdDB := db.NewDB(kubeClient.KubeClient.Namespace, settingsMgr, kubeClient.KubeClient.Clientset)
repo, err := argocdDB.GetRepository(ctx, wbc.GitRepo, project)
if err != nil {
return nil, err
Expand Down Expand Up @@ -112,12 +112,12 @@ func getCAPath(repoURL string) string {
}

// getCredsFromSecret loads repository credentials from secret
func getCredsFromSecret(wbc *WriteBackConfig, credentialsSecret string, kubeClient *kube.KubernetesClient) (git.Creds, error) {
func getCredsFromSecret(wbc *WriteBackConfig, credentialsSecret string, kubeClient *kube.ImageUpdaterKubernetesClient) (git.Creds, error) {
var credentials map[string][]byte
var err error
s := strings.SplitN(credentialsSecret, "/", 2)
if len(s) == 2 {
credentials, err = kubeClient.GetSecretData(s[0], s[1])
credentials, err = kubeClient.KubeClient.GetSecretData(s[0], s[1])
if err != nil {
return nil, err
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/argocd/gitcreds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/argoproj-labs/argocd-image-updater/ext/git"
"github.com/argoproj-labs/argocd-image-updater/pkg/kube"
registryKube "github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/kube"
"github.com/argoproj-labs/argocd-image-updater/test/fake"
"github.com/argoproj-labs/argocd-image-updater/test/fixture"

Expand All @@ -21,8 +22,10 @@ func TestGetCredsFromSecret(t *testing.T) {

secret1 := fixture.NewSecret("foo", "bar", map[string][]byte{"username": []byte("myuser"), "password": []byte("mypass")})
secret2 := fixture.NewSecret("foo1", "bar1", map[string][]byte{"username": []byte("myuser")})
kubeClient := kube.KubernetesClient{
Clientset: fake.NewFakeClientsetWithResources(secret1, secret2),
kubeClient := kube.ImageUpdaterKubernetesClient{
KubeClient: &registryKube.KubernetesClient{
Clientset: fake.NewFakeClientsetWithResources(secret1, secret2),
},
}

// Test case 1: Valid secret reference
Expand Down Expand Up @@ -53,7 +56,7 @@ func TestGetCredsFromSecret(t *testing.T) {
}

func TestGetGitCredsSource(t *testing.T) {
kubeClient := &kube.KubernetesClient{}
kubeClient := &kube.ImageUpdaterKubernetesClient{}
wbc := &WriteBackConfig{
GitRepo: "https://github.com/example/repo.git",
GitCreds: git.NoopCredsStore{},
Expand Down
Loading

0 comments on commit 1a998b1

Please sign in to comment.