-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
k8sops package added for deployment worker
- Loading branch information
1 parent
5b3af09
commit f4983fe
Showing
1 changed file
with
37 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package k8sops | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/intelops/go-common/logging" | ||
"github.com/kube-tarian/kad/capten/common-pkg/k8s" | ||
) | ||
|
||
func CreateUpdateConfigmap(ctx context.Context, log logging.Logger, namespace, cmName string, data map[string]string, k8sClient *k8s.K8SClient) error { | ||
err := k8sClient.CreateNamespace(ctx, namespace) | ||
if err != nil { | ||
log.Errorf("Creation of namespace failed: %v", err) | ||
return fmt.Errorf("creation of namespace faield") | ||
} | ||
cm, err := k8sClient.GetConfigmap(ctx, namespace, cmName) | ||
if err != nil { | ||
log.Infof("plugin configmap %s not found", cmName) | ||
err = k8sClient.CreateConfigmap(ctx, namespace, cmName, data, map[string]string{}) | ||
if err != nil { | ||
return fmt.Errorf("failed to create configmap %v", cmName) | ||
} | ||
} | ||
// configmap found but data is empty/nil | ||
if cm == nil { | ||
cm = map[string]string{} | ||
} | ||
for k, v := range data { | ||
cm[k] = v | ||
} | ||
err = k8sClient.UpdateConfigmap(ctx, namespace, cmName, cm) | ||
if err != nil { | ||
return fmt.Errorf("plugin configmap %s not found", cmName) | ||
} | ||
return nil | ||
} |