Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1196aa2
SecretFieldClusterId to CmFieldClusterId
prakash100198 May 21, 2025
17673c3
replace secret informer with field selector to configmap informer wit…
prakash100198 May 22, 2025
405943c
CreateConfigMapObject
prakash100198 May 22, 2025
d504346
ClusterModifyEventSecretTypeKey
prakash100198 May 22, 2025
18ca4a3
DeleteConfigMap k8s util func
prakash100198 May 22, 2025
0edc8f8
correct label selector
prakash100198 May 22, 2025
28fd5f0
add extra validation in add , update and delete func
prakash100198 May 22, 2025
dce8d68
cm informer instead of secret informer for cluster
prakash100198 May 22, 2025
e1121de
develop sync
prakash100198 May 23, 2025
9a252fc
bump common lib
prakash100198 May 23, 2025
1b6fc97
bump common lib
prakash100198 May 23, 2025
c0371be
Merge branch 'develop' into rename-secret-to-cm-cluster
prakash100198 May 23, 2025
df280dc
bump common lib
prakash100198 May 23, 2025
1041940
bump common lib
prakash100198 May 23, 2025
96556fe
fix
prakash100198 May 23, 2025
68ba8f2
bump common lib
prakash100198 May 23, 2025
996f82c
bump common lib
prakash100198 May 23, 2025
60bd924
r
prakash100198 May 23, 2025
c5591ad
ClusterModifyEventCmLabelValue = "cluster-request-modify"
prakash100198 May 23, 2025
48b990c
ClusterModifyEventCmLabelValue = "type=cluster-request-modify"
prakash100198 May 23, 2025
93c5820
import label selector from commonb lib
prakash100198 May 23, 2025
5ed7eaa
import label selector from commonb lib
prakash100198 May 23, 2025
17f2964
ClusterModifyEventCmLabelKeyValue and ClusterModifyEventCmLabelValue
prakash100198 May 23, 2025
1205ee2
small fix
prakash100198 May 23, 2025
01ed8fb
small fix
prakash100198 May 23, 2025
222f1e0
add logger for ignoring cluster change event in case label not found
prakash100198 May 27, 2025
556a5a9
fix
prakash100198 May 27, 2025
d40f917
logger
prakash100198 May 27, 2025
5f0ce09
refactoring of CreateConfigMapObject
prakash100198 May 27, 2025
f3a156d
fix
prakash100198 May 27, 2025
ddb036d
Merge branch 'develop' into rename-secret-to-cm-cluster
prakash100198 May 27, 2025
323af49
bump common lib
prakash100198 May 27, 2025
b13ea5f
bump common lib
prakash100198 May 27, 2025
626bf7f
remove WithCmName and make cmname as func signature
prakash100198 May 27, 2025
2439202
code review incorporation
prakash100198 May 27, 2025
483d6a2
bump common lib
prakash100198 May 27, 2025
8a47b97
Merge branch 'develop' into rename-secret-to-cm-cluster
prakash100198 May 28, 2025
b913d2d
make
prakash100198 May 28, 2025
aa57ae9
bump common lib
prakash100198 May 28, 2025
2650af5
Merge branch 'develop' into rename-secret-to-cm-cluster
prakash100198 Jun 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions common-lib/informer/bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
package informer

const (
ClusterModifyEventSecretType = "cluster.request/modify"
ClusterActionAdd = "add"
ClusterActionUpdate = "update"
ClusterActionDelete = "delete"
SecretFieldAction = "action"
SecretFieldClusterId = "cluster_id"
ClusterModifyEventSecretType = "cluster.request/modify"
ClusterModifyEventSecretTypeKey = "type"
ClusterActionAdd = "add"
ClusterActionUpdate = "update"
ClusterActionDelete = "delete"
CmFieldAction = "action"
CmFieldClusterId = "cluster_id"
ClusterModifyEventCmLabelKeyValue = "type=devtron.ai-cluster-request-modify"
ClusterModifyEventCmLabelValue = "devtron.ai-cluster-request-modify"
)

