diff --git a/Makefile b/Makefile index bfbb57abe1..f71238e065 100644 --- a/Makefile +++ b/Makefile @@ -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… @@ -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… diff --git a/pkg/agent/storage/legacy.go b/pkg/agent/storage/legacy.go index db0e9e6fd8..d0b698284b 100644 --- a/pkg/agent/storage/legacy.go +++ b/pkg/agent/storage/legacy.go @@ -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 diff --git a/pkg/agent/storage/storage.go b/pkg/agent/storage/storage.go index d93fdd6c62..e55c303fe6 100644 --- a/pkg/agent/storage/storage.go +++ b/pkg/agent/storage/storage.go @@ -9,7 +9,6 @@ import ( "io/fs" "os" "path/filepath" - "strings" "sync" "time" @@ -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 { @@ -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 diff --git a/pkg/common/util/k8sClient.go b/pkg/common/util/k8sClient.go index 648fb722bb..7a84ce8dec 100644 --- a/pkg/common/util/k8sClient.go +++ b/pkg/common/util/k8sClient.go @@ -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 }