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 1a3d2df
Show file tree
Hide file tree
Showing 39 changed files with 102 additions and 421 deletions.
89 changes: 0 additions & 89 deletions client/main.go

This file was deleted.

23 changes: 9 additions & 14 deletions cmd/tink-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,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"
"github.com/tinkerbell/tink/internal/tlscert"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)
Expand All @@ -30,11 +30,6 @@ 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
Expand Down Expand Up @@ -66,7 +61,6 @@ 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)
Expand Down Expand Up @@ -110,7 +104,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 @@ -125,19 +118,20 @@ func NewRootCommand(config *DaemonConfig, logger log.Logger) *cobra.Command {
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)
cert, err := tlscert.Load(certDir)
if err != nil {
return err
}
grpcOpts = append(grpcOpts, grpc.Creds(credentials.NewServerTLSFromCert(cert)))
}

switch config.Backend {
case backendKubernetes:
var err error
Expand All @@ -153,6 +147,7 @@ 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,
Expand All @@ -168,7 +163,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
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.

29 changes: 29 additions & 0 deletions internal/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package client

import (
"github.com/pkg/errors"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
)

func NewClientConn(authority string, tls bool) (*grpc.ClientConn, error) {
var creds grpc.DialOption
if tls {
creds = grpc.WithTransportCredentials(credentials.NewTLS(nil))
} else {
creds = grpc.WithTransportCredentials(insecure.NewCredentials())
}

conn, err := grpc.Dial(authority,
creds,
grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor()),
grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor()),
)
if err != nil {
return nil, errors.Wrap(err, "dial tinkerbell server")
}

return conn, nil
}
2 changes: 1 addition & 1 deletion pkg/convert/workflow.go → internal/convert/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"sort"

"github.com/tinkerbell/tink/internal/workflow"
"github.com/tinkerbell/tink/pkg/apis/core/v1alpha1"
protoworkflow "github.com/tinkerbell/tink/protos/workflow"
"github.com/tinkerbell/tink/workflow"
)

func WorkflowToWorkflowContext(wf *v1alpha1.Workflow) *protoworkflow.WorkflowContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/tinkerbell/tink/internal/tests"
"github.com/tinkerbell/tink/internal/testtime"
"github.com/tinkerbell/tink/internal/workflow"
"github.com/tinkerbell/tink/pkg/apis/core/v1alpha1"
protoworkflow "github.com/tinkerbell/tink/protos/workflow"
"github.com/tinkerbell/tink/workflow"
"google.golang.org/protobuf/testing/protocmp"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var TestTime = tests.NewFrozenTimeUnix(1637361794)
var TestTime = testtime.NewFrozenTimeUnix(1637361794)

func TestWorkflowToWorkflowContext(t *testing.T) {
cases := []struct {
Expand Down
Loading

0 comments on commit 1a3d2df

Please sign in to comment.