diff --git a/clients/dynamic/dynamic.go b/clients/dynamic/dynamic.go index b46ec3ec..a15168af 100644 --- a/clients/dynamic/dynamic.go +++ b/clients/dynamic/dynamic.go @@ -104,7 +104,9 @@ func (c *ResourceClient) Create(ctx context.Context, obj *unstructured.Unstructu if needsCleanup(obj) { c.ts.RegisterCleanupFunc(func() error { - err := c.Delete(context.TODO(), unstructuredObj.GetName(), metav1.DeleteOptions{}, subresources...) + // Using this policy avoids a flood of useless warnings on test logs. + orphanPolicy := metav1.DeletePropagationOrphan + err := c.Delete(context.TODO(), unstructuredObj.GetName(), metav1.DeleteOptions{PropagationPolicy: &orphanPolicy}, subresources...) if errors.IsNotFound(err) { return nil } diff --git a/clients/rancher/v1/client.go b/clients/rancher/v1/client.go index 922f88d9..f2b7be49 100644 --- a/clients/rancher/v1/client.go +++ b/clients/rancher/v1/client.go @@ -138,10 +138,6 @@ func (c *Client) ProxyDownstream(clusterID string) (*Client, error) { updatedOpts.URL = proxyHost baseClient, err := clientbase.NewAPIClient(&updatedOpts) - if err != nil { - return nil, err - } - if err != nil { return nil, fmt.Errorf("failed creating Proxy Client. Backoff error: %v", err) } @@ -231,9 +227,7 @@ func (c *SteveClient) ListAll(params url.Values) (*SteveCollection, error) { resp = next resp.Data = data } - if err != nil { - return resp, err - } + return resp, err } @@ -387,9 +381,7 @@ func (c *NamespacedSteveClient) ListAll(params url.Values) (*SteveCollection, er resp = next resp.Data = data } - if err != nil { - return resp, err - } + return resp, err } diff --git a/extensions/kubeapi/secrets/create.go b/extensions/kubeapi/secrets/create.go index 720e6ab2..39f89adf 100644 --- a/extensions/kubeapi/secrets/create.go +++ b/extensions/kubeapi/secrets/create.go @@ -33,3 +33,13 @@ func CreateSecretWithTemplate(client *rancher.Client, clusterID string, secretTe return createdSecret, nil } + +func UpdateSecretWithTemplate(client *rancher.Client, clusterID string, secretTemplate *corev1.Secret) error { + clusterContext, err := extclusterapi.GetClusterWranglerContext(client, clusterID) + if err != nil { + return fmt.Errorf("failed to get cluster context: %w", err) + } + + _, err = clusterContext.Core.Secret().Update(secretTemplate) + return err +} diff --git a/pkg/config/config.go b/pkg/config/config.go index c9758722..9d21cf53 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -6,6 +6,7 @@ import ( "os" "github.com/creasty/defaults" + "github.com/sirupsen/logrus" "sigs.k8s.io/yaml" ) @@ -18,6 +19,7 @@ func LoadConfig(key string, config interface{}) { configPath := os.Getenv(ConfigEnvironmentKey) if configPath == "" { + logrus.Infof("No config file path provided via %s env var", ConfigEnvironmentKey) yaml.Unmarshal([]byte("{}"), config) return } @@ -33,7 +35,10 @@ func LoadConfig(key string, config interface{}) { panic(err) } - scoped := all[key] + scoped, ok := all[key] + if !ok { + logrus.Infof("Key %s not present in provided config", key) + } scopedString, err := yaml.Marshal(scoped) if err != nil { panic(err) diff --git a/pkg/config/operations/operations.go b/pkg/config/operations/operations.go index 21b48e8e..68f7feff 100644 --- a/pkg/config/operations/operations.go +++ b/pkg/config/operations/operations.go @@ -2,9 +2,9 @@ package operations import ( "encoding/json" - "errors" "fmt" + "github.com/sirupsen/logrus" "sigs.k8s.io/yaml" ) @@ -42,7 +42,7 @@ func GetValue(keyPath []string, searchMap map[string]any) (any, error) { if len(keyPath) == 1 { keypathvalues, ok := searchMap[keyPath[0]] if !ok { - err = errors.New(fmt.Sprintf("expected key does not exist: %s", keyPath[0])) + err = fmt.Errorf("expected key does not exist: %s", keyPath[0]) } return keypathvalues, err } else { @@ -66,7 +66,11 @@ func GetValue(keyPath []string, searchMap map[string]any) (any, error) { // LoadObjectFromMap unmarshals a specific key's value into an object func LoadObjectFromMap(key string, config map[string]any, object any) { - keyConfig := config[key] + keyConfig, ok := config[key] + if !ok { + logrus.Infof("Key %s not present in provided config", key) + } + scopedString, err := yaml.Marshal(keyConfig) if err != nil { panic(err)