Files
troubleshoot/pkg/specs/secrets.go
Evans Mungai ff03bfa9cd chore: make spec loaders internal APIs (#1313)
* chore: make specs an internal package

* Some minor improvements

* Use LoadClusterSpecs in support bundle implementation

* Remove change accidentally committed

* Use LoadFromCLIArgs in preflight CLI implementation

* Update comment

* Fix edge case where the label selector is an empty string

* Fix failing test
2023-08-30 14:02:30 +01:00

34 lines
1.2 KiB
Go

package specs
import (
"context"
"github.com/pkg/errors"
specs "github.com/replicatedhq/troubleshoot/internal/specs"
"github.com/replicatedhq/troubleshoot/pkg/k8sutil"
"k8s.io/client-go/kubernetes"
)
// LoadFromSecret reads data from a secret in the cluster
// Deprecated: Remove in a future version (v1.0). Future loader functions
// will be created
func LoadFromSecret(namespace string, secretName string, key string) ([]byte, error) {
config, err := k8sutil.GetRESTConfig()
if err != nil {
return nil, errors.Wrap(err, "failed to convert kube flags to rest config")
}
client, err := kubernetes.NewForConfig(config)
if err != nil {
return nil, errors.Wrap(err, "failed to convert create k8s client")
}
return specs.LoadFromSecret(context.TODO(), client, namespace, secretName, key)
}
// LoadFromSecretMatchingLabel reads data from a secret in the cluster using a label selector
// Deprecated: Remove in a future version (v1.0). Future loader functions will be created
func LoadFromSecretMatchingLabel(client kubernetes.Interface, labelSelector string, namespace string, key string) ([]string, error) {
return specs.LoadFromSecretMatchingLabel(context.TODO(), client, labelSelector, namespace, key)
}