Skip to content

Commit

Permalink
chore: parse from env (argoproj#14116)
Browse files Browse the repository at this point in the history
Signed-off-by: xiaowu.zhu <[email protected]>
  • Loading branch information
yyzxw authored Jun 21, 2023
1 parent a5112a6 commit dc3ac02
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 22 deletions.
6 changes: 1 addition & 5 deletions cmd/argocd-repo-server/commands/argocd_repo_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ const (
)

func getGnuPGSourcePath() string {
if path := os.Getenv("ARGOCD_GPG_DATA_PATH"); path != "" {
return path
} else {
return gnuPGSourcePath
}
return env.StringFromEnv(common.EnvGPGDataPath, gnuPGSourcePath)
}

func getPauseGenerationAfterFailedGenerationAttempts() int {
Expand Down
6 changes: 4 additions & 2 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ const (
// PasswordPatten is the default password patten
PasswordPatten = `^.{8,32}$`

//LegacyShardingAlgorithm is the default value for Sharding Algorithm it uses an `uid` based distribution (non-uniform)
// LegacyShardingAlgorithm is the default value for Sharding Algorithm it uses an `uid` based distribution (non-uniform)
LegacyShardingAlgorithm = "legacy"
//RoundRobinShardingAlgorithm is a flag value that can be opted for Sharding Algorithm it uses an equal distribution accross all shards
// RoundRobinShardingAlgorithm is a flag value that can be opted for Sharding Algorithm it uses an equal distribution accross all shards
RoundRobinShardingAlgorithm = "round-robin"
DefaultShardingAlgorithm = LegacyShardingAlgorithm
)
Expand Down Expand Up @@ -231,6 +231,8 @@ const (
EnvCMPChunkSize = "ARGOCD_CMP_CHUNK_SIZE"
// EnvCMPWorkDir defines the full path of the work directory used by the CMP server
EnvCMPWorkDir = "ARGOCD_CMP_WORKDIR"
// EnvGPGDataPath overrides the location where GPG keyring for signature verification is stored
EnvGPGDataPath = "ARGOCD_GPG_DATA_PATH"
)

// Config Management Plugin related constants
Expand Down
12 changes: 4 additions & 8 deletions pkg/apiclient/apiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ func NewClient(opts *ClientOptions) (Client, error) {
c.UserAgent = fmt.Sprintf("%s/%s", common.ArgoCDUserAgentName, common.GetVersion().Version)
}
// Override server address if specified in env or CLI flag
if serverFromEnv := os.Getenv(EnvArgoCDServer); serverFromEnv != "" {
c.ServerAddr = serverFromEnv
}
c.ServerAddr = env.StringFromEnv(EnvArgoCDServer, c.ServerAddr)
if opts.PortForward || opts.PortForwardNamespace != "" {
if opts.KubeOverrides == nil {
opts.KubeOverrides = &clientcmd.ConfigOverrides{}
Expand All @@ -229,9 +227,7 @@ func NewClient(opts *ClientOptions) (Client, error) {
c.ServerAddr += ":443"
}
// Override auth-token if specified in env variable or CLI flag
if authFromEnv := os.Getenv(EnvArgoCDAuthToken); authFromEnv != "" {
c.AuthToken = authFromEnv
}
c.AuthToken = env.StringFromEnv(EnvArgoCDAuthToken, c.AuthToken)
if opts.AuthToken != "" {
c.AuthToken = strings.TrimSpace(opts.AuthToken)
}
Expand Down Expand Up @@ -285,8 +281,8 @@ func NewClient(opts *ClientOptions) (Client, error) {
}
}
if !c.GRPCWeb {
//test if we need to set it to true
//if a call to grpc failed, then try again with GRPCWeb
// test if we need to set it to true
// if a call to grpc failed, then try again with GRPCWeb
conn, versionIf, err := c.NewVersionClient()
if err == nil {
defer argoio.Close(conn)
Expand Down
9 changes: 5 additions & 4 deletions pkg/apis/application/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"time"
"unicode"

"github.com/argoproj/argo-cd/v2/util/env"
"github.com/argoproj/gitops-engine/pkg/health"
synccommon "github.com/argoproj/gitops-engine/pkg/sync/common"
"github.com/robfig/cron/v3"
Expand Down Expand Up @@ -1837,9 +1838,9 @@ type KnownTypeField struct {
// OverrideIgnoreDiff contains configurations about how fields should be ignored during diffs between
// the desired state and live state
type OverrideIgnoreDiff struct {
//JSONPointers is a JSON path list following the format defined in RFC4627 (https://datatracker.ietf.org/doc/html/rfc6902#section-3)
// JSONPointers is a JSON path list following the format defined in RFC4627 (https://datatracker.ietf.org/doc/html/rfc6902#section-3)
JSONPointers []string `json:"jsonPointers" protobuf:"bytes,1,rep,name=jSONPointers"`
//JQPathExpressions is a JQ path list that will be evaludated during the diff process
// JQPathExpressions is a JQ path list that will be evaludated during the diff process
JQPathExpressions []string `json:"jqPathExpressions" protobuf:"bytes,2,opt,name=jqPathExpressions"`
// ManagedFieldsManagers is a list of trusted managers. Fields mutated by those managers will take precedence over the
// desired state defined in the SCM and won't be displayed in diffs
Expand Down Expand Up @@ -2113,7 +2114,7 @@ type SyncWindow struct {
Clusters []string `json:"clusters,omitempty" protobuf:"bytes,6,opt,name=clusters"`
// ManualSync enables manual syncs when they would otherwise be blocked
ManualSync bool `json:"manualSync,omitempty" protobuf:"bytes,7,opt,name=manualSync"`
//TimeZone of the sync that will be applied to the schedule
// TimeZone of the sync that will be applied to the schedule
TimeZone string `json:"timeZone,omitempty" protobuf:"bytes,8,opt,name=timeZone"`
}

Expand Down Expand Up @@ -2826,7 +2827,7 @@ func SetK8SConfigDefaults(config *rest.Config) error {
func (c *Cluster) RawRestConfig() *rest.Config {
var config *rest.Config
var err error
if c.Server == KubernetesInternalAPIServerAddr && os.Getenv(EnvVarFakeInClusterConfig) == "true" {
if c.Server == KubernetesInternalAPIServerAddr && env.ParseBoolFromEnv(EnvVarFakeInClusterConfig, false) {
conf, exists := os.LookupEnv("KUBECONFIG")
if exists {
config, err = clientcmd.BuildConfigFromFlags("", conf)
Expand Down
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func init() {
if replicasCount > 0 {
maxConcurrentLoginRequestsCount = maxConcurrentLoginRequestsCount / replicasCount
}
enableGRPCTimeHistogram = os.Getenv(common.EnvEnableGRPCTimeHistogramEnv) == "true"
enableGRPCTimeHistogram = env.ParseBoolFromEnv(common.EnvEnableGRPCTimeHistogramEnv, false)
}

// ArgoCDServer is the API server for Argo CD
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/fixture/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
sessionpkg "github.com/argoproj/argo-cd/v2/pkg/apiclient/session"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
appclientset "github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned"
"github.com/argoproj/argo-cd/v2/util/env"
. "github.com/argoproj/argo-cd/v2/util/errors"
grpcutil "github.com/argoproj/argo-cd/v2/util/grpc"
"github.com/argoproj/argo-cd/v2/util/io"
Expand Down Expand Up @@ -142,8 +143,7 @@ func GetEnvWithDefault(envName, defaultValue string) string {
// IsRemote returns true when the tests are being run against a workload that
// is running in a remote cluster.
func IsRemote() bool {
r := os.Getenv("ARGOCD_E2E_REMOTE")
return r == "true"
return env.ParseBoolFromEnv("ARGOCD_E2E_REMOTE", false)
}

// IsLocal returns when the tests are being run against a local workload
Expand Down

0 comments on commit dc3ac02

Please sign in to comment.