@@ -35,6 +35,7 @@ import (
3535 "github.com/spf13/viper"
3636 spin "github.com/tj/go-spin"
3737 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
38+ "k8s.io/client-go/kubernetes"
3839)
3940
4041var (
@@ -247,6 +248,21 @@ the %s Admin Console to begin analysis.`
247248
248249func loadSpec (v * viper.Viper , arg string ) ([]byte , error ) {
249250 var err error
251+ if strings .HasPrefix (arg , "secret/" ) {
252+ // format secret/namespace-name/secret-name
253+ pathParts := strings .Split (arg , "/" )
254+ if len (pathParts ) != 3 {
255+ return nil , errors .Errorf ("path %s must have 3 components" , arg )
256+ }
257+
258+ spec , err := loadSpecFromSecret (pathParts [1 ], pathParts [2 ])
259+ if err != nil {
260+ return nil , errors .Wrap (err , "failed to get spec from secret" )
261+ }
262+
263+ return spec , nil
264+ }
265+
250266 if _ , err = os .Stat (arg ); err == nil {
251267 b , err := ioutil .ReadFile (arg )
252268 if err != nil {
@@ -258,6 +274,38 @@ func loadSpec(v *viper.Viper, arg string) ([]byte, error) {
258274 return nil , fmt .Errorf ("%s is not a URL and was not found (err %s)" , arg , err )
259275 }
260276
277+ spec , err := loadSpecFromURL (v , arg )
278+ if err != nil {
279+ return nil , errors .Wrap (err , "failed to get spec from URL" )
280+ }
281+ return spec , nil
282+ }
283+
284+ func loadSpecFromSecret (namespace string , secretName string ) ([]byte , error ) {
285+ config , err := KubernetesConfigFlags .ToRESTConfig ()
286+ if err != nil {
287+ return nil , errors .Wrap (err , "failed to convert kube flags to rest config" )
288+ }
289+
290+ client , err := kubernetes .NewForConfig (config )
291+ if err != nil {
292+ return nil , errors .Wrap (err , "failed to convert create k8s client" )
293+ }
294+
295+ foundSecret , err := client .CoreV1 ().Secrets (namespace ).Get (context .TODO (), secretName , metav1.GetOptions {})
296+ if err != nil {
297+ return nil , errors .Wrap (err , "failed to get secret" )
298+ }
299+
300+ spec , ok := foundSecret .Data ["support-bundle-spec" ]
301+ if ! ok {
302+ return nil , errors .Errorf ("spec not found in secret %s" , secretName )
303+ }
304+
305+ return spec , nil
306+ }
307+
308+ func loadSpecFromURL (v * viper.Viper , arg string ) ([]byte , error ) {
261309 for {
262310 req , err := http .NewRequest ("GET" , arg , nil )
263311 if err != nil {
0 commit comments