Skip to content

Commit

Permalink
move and refactor common environment; AuthN version and build time
Browse files Browse the repository at this point in the history
* add `api/env` package
* authn executable to report version and build time (consistent format)

Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Jul 5, 2022
1 parent eb50757 commit 41a5070
Show file tree
Hide file tree
Showing 32 changed files with 125 additions and 85 deletions.
13 changes: 7 additions & 6 deletions ais/earlystart.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package ais provides core functionality for the AIStore object storage.
/*
* Copyright (c) 2018-2021, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
*/
package ais

Expand All @@ -11,6 +11,7 @@ import (

"github.com/NVIDIA/aistore/3rdparty/glog"
"github.com/NVIDIA/aistore/api/apc"
"github.com/NVIDIA/aistore/api/env"
"github.com/NVIDIA/aistore/cluster"
"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/cmn/cos"
Expand Down Expand Up @@ -115,14 +116,14 @@ func (p *proxy) determineRole(loadedSmap *smapX) (pid string, primary bool) {
pid string
primary bool
}{
pid: os.Getenv(cmn.EnvVars.PrimaryID),
primary: cos.IsParseBool(os.Getenv(cmn.EnvVars.IsPrimary)),
pid: os.Getenv(env.AIS.PrimaryID),
primary: cos.IsParseBool(os.Getenv(env.AIS.IsPrimary)),
}

if envP.pid != "" && envP.primary && p.si.ID() != envP.pid {
cos.ExitLogf(
"FATAL: %s: invalid combination of %s=true & %s=%s",
p.si, cmn.EnvVars.IsPrimary, cmn.EnvVars.PrimaryID, envP.pid,
p.si, env.AIS.IsPrimary, env.AIS.PrimaryID, envP.pid,
)
}
glog.Infof("%s: %sprimary-env=%+v", p.si.StringEx(), tag, envP)
Expand All @@ -132,13 +133,13 @@ func (p *proxy) determineRole(loadedSmap *smapX) (pid string, primary bool) {
if primary == nil {
glog.Errorf(
"%s: ignoring %s=%s - not found in the loaded %s",
p.si, cmn.EnvVars.IsPrimary, envP.pid, loadedSmap,
p.si, env.AIS.IsPrimary, envP.pid, loadedSmap,
)
envP.pid = ""
} else if loadedSmap.Primary.ID() != envP.pid {
glog.Warningf(
"%s: new %s=%s, previous %s",
p.si, cmn.EnvVars.PrimaryID, envP.pid, loadedSmap.Primary,
p.si, env.AIS.PrimaryID, envP.pid, loadedSmap.Primary,
)
loadedSmap.Primary = primary
}
Expand Down
3 changes: 2 additions & 1 deletion ais/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/NVIDIA/aistore/3rdparty/glog"
"github.com/NVIDIA/aistore/api/apc"
"github.com/NVIDIA/aistore/api/env"
"github.com/NVIDIA/aistore/cluster"
"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/cmn/cos"
Expand Down Expand Up @@ -2341,7 +2342,7 @@ func (p *proxy) httpdaeget(w http.ResponseWriter, r *http.Request) {
DeploymentType: deploymentType(),
Version: daemon.version,
BuildTime: daemon.buildTime,
K8sPodName: os.Getenv(cmn.EnvVars.K8sPod),
K8sPodName: os.Getenv(env.AIS.K8sPod),
}

p.writeJSON(w, r, msg, what)
Expand Down
11 changes: 6 additions & 5 deletions ais/tests/main_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package integration contains AIS integration tests.
/*
* Copyright (c) 2018-2021, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
*/
package integration

Expand All @@ -15,6 +15,7 @@ import (

"github.com/NVIDIA/aistore/api"
"github.com/NVIDIA/aistore/api/apc"
"github.com/NVIDIA/aistore/api/env"
"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/cmn/cos"
"github.com/NVIDIA/aistore/devtools/tlog"
Expand Down Expand Up @@ -50,16 +51,16 @@ func waitForCluster() error {
err error
proxyCnt, targetCnt, retry int
)
pc := os.Getenv(cmn.EnvVars.NumProxy)
tc := os.Getenv(cmn.EnvVars.NumTarget)
pc := os.Getenv(env.AIS.NumProxy)
tc := os.Getenv(env.AIS.NumTarget)
if pc != "" || tc != "" {
proxyCnt, err = strconv.Atoi(pc)
if err != nil {
return fmt.Errorf("error EnvVars: %s. err: %v", cmn.EnvVars.NumProxy, err)
return fmt.Errorf("error EnvVars: %s. err: %v", env.AIS.NumProxy, err)
}
targetCnt, err = strconv.Atoi(tc)
if err != nil {
return fmt.Errorf("error EnvVars: %s. err: %v", cmn.EnvVars.NumTarget, err)
return fmt.Errorf("error EnvVars: %s. err: %v", env.AIS.NumTarget, err)
}
}
_, err = tutils.WaitForClusterState(tutils.GetPrimaryURL(), "startup", -1, proxyCnt, targetCnt)
Expand Down
6 changes: 3 additions & 3 deletions ais/tests/s3compat/e2e_s3_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package s3_integration provides tests of compatibility with AWS S3
/*
* Copyright (c) 2018-2021, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
*/
package integration

Expand All @@ -11,7 +11,7 @@ import (
"testing"
"time"

"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/api/env"
"github.com/NVIDIA/aistore/cmn/cos"
"github.com/NVIDIA/aistore/devtools/tutils"
. "github.com/onsi/ginkgo"
Expand All @@ -38,7 +38,7 @@ var _ = Describe("E2E AWS Compatibility Tests", func() {
params string
)

if value := os.Getenv(cmn.EnvVars.UseHTTPS); cos.IsParseBool(value) {
if value := os.Getenv(env.AIS.UseHTTPS); cos.IsParseBool(value) {
host = "https://localhost:8080/s3"
params = "--no-check-certificate"
} else {
Expand Down
3 changes: 2 additions & 1 deletion ais/tgtcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/NVIDIA/aistore/3rdparty/glog"
"github.com/NVIDIA/aistore/ais/backend"
"github.com/NVIDIA/aistore/api/apc"
"github.com/NVIDIA/aistore/api/env"
"github.com/NVIDIA/aistore/cluster"
"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/cmn/cos"
Expand Down Expand Up @@ -262,7 +263,7 @@ func (t *target) httpdaeget(w http.ResponseWriter, r *http.Request) {
DeploymentType: deploymentType(),
Version: daemon.version,
BuildTime: daemon.buildTime,
K8sPodName: os.Getenv(cmn.EnvVars.K8sPod),
K8sPodName: os.Getenv(env.AIS.K8sPod),
}
// capacity
tstats := t.statsT.(*stats.Trunner)
Expand Down
5 changes: 3 additions & 2 deletions ais/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/NVIDIA/aistore/3rdparty/glog"
"github.com/NVIDIA/aistore/api/apc"
"github.com/NVIDIA/aistore/api/env"
"github.com/NVIDIA/aistore/cluster"
"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/cmn/cos"
Expand Down Expand Up @@ -242,7 +243,7 @@ func cleanupConfigDir(name string, keepInitialConfig bool) {
}

func writeShutdownMarker() {
markerDir := os.Getenv(cmn.EnvVars.ShutdownMarkerPath)
markerDir := os.Getenv(env.AIS.ShutdownMarkerPath)
if markerDir == "" {
if k8s.Detect() == nil {
glog.Warningf("marker directory not specified, skipping writing shutdown marker")
Expand All @@ -259,7 +260,7 @@ func writeShutdownMarker() {
}

func deleteShutdownMarker() {
markerDir := os.Getenv(cmn.EnvVars.ShutdownMarkerPath)
markerDir := os.Getenv(env.AIS.ShutdownMarkerPath)
if markerDir != "" {
cos.RemoveFile(filepath.Join(markerDir, cmn.ShutdownMarker))
}
Expand Down
3 changes: 2 additions & 1 deletion api/authn/loadtoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path/filepath"

"github.com/NVIDIA/aistore/api/env"
"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/cmn/cos"
"github.com/NVIDIA/aistore/cmn/debug"
Expand All @@ -21,7 +22,7 @@ func LoadToken(tokenFile string) string {
mustLoad = true
)
if tokenFile == "" {
tokenFile = os.Getenv(EnvVars.TokenFile)
tokenFile = os.Getenv(env.AuthN.TokenFile)
}
if tokenFile == "" {
// default config location
Expand Down
7 changes: 3 additions & 4 deletions cmn/env_const.go → api/env/ais.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Package cmn provides common constants, types, and utilities for AIS clients
// and AIStore.
// Package env contains environment variables
/*
* Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
*/
package cmn
package env

// ais environment variable names (see also fname_const.go)

var (
EnvVars = struct {
AIS = struct {
Endpoint string
ShutdownMarkerPath string
IsPrimary string
Expand Down
8 changes: 4 additions & 4 deletions api/authn/env_const.go → api/env/authn.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Package authn provides AuthN API over HTTP(S)
// Package env contains environment variables
/*
* Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
*/
package authn
package env

// authn environment variable names (see also cmn/env_const.go)
// authn environment variables

var (
EnvVars = struct {
AuthN = struct {
Enabled string
URL string
ConfFile string
Expand Down
3 changes: 2 additions & 1 deletion bench/aisloader/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import (
"github.com/NVIDIA/aistore/api"
"github.com/NVIDIA/aistore/api/apc"
"github.com/NVIDIA/aistore/api/authn"
"github.com/NVIDIA/aistore/api/env"
"github.com/NVIDIA/aistore/bench/aisloader/namegetter"
"github.com/NVIDIA/aistore/bench/aisloader/stats"
"github.com/NVIDIA/aistore/cmn"
Expand Down Expand Up @@ -552,7 +553,7 @@ func parseCmdLine() (params, error) {
}

aisEndpoint = "http://" + ip + ":" + port
envEndpoint = os.Getenv(cmn.EnvVars.Endpoint)
envEndpoint = os.Getenv(env.AIS.Endpoint)
if envEndpoint != "" {
aisEndpoint = envEndpoint
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/aisfs/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package aisfs - command-line mounting utility for aisfs.
/*
* Copyright (c) 2018-2021, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
*/
package main

Expand All @@ -10,8 +10,8 @@ import (
"path/filepath"
"time"

"github.com/NVIDIA/aistore/api/env"
"github.com/NVIDIA/aistore/cmd/aisfs/fs"
"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/cmn/cos"
"github.com/NVIDIA/aistore/cmn/jsp"
)
Expand Down Expand Up @@ -51,7 +51,7 @@ type (
var defaultConfig = Config{
Cluster: ClusterConfig{
URL: "http://127.0.0.1:8080",
SkipVerifyCrt: cos.IsParseBool(os.Getenv(cmn.EnvVars.SkipVerifyCrt)),
SkipVerifyCrt: cos.IsParseBool(os.Getenv(env.AIS.SkipVerifyCrt)),
},
Timeout: TimeoutConfig{
TCPTimeoutStr: "60s",
Expand Down
5 changes: 3 additions & 2 deletions cmd/aisfs/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"time"

"github.com/NVIDIA/aistore/api"
"github.com/NVIDIA/aistore/api/env"
"github.com/NVIDIA/aistore/cmd/aisfs/fs"
"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/cmn/cos"
Expand Down Expand Up @@ -60,9 +61,9 @@ func discoverClusterURL(c *cli.Context) string {
defaultAISDockerURL = "http://172.50.0.2:8080"
dockerErrMsgFmt = "Failed to discover docker proxy URL: %v.\nUsing default %q.\n"
)
setURLMsg := fmt.Sprintf("Set URL with: export %s=`url`.", cmn.EnvVars.Endpoint)
setURLMsg := fmt.Sprintf("Set URL with: export %s=`url`.", env.AIS.Endpoint)

if envURL := os.Getenv(cmn.EnvVars.Endpoint); envURL != "" {
if envURL := os.Getenv(env.AIS.Endpoint); envURL != "" {
return envURL
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/aisnode/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package main for the AIS node executable.
/*
* Copyright (c) 2018-2021, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
*/
package main

Expand Down
2 changes: 1 addition & 1 deletion cmd/authn/aisreq.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package authn provides AuthN server for AIStore.
// Package authn is authentication server for AIStore.
/*
* Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
*/
Expand Down
2 changes: 1 addition & 1 deletion cmd/authn/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package authn provides AuthN server for AIStore.
// Package authn is authentication server for AIStore.
/*
* Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
*/
Expand Down
2 changes: 1 addition & 1 deletion cmd/authn/const.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package authn provides AuthN server for AIStore.
// Package authn is authentication server for AIStore.
/*
* Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
*/
Expand Down
2 changes: 1 addition & 1 deletion cmd/authn/hcommon.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package authn provides AuthN server for AIStore.
// Package authn is authentication server for AIStore.
/*
* Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
*/
Expand Down
2 changes: 1 addition & 1 deletion cmd/authn/hserv.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package authn provides AuthN server for AIStore.
// Package authn is authentication server for AIStore.
/*
* Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
*/
Expand Down
Loading

0 comments on commit 41a5070

Please sign in to comment.