Skip to content

Commit

Permalink
Clean up and rearrange packages
Browse files Browse the repository at this point in the history
- Remove TLS configurability
- Move packages that can be easily moved and are internal to /internal
- Update some package names to be more representative of their function
- Remove obsolete/unused code

Signed-off-by: Chris Doherty <[email protected]>
  • Loading branch information
chrisdoherty4 committed Dec 27, 2022
1 parent 1369125 commit 102b0d7
Show file tree
Hide file tree
Showing 39 changed files with 69 additions and 451 deletions.
89 changes: 0 additions & 89 deletions client/main.go

This file was deleted.

36 changes: 4 additions & 32 deletions cmd/tink-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"

Expand All @@ -15,12 +14,10 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
grpcserver "github.com/tinkerbell/tink/grpc-server"
httpserver "github.com/tinkerbell/tink/http-server"
"github.com/tinkerbell/tink/metrics"
"github.com/tinkerbell/tink/server"
"github.com/tinkerbell/tink/internal/grpcserver"
"github.com/tinkerbell/tink/internal/httpserver"
"github.com/tinkerbell/tink/internal/server"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)

// version is set at build time.
Expand All @@ -30,15 +27,8 @@ var version = "devel"
// You can change the configuration via environment variable, or file, or command flags.
type DaemonConfig struct {
Facility string
PGDatabase string
PGUSer string
PGPassword string
PGSSLMode string
OnlyMigration bool
GRPCAuthority string
CertDir string
HTTPAuthority string
TLS bool
Backend string

KubeconfigPath string
Expand All @@ -55,9 +45,7 @@ func backends() []string {
func (c *DaemonConfig) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&c.Facility, "facility", "deprecated", "This is temporary. It will be removed")
fs.StringVar(&c.GRPCAuthority, "grpc-authority", ":42113", "The address used to expose the gRPC server")
fs.StringVar(&c.CertDir, "cert-dir", "", "")
fs.StringVar(&c.HTTPAuthority, "http-authority", ":42114", "The address used to expose the HTTP server")
fs.BoolVar(&c.TLS, "tls", true, "Run in tls protected mode (disabling should only be done for development or if behind TLS terminating proxy)")
fs.StringVar(&c.Backend, "backend", backendKubernetes, fmt.Sprintf("The backend datastore to use. Must be one of %s", strings.Join(backends(), ", ")))
fs.StringVar(&c.KubeconfigPath, "kubeconfig", "", "The path to the Kubeconfig. Only takes effect if `--backend=kubernetes`")
fs.StringVar(&c.KubeAPI, "kubernetes", "", "The Kubernetes API URL, used for in-cluster client construction. Only takes effect if `--backend=kubernetes`")
Expand All @@ -66,11 +54,8 @@ func (c *DaemonConfig) AddFlags(fs *pflag.FlagSet) {

func (c *DaemonConfig) PopulateFromLegacyEnvVar() {
c.Facility = env.Get("FACILITY", c.Facility)

c.CertDir = env.Get("TINKERBELL_CERTS_DIR", c.CertDir)
c.GRPCAuthority = env.Get("TINKERBELL_GRPC_AUTHORITY", c.GRPCAuthority)
c.HTTPAuthority = env.Get("TINKERBELL_HTTP_AUTHORITY", c.HTTPAuthority)
c.TLS = env.Bool("TINKERBELL_TLS", c.TLS)
}

func main() {
Expand Down Expand Up @@ -110,7 +95,6 @@ func NewRootCommand(config *DaemonConfig, logger log.Logger) *cobra.Command {
// the most aggressive way we have to guarantee that
// the old way works as before.
config.PopulateFromLegacyEnvVar()
metrics.SetupMetrics(config.Facility, logger)

logger.Info("starting version " + version)

Expand All @@ -124,20 +108,8 @@ func NewRootCommand(config *DaemonConfig, logger log.Logger) *cobra.Command {
errCh := make(chan error, 2)
var (
registrar grpcserver.Registrar
grpcOpts []grpc.ServerOption
err error
)
if config.TLS {
certDir := config.CertDir
if certDir == "" {
certDir = env.Get("TINKERBELL_CERTS_DIR", filepath.Join("/certs", config.Facility))
}
cert, err := grpcserver.GetCerts(certDir)
if err != nil {
return err
}
grpcOpts = append(grpcOpts, grpc.Creds(credentials.NewServerTLSFromCert(cert)))
}
switch config.Backend {
case backendKubernetes:
var err error
Expand All @@ -158,7 +130,7 @@ func NewRootCommand(config *DaemonConfig, logger log.Logger) *cobra.Command {
ctx,
registrar,
config.GRPCAuthority,
grpcOpts,
[]grpc.ServerOption{},
errCh)
if err != nil {
return err
Expand Down
8 changes: 2 additions & 6 deletions cmd/tink-worker/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/tinkerbell/tink/client"
"github.com/tinkerbell/tink/cmd/tink-worker/worker"
"github.com/tinkerbell/tink/internal/client"
"github.com/tinkerbell/tink/protos/workflow"
)

Expand Down Expand Up @@ -44,10 +44,7 @@ func NewRootCommand(version string, logger log.Logger) *cobra.Command {

logger.With("version", version).Info("starting")

conn, err := client.NewClientConn(
viper.GetString("tinkerbell-grpc-authority"),
viper.GetBool("tinkerbell-tls"),
)
conn, err := client.NewClientConn(viper.GetString("tinkerbell-grpc-authority"))
if err != nil {
return err
}
Expand Down Expand Up @@ -92,7 +89,6 @@ func NewRootCommand(version string, logger log.Logger) *cobra.Command {
rootCmd.Flags().Int("max-retry", defaultRetryCount, "Maximum number of retries to attempt (MAX_RETRY)")
rootCmd.Flags().Int64("max-file-size", defaultMaxFileSize, "Maximum file size in bytes (MAX_FILE_SIZE)")
rootCmd.Flags().Bool("capture-action-logs", true, "Capture action container output as part of worker logs")
rootCmd.Flags().Bool("tinkerbell-tls", true, "Connect to server via TLS or not (TINKERBELL_TLS)")
rootCmd.Flags().StringP("docker-registry", "r", "", "Sets the Docker registry (DOCKER_REGISTRY)")
rootCmd.Flags().StringP("registry-username", "u", "", "Sets the registry username (REGISTRY_USERNAME)")
rootCmd.Flags().StringP("registry-password", "p", "", "Sets the registry-password (REGISTRY_PASSWORD)")
Expand Down
7 changes: 2 additions & 5 deletions cmd/virtual-worker/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/tinkerbell/tink/client"
tinkWorker "github.com/tinkerbell/tink/cmd/tink-worker/worker"
"github.com/tinkerbell/tink/cmd/virtual-worker/worker"
"github.com/tinkerbell/tink/internal/client"
"github.com/tinkerbell/tink/protos/workflow"
)

Expand Down Expand Up @@ -40,10 +40,7 @@ func NewRootCommand(version string, logger log.Logger) *cobra.Command {

logger.With("version", version).Info("starting")

conn, err := client.NewClientConn(
viper.GetString("tinkerbell-grpc-authority"),
viper.GetBool("tinkerbell-tls"),
)
conn, err := client.NewClientConn(viper.GetString("tinkerbell-grpc-authority"))
if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion config/server/server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ spec:
containers:
- args:
- "--backend=kubernetes"
- "--tls=false"
image: server:latest
imagePullPolicy: IfNotPresent
name: tink-server
Expand Down
35 changes: 0 additions & 35 deletions docs/ENVVARS.md

This file was deleted.

32 changes: 0 additions & 32 deletions grpc-server/testdata/bundle.pem

This file was deleted.

Loading

0 comments on commit 102b0d7

Please sign in to comment.