Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up and rearrange packages #663

Merged
merged 1 commit into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 0 additions & 89 deletions client/main.go

This file was deleted.

48 changes: 9 additions & 39 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,9 @@ 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"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"github.com/tinkerbell/tink/internal/grpcserver"
"github.com/tinkerbell/tink/internal/httpserver"
"github.com/tinkerbell/tink/internal/server"
)

// version is set at build time.
Expand All @@ -30,15 +26,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 +44,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 +53,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 +94,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 @@ -122,22 +105,8 @@ func NewRootCommand(config *DaemonConfig, logger log.Logger) *cobra.Command {
// graceful shutdown and error management but I want to
// figure this out in another PR
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)))
}
var registrar grpcserver.Registrar

switch config.Backend {
case backendKubernetes:
var err error
Expand All @@ -153,13 +122,14 @@ func NewRootCommand(config *DaemonConfig, logger log.Logger) *cobra.Command {
default:
return fmt.Errorf("invalid backend: %s", config.Backend)
}

// Start the gRPC server in the background
addr, err := grpcserver.SetupGRPC(
ctx,
registrar,
config.GRPCAuthority,
grpcOpts,
errCh)
errCh,
)
if err != nil {
return err
}
Expand All @@ -168,7 +138,7 @@ func NewRootCommand(config *DaemonConfig, logger log.Logger) *cobra.Command {
httpserver.SetupHTTP(ctx, logger, config.HTTPAuthority, errCh)

select {
case err = <-errCh:
case err := <-errCh:
logger.Error(err)
case sig := <-sigs:
logger.With("signal", sig.String()).Info("signal received, stopping servers")
Expand Down
2 changes: 1 addition & 1 deletion 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
2 changes: 1 addition & 1 deletion 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
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.

53 changes: 0 additions & 53 deletions grpc-server/testdata/server-key.pem

This file was deleted.

Loading