Skip to content

Commit

Permalink
Remove cacher backend
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Doherty <[email protected]>
  • Loading branch information
chrisdoherty4 committed Oct 24, 2022
1 parent 7328b18 commit 3ac2c99
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 491 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: "1.17"
go-version: "1.19"
- name: goimports
run: go get golang.org/x/tools/cmd/goimports && goimports -d . | (! grep .)
run: go install golang.org/x/tools/cmd/goimports@latest && goimports -d . | (! grep .)
- name: go vet
run: go vet ./...
- name: lint
Expand Down
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ linters-settings:
- name: waitgroup-by-value

staticcheck:
go: "1.17.5"
go: "1.19"

unused:
go: "1.17.5"
go: "1.19"

output:
sort-results: true
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ endif
# BEGIN: lint-install --dockerfile=warn .
# http://github.com/tinkerbell/lint-install

GOLINT_VERSION ?= v1.42.0
HADOLINT_VERSION ?= v2.7.0
GOLINT_VERSION ?= v1.50.1
HADOLINT_VERSION ?= v2.10.0

YAMLLINT_VERSION ?= 1.26.3
YAMLLINT_VERSION ?= 1.28.0
LINT_OS := $(shell uname)
LINT_ARCH := $(shell uname -m)
LINT_ROOT := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
Expand Down
2 changes: 1 addition & 1 deletion cmd/hegel/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.17.5-alpine AS builder
FROM golang:1.19-alpine AS builder

ARG GOPROXY=https://proxy.golang.org,direct

