func (r *PostgreSqlReconciler) GetGCPCredentialsFromSecret(secretList kubeApiV1.SecretList, namespace string, ctx context.Context, instance *sqlv1alpha1.PostgreSql, dir string) error {
	var filePath string
	err := r.List(ctx, &secretList, client.InNamespace(namespace))
	if err != nil {
		errMsg := fmt.Sprintf("unable to list secret in namespace  %v", instance.Namespace)
		r.Log.Error(err, errMsg)
	}
	isFound := false
	for _, k := range secretList.Items {
		for obj := range k.Data {
			if !strings.Contains(obj, ".json") {
				continue
			}
			isFound = true
			value := k.Data[obj]
			filePath = filepath.Join(dir + "/" + obj)
			if len(value) != 0 {
				if err := ioutil.WriteFile(filePath, value, 0600); err != nil {
					return fmt.Errorf("failed to write serviceAccount json key to file %v", err)
				}
				os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", filePath)
			}
		}
	}
	if !isFound {
		r.Recorder.Eventf(instance, kubeApiV1.EventTypeWarning, "KeyNotFound", "unable to find valid GCP serviceAccount json key in namespace %q", namespace)
		return fmt.Errorf("json secret key not found in namespace %v", namespace)
	}
	return nil
}
//GetGCPCredentialsFromSecret fetch gcp serviceAccount from secret
GetGCPCredentialsFromSecret fetch gcp serviceAccount from secret
// GetGCPCredentialsFromSecret fetch gcp serviceAccount from secret
func (r *PostgreSqlReconciler) GetGCPCredentialsFromSecret(secretList kubeApiV1.SecretList, namespace string, ctx context.Context, instance *sqlv1alpha1.PostgreSql, dir string) error {
	var filePath string
	err := r.List(ctx, &secretList, client.InNamespace(namespace))
	if err != nil {
		errMsg := fmt.Sprintf("unable to list secret in namespace  %v", instance.Namespace)
		r.Log.Error(err, errMsg)
	}
	isFound := false
	for _, k := range secretList.Items {
		for obj := range k.Data {
			if !strings.Contains(obj, ".json") {
				continue
			}
			isFound = true
			value := k.Data[obj]
			filePath = filepath.Join(dir + "/" + obj)
			if len(value) != 0 {
				if err := ioutil.WriteFile(filePath, value, 0600); err != nil {
					return fmt.Errorf("failed to write serviceAccount json key to file %v", err)
				}
				os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", filePath)
			}
		}
	}
	if !isFound {
		r.Recorder.Eventf(instance, kubeApiV1.EventTypeWarning, "KeyNotFound", "unable to find valid GCP serviceAccount json key in namespace %q", namespace)
		return fmt.Errorf("json secret key not found in namespace %v", namespace)
	}
	return nil
}
func ( r * PostgreSqlReconciler ) GetGCPCredentialsFromSecret ( secretList kubeApiV1 . SecretList , namespace string , ctx context . Context , instance * sqlv1alpha1 . PostgreSql , dir string ) error { var filePath string err := r . List ( ctx , & secretList , client . InNamespace ( namespace ) ) if err != nil { errMsg := fmt . Sprintf ( " " , instance . Namespace ) r . Log . Error ( err , errMsg ) } isFound := false for _ , k := range secretList . Items { for obj := range k . Data { if ! strings . Contains ( obj , " " ) { continue } isFound = true value := k . Data [ obj ] filePath = filepath . Join ( dir + " " + obj ) if len ( value ) != 0 { if err := ioutil . WriteFile ( filePath , value , 0600 ) ; err != nil { return fmt . Errorf ( " " , err ) } os . Setenv ( " " , filePath ) } } } if ! isFound { r . Recorder . Eventf ( instance , kubeApiV1 . EventTypeWarning , " " , " " , namespace ) return fmt . Errorf ( " " , namespace ) } return nil }
GetGCPCredentialsFromSecret fetch gcp serviceAccount from secret
GetGCPCredentialsFromSecret fetch gcp serviceAccount from secret