Skip to content

Commit

Permalink
Updated spire agent code to use existing secret
Browse files Browse the repository at this point in the history
- Updated codebase to write to existing k8s secret
- Updated makefile to pull submodules from remote repository

Signed-off-by: Vishnu Soman <[email protected]>
  • Loading branch information
vishnusomank authored and wazir-ahmed committed May 18, 2023
1 parent f2f63ff commit 24451b7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ go_build := $(go_path) go build $(go_flags) -ldflags '$(go_ldflags)' -o

bin/%: cmd/% FORCE | go-check
@echo Updating git submodules...
$(E)git submodule update --init --recursive
$(E)git submodule update --init --recursive --remote
@echo Building $@
$(E)$(go_build) $@$(exe) ./$<
@echo Building bin/k8s-sat…
Expand Down Expand Up @@ -277,7 +277,7 @@ go_build_static := $(go_path) go build $(go_flags) -ldflags '$(go_ldflags) -link

bin/static/%: cmd/% FORCE | go-check
@echo Updating git submodules...
$(E)git submodule update --init --recursive
$(E)git submodule update --init --recursive --remote
@echo Building $@
$(E)$(go_build_static) $@$(exe) ./$<
@echo Building bin/static/k8s-sat…
Expand Down
6 changes: 5 additions & 1 deletion pkg/agent/storage/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ func getLegacyDataFromK8SSecret(namespace, secretname, dataType string) ([]byte,

var timeByte, bundleByte []byte

if secret.Data == nil {
err = ErrNoData
}

if err != nil {
if strings.Contains(err.Error(), "not found") {
if errors.Is(err, ErrNotFound) || errors.Is(err, ErrNoData) {
return nil, nil, nil
}
return nil, nil, err
Expand Down
9 changes: 7 additions & 2 deletions pkg/agent/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"io/fs"
"os"
"path/filepath"
"strings"
"sync"
"time"

Expand All @@ -21,6 +20,8 @@ import (

var (
ErrNotCached = errors.New("not cached")
ErrNotFound = errors.New("not found")
ErrNoData = errors.New("no data found")
)

type Storage interface {
Expand Down Expand Up @@ -353,10 +354,14 @@ func loadDataFromK8S(namespace, secretname string) (storageData, time.Time, erro
var data storageData
secret, err := util.GetK8sSecrets(namespace, secretname)

if secret.Data == nil {
err = ErrNoData
}

var dataByte, timeByte []byte

if err != nil {
if strings.Contains(err.Error(), "not found") {
if errors.Is(err, ErrNotFound) || errors.Is(err, ErrNoData) {
return storageData{}, time.Time{}, nil
}
return storageData{}, time.Time{}, err
Expand Down
3 changes: 3 additions & 0 deletions pkg/common/util/k8sClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ func CreateK8sSecrets(namespace, secretname string, data map[string][]byte) erro
oldSec, err := GetK8sSecrets(namespace, secretname)
if err == nil {
log.WithField("secret", oldSec.Name).Info("Found k8s secret with same name. Trying to update existing secret")
if oldSec.Data == nil {
oldSec.Data = map[string][]byte{}
}
for k, value := range data {
oldSec.Data[k] = value
}
Expand Down

0 comments on commit 24451b7

Please sign in to comment.