-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #273 from replicatedhq/divolgin/preflight
Allow preflight spec to be loaded from a secret
- Loading branch information
Showing
8 changed files
with
86 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package k8sutil | ||
|
||
import ( | ||
flag "github.com/spf13/pflag" | ||
"k8s.io/cli-runtime/pkg/genericclioptions" | ||
"k8s.io/client-go/rest" | ||
) | ||
|
||
var ( | ||
kubernetesConfigFlags *genericclioptions.ConfigFlags | ||
) | ||
|
||
func init() { | ||
kubernetesConfigFlags = genericclioptions.NewConfigFlags(false) | ||
} | ||
|
||
func AddFlags(flags *flag.FlagSet) { | ||
kubernetesConfigFlags.AddFlags(flags) | ||
} | ||
|
||
func GetRESTConfig() (*rest.Config, error) { | ||
return kubernetesConfigFlags.ToRESTConfig() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package specs | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/replicatedhq/troubleshoot/pkg/k8sutil" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
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") | ||
} | ||
|
||
foundSecret, err := client.CoreV1().Secrets(namespace).Get(context.TODO(), secretName, metav1.GetOptions{}) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to get secret") | ||
} | ||
|
||
spec, ok := foundSecret.Data[key] | ||
if !ok { | ||
return nil, errors.Errorf("spec not found in secret %s", secretName) | ||
} | ||
|
||
return spec, nil | ||
} |