const (
Expand Down
3 changes: 3 additions & 0 deletions common-lib/utils/k8s/K8sService.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package k8s
import (
"context"
"flag"
"github.com/devtron-labs/common-lib/utils/k8s/configMap"
"go.uber.org/zap"
"io"
batchV1 "k8s.io/api/batch/v1"
Expand Down Expand Up @@ -76,7 +77,9 @@ type K8sService interface {
PatchConfigMap(namespace string, clusterConfig *ClusterConfig, name string, data map[string]interface{}) (*v1.ConfigMap, error)
UpdateConfigMap(namespace string, cm *v1.ConfigMap, client *v12.CoreV1Client) (*v1.ConfigMap, error)
CreateConfigMap(namespace string, cm *v1.ConfigMap, client *v12.CoreV1Client) (*v1.ConfigMap, error)
CreateConfigMapObject(name, namespace string, client *v12.CoreV1Client, opts ...configMap.ConfigMapOption) (*v1.ConfigMap, error)
GetConfigMap(namespace string, name string, client *v12.CoreV1Client) (*v1.ConfigMap, error)
DeleteConfigMap(namespace string, name string, client *v12.CoreV1Client) error
GetConfigMapWithCtx(ctx context.Context, namespace string, name string, client *v12.CoreV1Client) (*v1.ConfigMap, error)
GetNsIfExists(namespace string, client *v12.CoreV1Client) (ns *v1.Namespace, exists bool, err error)
CreateNsIfNotExists(namespace string, clusterConfig *ClusterConfig) (ns *v1.Namespace, nsCreated bool, err error)
Expand Down
22 changes: 22 additions & 0 deletions common-lib/utils/k8s/K8sUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/devtron-labs/common-lib/utils"
http2 "github.com/devtron-labs/common-lib/utils/http"
"github.com/devtron-labs/common-lib/utils/k8s/commonBean"
"github.com/devtron-labs/common-lib/utils/k8s/configMap"
"io"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -237,6 +238,27 @@ func (impl *K8sServiceImpl) CreateConfigMap(namespace string, cm *v1.ConfigMap,
}
}

func (impl *K8sServiceImpl) CreateConfigMapObject(name, namespace string, client *v12.CoreV1Client, opts ...configMap.ConfigMapOption) (*v1.ConfigMap, error) {
configMap := &v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
}
for _, option := range opts {
option(configMap)
}
return impl.CreateConfigMap(namespace, configMap, client)
}

func (impl *K8sServiceImpl) DeleteConfigMap(namespace string, name string, client *v12.CoreV1Client) error {
err := client.ConfigMaps(namespace).Delete(context.Background(), name, metav1.DeleteOptions{})
if err != nil {
impl.logger.Errorw("error in deleting cm", "namespace", namespace, "err", err)
return err
}
return nil
}

func (impl *K8sServiceImpl) UpdateConfigMap(namespace string, cm *v1.ConfigMap, client *v12.CoreV1Client) (*v1.ConfigMap, error) {
cm, err := client.ConfigMaps(namespace).Update(context.Background(), cm, metav1.UpdateOptions{})
if err != nil {
Expand Down
43 changes: 43 additions & 0 deletions common-lib/utils/k8s/configMap/Options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package configMap

import (
v1 "k8s.io/api/core/v1"
)

type ConfigMapOption func(*v1.ConfigMap)

// WithLabels adds labels to a ConfigMap
func WithLabels(labels map[string]string) ConfigMapOption {
return func(cm *v1.ConfigMap) {
if labels != nil && len(labels) > 0 {
cm.ObjectMeta.Labels = labels
}
}
}

// WithAnnotations adds annotations to a ConfigMap
func WithAnnotations(annotations map[string]string) ConfigMapOption {
return func(cm *v1.ConfigMap) {
if annotations != nil && len(annotations) > 0 {
cm.ObjectMeta.Annotations = annotations
}
}
}

// WithData adds string data to a ConfigMap
func WithData(data map[string]string) ConfigMapOption {
return func(cm *v1.ConfigMap) {
if data != nil && len(data) > 0 {
cm.Data = data
}
}
}

// WithBinaryData adds binary data to a ConfigMap
func WithBinaryData(binaryData map[string][]byte) ConfigMapOption {
return func(cm *v1.ConfigMap) {
if binaryData != nil && len(binaryData) > 0 {
cm.BinaryData = binaryData
}
}
}
Loading
Loading