Expand Down
5 changes: 0 additions & 5 deletions cmd/hegel/root_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Each CLI argument has a corresponding environment variable in the form of the CL
the flag and environment variable form are specified, the flag form takes precedence.
Examples
--factility HEGEL_FACILITY
--http-port HEGEL_HTTP_PORT
--http-custom-endpoints HEGEL_HTTP_CUSTOM_ENDPOINTS
`
Expand All @@ -41,7 +40,6 @@ const EnvNamePrefix = "HEGEL"
// RootCommandOptions encompasses all the configurability of the RootCommand.
type RootCommandOptions struct {
DataModel string `mapstructure:"data-model"`
Facility string `mapstructure:"facility"`
TrustedProxies string `mapstructure:"trusted-proxies"`

HTTPCustomEndpoints string `mapstructure:"http-custom-endpoints"`
Expand Down Expand Up @@ -112,7 +110,6 @@ func (c *RootCommand) Run(cmd *cobra.Command, _ []string) error {

hardwareClient, err := hardware.NewClient(hardware.ClientConfig{
Model: c.Opts.GetDataModel(),
Facility: c.Opts.Facility,
KubeAPI: c.Opts.KubernetesAPIURL,
Kubeconfig: c.Opts.Kubeconfig,
KubeNamespace: c.Opts.KubeNamespace,
Expand Down Expand Up @@ -145,9 +142,7 @@ func (c *RootCommand) Run(cmd *cobra.Command, _ []string) error {
}

func (c *RootCommand) configureFlags() error {
// Alphabetically ordereed
c.Flags().String("data-model", string(datamodel.TinkServer), "The back-end data source: [\"1\", \"kubernetes\"] (1 indicates tink server)")
c.Flags().String("facility", "onprem", "The facility we are running in (mostly to connect to cacher)")

c.Flags().String("http-custom-endpoints", `{"/metadata":".metadata.instance"}`, "JSON encoded object specifying custom endpoint => metadata mappings")
c.Flags().Int("http-port", 50061, "Port to listen on for HTTP requests")
Expand Down
1 change: 0 additions & 1 deletion datamodel/datamodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package datamodel
type DataModel string

const (
Cacher DataModel = ""
TinkServer DataModel = "1"
Kubernetes DataModel = "kubernetes"
)
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/tinkerbell/hegel

go 1.17
go 1.19

require (
github.com/equinix-labs/otel-init-go v0.0.4
Expand All @@ -9,7 +9,6 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/itchyny/gojq v0.11.0
github.com/oklog/run v1.1.0
github.com/packethost/cacher v0.0.0-20211110202753-9b918bf0fe6d
github.com/packethost/pkg v0.0.0-20211110202003-387414657e83
github.com/packethost/xff v0.0.0-20190305172552-d3e9190c41b3
github.com/pkg/errors v0.9.1
Expand Down
234 changes: 0 additions & 234 deletions go.sum

Large diffs are not rendered by default.

98 changes: 0 additions & 98 deletions hardware/cacher.go

This file was deleted.

37 changes: 2 additions & 35 deletions hardware/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package hardware
import (
"context"

cacher "github.com/packethost/cacher/client"
"github.com/pkg/errors"
"github.com/tinkerbell/hegel/datamodel"
tink "github.com/tinkerbell/tink/client"
Expand All @@ -16,10 +15,6 @@ type Client interface {

// ByIP retrieves hardware data by its IP address.
ByIP(ctx context.Context, ip string) (Hardware, error)

// Watch creates a subscription to a hardware identified by id such that updates to the hardware data are
// pushed to the stream.
Watch(ctx context.Context, id string) (Watcher, error)
}

// Hardware is the interface for Cacher/Tink hardware types.
Expand All @@ -28,21 +23,12 @@ type Hardware interface {
ID() (string, error)
}

// Watcher is the interface for Cacher/Tink watch client types.
type Watcher interface {
Recv() (Hardware, error)
}

// ClientConfig is the configuration used by the NewClient func. Field requirements are based on the value of Model.
type ClientConfig struct {
// Model defines the client implementation that is constructed.
// Required.
Model datamodel.DataModel

// Facility is used by the Cache client.
// Required for datamodel.Cacher.
Facility string

// KubeAPI is the URL of the Kube API the Kubernetes client talks to.
// Optional
KubeAPI string
Expand All @@ -56,22 +42,8 @@ type ClientConfig struct {
KubeNamespace string
}

func (v ClientConfig) validate() error {
if v.Model == datamodel.Cacher {
if v.Facility == "" {
return errors.New("cacher data model: factility is required")
}
}

return nil
}

// NewClient returns a new hardware Client, configured appropriately according to the mode (Cacher or Tink) Hegel is running in.
func NewClient(config ClientConfig) (Client, error) {
if err := config.validate(); err != nil {
return nil, err
}

switch config.Model {
case datamodel.Kubernetes:
config, err := NewKubernetesClientConfig(config.Kubeconfig, config.KubeAPI, config.KubeNamespace)
Expand All @@ -93,12 +65,7 @@ func NewClient(config ClientConfig) (Client, error) {
return nil, errors.Wrap(err, "failed to create the tink client")
}
return clientTinkerbell{client: tc}, nil

default:
cc, err := cacher.New(config.Facility)
if err != nil {
return nil, errors.Wrap(err, "failed to create the cacher client")
}
return clientCacher{client: cc}, nil
}

return nil, errors.New("unknown data model")
}
6 changes: 0 additions & 6 deletions hardware/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"sync"

"github.com/pkg/errors"
tinkv1alpha1 "github.com/tinkerbell/tink/pkg/apis/core/v1alpha1"
tink "github.com/tinkerbell/tink/pkg/controllers"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -123,11 +122,6 @@ func (k *KubernetesClient) ByIP(ctx context.Context, ip string) (Hardware, error
return FromK8sTinkHardware(&hw.Items[0]), nil
}

// Watch is unimplemented.
func (k *KubernetesClient) Watch(context.Context, string) (Watcher, error) {
return nil, errors.New("kubernetes client: watch is unimplemented")
}

// KuberneteSClientConfig used by the NewKubernetesClient function family.
type KubernetesClientConfig struct {
*rest.Config
Expand Down
28 changes: 7 additions & 21 deletions hardware/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"

"github.com/packethost/cacher/protos/cacher"
"github.com/pkg/errors"
"github.com/tinkerbell/hegel/datamodel"
"github.com/tinkerbell/hegel/hardware"
Expand All @@ -27,29 +26,16 @@ func (hg HardwareClient) IsHealthy(context.Context) bool {
// Given any other IP inside the get request, ByIP will return an empty piece of hardware regardless of whether or not the IP
// actually matches the IP inside `Data`.
func (hg HardwareClient) ByIP(_ context.Context, ip string) (hardware.Hardware, error) {
switch hg.Model {
case datamodel.TinkServer:
if ip != UserIP {
return nil, errors.Errorf("received non-mock remote ip address: %v", ip)
}

hw := &hardware.Tinkerbell{}
if err := json.Unmarshal([]byte(hg.Data), hw); err != nil {
return nil, err
}

return hw, nil
default:
if ip != UserIP {
return &hardware.Cacher{}, errors.Errorf("received non-mock remote ip address: %v", ip)
}
if ip != UserIP {
return nil, errors.Errorf("received non-mock remote ip address: %v", ip)
}

return &hardware.Cacher{Hardware: &cacher.Hardware{JSON: hg.Data}}, nil
hw := &hardware.Tinkerbell{}
if err := json.Unmarshal([]byte(hg.Data), hw); err != nil {
return nil, err
}
}

func (hg HardwareClient) Watch(context.Context, string) (hardware.Watcher, error) {
return nil, nil
return hw, nil
}

const (
Expand Down
25 changes: 0 additions & 25 deletions hardware/tink.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ type clientTinkerbell struct {
client hardware.HardwareServiceClient
}

type watcherTinkerbell struct {
client hardware.HardwareService_DeprecatedWatchClient
}

// All retrieves all the pieces of hardware stored in Cacher.
func (hg clientTinkerbell) IsHealthy(ctx context.Context) bool {
_, err := hg.client.All(ctx, &hardware.Empty{})
Expand All @@ -38,18 +34,6 @@ func (hg clientTinkerbell) ByIP(ctx context.Context, ip string) (Hardware, error
return &Tinkerbell{hw}, nil
}

// Watch returns a Tink watch client on the hardware with the specified ID.
func (hg clientTinkerbell) Watch(ctx context.Context, id string) (Watcher, error) {
in := &hardware.GetRequest{
Id: id,
}
w, err := hg.client.DeprecatedWatch(ctx, in)
if err != nil {
return nil, err
}
return &watcherTinkerbell{w}, nil
}

// Export formats the piece of hardware to be returned in responses to clients.
func (hw *Tinkerbell) Export() ([]byte, error) {
return json.Marshal(tinkpkg.HardwareWrapper(*hw))
Expand All @@ -59,12 +43,3 @@ func (hw *Tinkerbell) Export() ([]byte, error) {
func (hw *Tinkerbell) ID() (string, error) {
return hw.Id, nil
}

// Recv receives a piece of hardware from the Tink watch client.
func (w *watcherTinkerbell) Recv() (Hardware, error) {
hw, err := w.client.Recv()
if err != nil {
return nil, err
}
return &Tinkerbell{hw}, nil
}
Loading

0 comments on commit 3ac2c99

Please sign in to comment.