File tree Expand file tree Collapse file tree 6 files changed +89
-40
lines changed
cmd/argocd-k8s-auth/commands Expand file tree Collapse file tree 6 files changed +89
-40
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ builds:
2121 - -X github.com/argoproj/argo-cd/v3/common.gitCommit={{ .FullCommit }}
2222 - -X github.com/argoproj/argo-cd/v3/common.gitTreeState={{ .Env.GIT_TREE_STATE }}
2323 - -X github.com/argoproj/argo-cd/v3/common.kubectlVersion={{ .Env.KUBECTL_VERSION }}
24- - ' {{ if or (eq .Runtime.Goos "linux") (eq .Runtime.Goos "windows") }} -extldflags="-static"{{ end }} '
24+ - -extldflags="-static"
2525 goos :
2626 - linux
2727 - windows
@@ -42,15 +42,6 @@ builds:
4242 goarch : ppc64le
4343 - goos : windows
4444 goarch : arm64
45- overrides :
46- - goos : darwin
47- goarch : amd64
48- env :
49- - CGO_ENABLED=1
50- - goos : darwin
51- goarch : arm64
52- env :
53- - CGO_ENABLED=1
5445
5546archives :
5647 - id : argocd-archive
Original file line number Diff line number Diff line change 1+ //go:build !darwin || (cgo && darwin)
2+
13package commands
24
35import (
Original file line number Diff line number Diff line change 1+ //go:build darwin && !cgo
2+
3+ // Package commands
4+ // This file is used when the GOOS is darwin and CGO is not enabled.
5+ // It provides a no-op implementation of newAzureCommand to allow goreleaser to build
6+ // a darwin binary on a linux machine.
7+ package commands
8+
9+ import (
10+ "log"
11+
12+ "github.com/spf13/cobra"
13+
14+ "github.com/argoproj/argo-cd/v3/util/workloadidentity"
15+ )
16+
17+ func newAzureCommand () * cobra.Command {
18+ command := & cobra.Command {
19+ Use : "azure" ,
20+ Run : func (c * cobra.Command , _ []string ) {
21+ log .Fatalf (workloadidentity .CGOError )
22+ },
23+ }
24+ return command
25+ }
Original file line number Diff line number Diff line change 11package workloadidentity
22
33import (
4- "context"
54 "time"
6-
7- "github.com/Azure/azure-sdk-for-go/sdk/azcore"
8- "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
9- "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
105)
116
127const (
@@ -22,34 +17,9 @@ type TokenProvider interface {
2217 GetToken (scope string ) (* Token , error )
2318}
2419
25- type WorkloadIdentityTokenProvider struct {
26- tokenCredential azcore.TokenCredential
27- }
28-
2920// Used to propagate initialization error if any
3021var initError error
3122
32- func NewWorkloadIdentityTokenProvider () TokenProvider {
33- cred , err := azidentity .NewDefaultAzureCredential (& azidentity.DefaultAzureCredentialOptions {})
34- initError = err
35- return WorkloadIdentityTokenProvider {tokenCredential : cred }
36- }
37-
38- func (c WorkloadIdentityTokenProvider ) GetToken (scope string ) (* Token , error ) {
39- if initError != nil {
40- return nil , initError
41- }
42-
43- token , err := c .tokenCredential .GetToken (context .Background (), policy.TokenRequestOptions {
44- Scopes : []string {scope },
45- })
46- if err != nil {
47- return nil , err
48- }
49-
50- return & Token {AccessToken : token .Token , ExpiresOn : token .ExpiresOn }, nil
51- }
52-
5323func CalculateCacheExpiryBasedOnTokenExpiry (tokenExpiry time.Time ) time.Duration {
5424 // Calculate the cache expiry as 5 minutes before the token expires
5525 cacheExpiry := time .Until (tokenExpiry ) - time .Minute * 5
Original file line number Diff line number Diff line change 1+ //go:build !darwin || (cgo && darwin)
2+
3+ package workloadidentity
4+
5+ import (
6+ "context"
7+
8+ "github.com/Azure/azure-sdk-for-go/sdk/azcore"
9+ "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
10+ "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
11+ )
12+
13+ type WorkloadIdentityTokenProvider struct {
14+ tokenCredential azcore.TokenCredential
15+ }
16+
17+ func NewWorkloadIdentityTokenProvider () TokenProvider {
18+ cred , err := azidentity .NewDefaultAzureCredential (& azidentity.DefaultAzureCredentialOptions {})
19+ initError = err
20+ return WorkloadIdentityTokenProvider {tokenCredential : cred }
21+ }
22+
23+ func (c WorkloadIdentityTokenProvider ) GetToken (scope string ) (* Token , error ) {
24+ if initError != nil {
25+ return nil , initError
26+ }
27+
28+ token , err := c .tokenCredential .GetToken (context .Background (), policy.TokenRequestOptions {
29+ Scopes : []string {scope },
30+ })
31+ if err != nil {
32+ return nil , err
33+ }
34+
35+ return & Token {AccessToken : token .Token , ExpiresOn : token .ExpiresOn }, nil
36+ }
Original file line number Diff line number Diff line change 1+ //go:build darwin && !cgo
2+
3+ // Package workloadidentity
4+ // This file is used when the GOOS is darwin and CGO is not enabled.
5+ // It provides a no-op implementation of the WorkloadIdentityTokenProvider to allow goreleaser to build
6+ // a darwin binary on a linux machine.
7+ package workloadidentity
8+
9+ import (
10+ "errors"
11+ )
12+
13+ type WorkloadIdentityTokenProvider struct {
14+ }
15+
16+ const CGOError = "CGO is not enabled, cannot use workload identity token provider"
17+
18+ // Code that does not require CGO
19+ func NewWorkloadIdentityTokenProvider () TokenProvider {
20+ panic (CGOError )
21+ }
22+
23+ func (c WorkloadIdentityTokenProvider ) GetToken (scope string ) (* Token , error ) {
24+ return nil , errors .New (CGOError )
25+ }
You can’t perform that action at this time.
0 commit comments