Skip to content

Commit

Permalink
Fix t3c version in build (#6405)
Browse files Browse the repository at this point in the history
Fixes the t3c build to properly add the ATC version, changeset,
and monotonic version to the t3c version commands,
as well as to t3c-generate generated files.

Also adds the version flag to apps that were missing it.
  • Loading branch information
rob05c committed Dec 13, 2021
1 parent 431aa13 commit e70ac05
Show file tree
Hide file tree
Showing 28 changed files with 345 additions and 64 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- cache config t3c-apply retrying when another t3c-apply is running.
- IMS warnings to Content Invalidation requests in Traffic Portal and documentation.
- [#6032](https://github.com/apache/trafficcontrol/issues/6032) Add t3c setting mode 0600 for secure files
- [#6405](https://github.com/apache/trafficcontrol/issues/6405) Added cache config version to all t3c apps and config file headers
- Traffic Vault: Added additional flag to TV Riak (Deprecated) Util

### Fixed
Expand Down
6 changes: 6 additions & 0 deletions cache-config/t3c-apply/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ t3c-apply [-2AbceFhIknopsSvW] [-a service-action] [-f \<all|reval|none\>] [-g \<

[\-\-help]

[\-\-version]

# DESCRIPTION

The t3c-apply command is a transliteration of traffic_ops_ort.pl script to the go language. It is designed to replace the traffic_ops_ort.pl perl script and it is used to apply configuration from Traffic Control, stored in Traffic Ops, to the cache.
Expand Down Expand Up @@ -94,6 +96,10 @@ Typical usage is to install t3c on the cache machine, and then run it periodical
Whether to set the records.config via header to the ATS
release from the RPM. Default true.

-E, -\-version

Print version information and exit.

-f, -\-files=value [all | reval]

Which files to generate. If reval, the Traffic
Expand Down
20 changes: 16 additions & 4 deletions cache-config/t3c-apply/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import (
"github.com/pborman/getopt/v2"
)

const AppName = "t3c-apply"

var TSHome string = "/opt/trafficserver"

const DefaultTSConfigDir = "/opt/trafficserver/etc/trafficserver"
Expand Down Expand Up @@ -112,8 +114,12 @@ type Cfg struct {
IgnoreUpdateFlag bool
NoUnsetUpdateFlag bool
UpdateIPAllow bool
Version string
GitRevision string
}

func (cfg Cfg) AppVersion() string { return t3cutil.VersionStr(AppName, cfg.Version, cfg.GitRevision) }

type UseGitFlag string

const (
Expand Down Expand Up @@ -213,10 +219,11 @@ func GetTSPackageHome() string {
return tsHome
}

func GetCfg() (Cfg, error) {
func GetCfg(appVersion string, gitRevision string) (Cfg, error) {
var err error
toInfoLog := []string{}

version := getopt.BoolLong("version", 'E', "Print version information and exit.")
cacheHostNamePtr := getopt.StringLong("cache-host-name", 'H', "", "Host name of the cache to generate config for. Must be the server host name in Traffic Ops, not a URL, and not the FQDN")
retriesPtr := getopt.IntLong("num-retries", 'r', 3, "[number] retry connection to Traffic Ops URL [number] times, default is 3")
reverseProxyDisablePtr := getopt.BoolLong("reverse-proxy-disable", 'p', "[false | true] bypass the reverse proxy even if one has been configured default is false")
Expand All @@ -228,7 +235,7 @@ func GetCfg() (Cfg, error) {
toPassPtr := getopt.StringLong("traffic-ops-password", 'P', "", "Traffic Ops password. Required. May also be set with the environment variable TO_PASS")
tsHomePtr := getopt.StringLong("trafficserver-home", 'R', "", "Trafficserver Package directory. May also be set with the environment variable TS_HOME")
dnsLocalBindPtr := getopt.BoolLong("dns-local-bind", 'b', "[true | false] whether to use the server's Service Addresses to set the ATS DNS local bind address")
helpPtr := getopt.BoolLong("help", 'h', "Print usage information and exit")
help := getopt.BoolLong("help", 'h', "Print usage information and exit")
useGitStr := getopt.StringLong("git", 'g', "auto", "Create and use a git repo in the config directory. Options are yes, no, and auto. If yes, create and use. If auto, use if it exist. Default is auto.")
noCachePtr := getopt.BoolLong("no-cache", 'n', "Whether to not use a cache and make conditional requests to Traffic Ops")
syncdsUpdatesIPAllowPtr := getopt.BoolLong("syncds-updates-ipallow", 'S', "Whether syncds mode will update ipallow. This exists because ATS had a bug where reloading after changing ipallow would block everything. Default is false.")
Expand Down Expand Up @@ -400,10 +407,13 @@ If any of the related flags are also set, they override the mode's default behav
toUser := *toUserPtr
toPass := *toPassPtr
dnsLocalBind := *dnsLocalBindPtr
help := *helpPtr
maxmindLocation := *maxmindLocationPtr

if help {
if *version {
cfg := &Cfg{Version: appVersion, GitRevision: gitRevision}
fmt.Println(cfg.AppVersion())
os.Exit(0)
} else if *help {
Usage()
return Cfg{}, nil
}
Expand Down Expand Up @@ -515,6 +525,8 @@ If any of the related flags are also set, they override the mode's default behav
InstallPackages: *installPackagesPtr,
IgnoreUpdateFlag: *ignoreUpdateFlagPtr,
NoUnsetUpdateFlag: *noUnsetUpdateFlagPtr,
Version: appVersion,
GitRevision: gitRevision,
}

if err = log.InitCfg(cfg); err != nil {
Expand Down
10 changes: 9 additions & 1 deletion cache-config/t3c-apply/t3c-apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ import (
"github.com/apache/trafficcontrol/lib/go-log"
)

// Version is the application version.
// This is overwritten by the build with the current project version.
var Version = "0.4"

// GitRevision is the git revision the application was built from.
// This is overwritten by the build with the current project version.
var GitRevision = "nogit"

// exit codes
const (
Success = 0
Expand Down Expand Up @@ -66,7 +74,7 @@ const LockFileRetryTimeout = time.Minute
func main() {
var syncdsUpdate torequest.UpdateStatus
var lock util.FileLock
cfg, err := config.GetCfg()
cfg, err := config.GetCfg(Version, GitRevision)
if err != nil {
fmt.Println(err)
os.Exit(ConfigError)
Expand Down
6 changes: 6 additions & 0 deletions cache-config/t3c-check-refs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ t3c-check-refs [-c directory] [-d location] [-e location] [-f files] [-i locatio

[\-\-help]

[\-\-version]

## DESCRIPTION

The t3c-check-refs app will read an ATS formatted plugin.config or remap.config
Expand Down Expand Up @@ -90,6 +92,10 @@ supplied, t3c-check-refs reads its config file input from stdin.
errors are logged. To log warnings, pass '-v'. To log info,
pass '-vv'. To omit error logging, see '-s'.

-V, -\-version

Print version information and exit.

## EXIT CODES

Returns 0 if no missing plugin DSO or config files are found.
Expand Down
19 changes: 18 additions & 1 deletion cache-config/t3c-check-refs/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ package config

import (
"errors"
"fmt"
"os"
"strings"

"github.com/apache/trafficcontrol/cache-config/t3cutil"
"github.com/apache/trafficcontrol/lib/go-log"

"github.com/pborman/getopt/v2"
)

const AppName = "t3c-check-refs"

type Cfg struct {
CommandArgs []string
LogLocationDebug string
Expand All @@ -37,13 +42,17 @@ type Cfg struct {
TrafficServerConfigDir string
TrafficServerPluginDir string
FilesAdding map[string]struct{}
Version string
GitRevision string
}

var (
defaultATSConfigDir = "/opt/trafficserver/etc/trafficserver"
defaultATSPluginDir = "/opt/trafficserver/libexec/trafficserver"
)

func (cfg Cfg) AppVersion() string { return t3cutil.VersionStr(AppName, cfg.Version, cfg.GitRevision) }

func (cfg Cfg) DebugLog() log.LogLocation { return log.LogLocation(cfg.LogLocationDebug) }
func (cfg Cfg) ErrorLog() log.LogLocation { return log.LogLocation(cfg.LogLocationError) }
func (cfg Cfg) InfoLog() log.LogLocation { return log.LogLocation(cfg.LogLocationInfo) }
Expand All @@ -57,7 +66,8 @@ func Usage() {
}

// InitConfig() intializes the configuration variables and loggers.
func InitConfig() (Cfg, error) {
func InitConfig(appVersion string, gitRevision string) (Cfg, error) {
versionPtr := getopt.BoolLong("version", 'V', "Print version information and exit.")
atsConfigDirPtr := getopt.StringLong("trafficserver-config-dir", 'c', defaultATSConfigDir, "directory where ATS config files are stored.")
atsPluginDirPtr := getopt.StringLong("trafficserver-plugin-dir", 'p', defaultATSPluginDir, "directory where ATS plugins are stored.")
filesAdding := getopt.StringLong("files-adding", 'f', "", "comma-delimited list of file names being added, to not fail to verify if they don't already exist.")
Expand All @@ -69,6 +79,11 @@ func InitConfig() (Cfg, error) {

if *helpPtr == true {
Usage()
os.Exit(0)
} else if *versionPtr {
cfg := &Cfg{Version: appVersion, GitRevision: gitRevision}
fmt.Println(cfg.AppVersion())
os.Exit(0)
}

logLocationError := log.LogLocationStderr
Expand Down Expand Up @@ -109,6 +124,8 @@ func InitConfig() (Cfg, error) {
TrafficServerConfigDir: *atsConfigDirPtr,
TrafficServerPluginDir: *atsPluginDirPtr,
FilesAdding: filesAddingSet,
Version: appVersion,
GitRevision: gitRevision,
}

if err := log.InitCfg(cfg); err != nil {
Expand Down
10 changes: 9 additions & 1 deletion cache-config/t3c-check-refs/t3c-check-refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ import (
"github.com/apache/trafficcontrol/lib/go-log"
)

// Version is the application version.
// This is overwritten by the build with the current project version.
var Version = "0.4"

// GitRevision is the git revision the application was built from.
// This is overwritten by the build with the current project version.
var GitRevision = "nogit"

var (
cfg config.Cfg
atsPlugins = make(map[string]int)
Expand Down Expand Up @@ -241,7 +249,7 @@ func main() {
pluginErrorCount := 0

var err error
cfg, err = config.InitConfig()
cfg, err = config.InitConfig(Version, GitRevision)
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR: %s\n", err.Error())
os.Exit(1)
Expand Down
9 changes: 8 additions & 1 deletion cache-config/t3c-check-reload/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ t3c-check-reload

[\-\-help]

[\-\-version]

# DESCRIPTION

The t3c-check-reload app takes json input from stdin.
Expand All @@ -62,11 +64,16 @@ Possible return values are:
# JSON Format

{"changed_files":"<list of files>","installed_plugins":"<list of plugins>"}

# OPTIONS
-h, --help

-h, -\-help

Print usage information and exit

-V, -\-version

Print version information and exit.

# AUTHORS

Expand Down
14 changes: 14 additions & 0 deletions cache-config/t3c-check-reload/t3c-check-reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,30 @@ import (
"github.com/pborman/getopt/v2"
)

const AppName = "t3c-check-reload"

// Version is the application version.
// This is overwritten by the build with the current project version.
var Version = "0.4"

// GitRevision is the git revision the application was built from.
// This is overwritten by the build with the current project version.
var GitRevision = "nogit"

func main() {
// presumably calculated by by t3c-check-refs
// TODO remove? The blueprint says t3c/ORT will no longer install packages

version := getopt.BoolLong("version", 'V', "Print version information and exit.")
help := getopt.BoolLong("help", 'h', "Print usage information and exit")
getopt.Parse()

if *help {
fmt.Println(usageStr())
os.Exit(0)
} else if *version {
fmt.Println(t3cutil.VersionStr(AppName, Version, GitRevision))
os.Exit(0)
}

changedCfg := &ChangedCfg{}
Expand Down
11 changes: 11 additions & 0 deletions cache-config/t3c-check/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ t3c-check \<command\> [\<args\>]

[\-\-help]

[\-\-version]

# DESCRIPTION

The t3c-check application has commands for checking things about new config files, such as
Expand All @@ -61,6 +63,15 @@ t3c-check-refs

Check if a config file's referenced plugins and files are valid

# OPTIONS
-h, -\-help

Print usage information and exit

-V, -\-version

Print version information and exit.

# AUTHORS

The t3c application is maintained by Apache Traffic Control project. For help, bug reports, contributing, or anything else, see:
Expand Down
19 changes: 18 additions & 1 deletion cache-config/t3c-check/t3c-check.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,27 @@ package main
*/

import (
"github.com/apache/trafficcontrol/lib/go-log"
"fmt"
"os"
"os/exec"
"syscall" // TODO change to x/unix ?

"github.com/apache/trafficcontrol/cache-config/t3cutil"
"github.com/apache/trafficcontrol/lib/go-log"

"github.com/pborman/getopt/v2"
)

const AppName = "t3c-check"

// Version is the application version.
// This is overwritten by the build with the current project version.
var Version = "0.4"

// GitRevision is the git revision the application was built from.
// This is overwritten by the build with the current project version.
var GitRevision = "nogit"

var commands = map[string]struct{}{
"refs": {},
"reload": {},
Expand All @@ -42,11 +55,15 @@ const ExitCodeCommandLookupErr = 5

func main() {
flagHelp := getopt.BoolLong("help", 'h', "Print usage information and exit")
flagVersion := getopt.BoolLong("version", 'V', "Print version information and exit.")
getopt.Parse()
log.Init(os.Stderr, os.Stderr, os.Stderr, os.Stderr, os.Stderr)
if *flagHelp {
log.Errorln(usageStr())
os.Exit(ExitCodeSuccess)
} else if *flagVersion {
fmt.Println(t3cutil.VersionStr(AppName, Version, GitRevision))
os.Exit(ExitCodeSuccess)
}

if len(os.Args) < 2 {
Expand Down
8 changes: 7 additions & 1 deletion cache-config/t3c-diff/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ t3c-diff \<file-a\> \<file-a\>

[\-\-help]

[\-\-version]

# DESCRIPTION

The t3c-diff application compares configuration files with semantic context, omitting comments and other semantically irrelevant text.
Expand All @@ -58,10 +60,14 @@ if the file being created or deleted is semantically empty.

# OPTIONS

-h, --help
-h, -\-help

Print usage info and exit.

-V, -\-version

Print version information and exit.

# AUTHORS

The t3c application is maintained by Apache Traffic Control project. For help, bug reports, contributing, or anything else, see:
Expand Down
Loading

0 comments on commit e70ac05

Please sign in to comment.