From 620c3f1fb49c6b91deec18993d5b135c0613e67f Mon Sep 17 00:00:00 2001 From: Gireesh Naidu Date: Thu, 16 Nov 2023 12:37:35 +0530 Subject: [PATCH 1/3] update common-lib version with for event listing fix --- go.mod | 2 +- go.sum | 2 ++ .../common-lib/utils/k8s/K8sUtil.go | 20 ++++++++++++++++--- .../devtron-labs/common-lib/utils/k8s/bean.go | 5 +++-- .../common-lib/utils/k8s/commonBean/bean.go | 12 +++++++++++ vendor/modules.txt | 3 +-- 6 files changed, 36 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 74f7e7859f3..c2587b3963a 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.8.0 github.com/devtron-labs/authenticator v0.4.31 - github.com/devtron-labs/common-lib v0.0.5 + github.com/devtron-labs/common-lib v0.0.7-0.20231116065433-cb0da4b34b69 github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2 github.com/evanphx/json-patch v5.6.0+incompatible github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 diff --git a/go.sum b/go.sum index 61dbe234772..10bb8e59e08 100644 --- a/go.sum +++ b/go.sum @@ -295,6 +295,8 @@ github.com/devtron-labs/authenticator v0.4.31 h1:CEMLek3JnMuH9ULsC6BHNJr+NiyGzBd github.com/devtron-labs/authenticator v0.4.31/go.mod h1:ozNfT8WcruiSgnUbyp48WVfc41++W6xYXhKFp67lNTU= github.com/devtron-labs/common-lib v0.0.5 h1:Y9FqAWhpdbIuRVLp75adSK55sh3H/rOt4zgPrvgLH4Q= github.com/devtron-labs/common-lib v0.0.5/go.mod h1:x6OdUIo2z9kxXtBfz7fJEfD4s8kiAtEmlApozOf7ECM= +github.com/devtron-labs/common-lib v0.0.7-0.20231116065433-cb0da4b34b69 h1:nt7l476p/gwTeJ9RxU5bJ/0fJyUkx2bdIZVnyQLwtHI= +github.com/devtron-labs/common-lib v0.0.7-0.20231116065433-cb0da4b34b69/go.mod h1:x6OdUIo2z9kxXtBfz7fJEfD4s8kiAtEmlApozOf7ECM= github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2 h1:/IEIsJTxDZ3hv8uOoCaqdWCXqcv7nCAgX9AP/v84dUY= github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2/go.mod h1:l85jxWHlcSo910hdUfRycL40yGzC6glE93V1sVxVPto= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= diff --git a/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go b/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go index d26f2531925..866ff95d654 100644 --- a/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go +++ b/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go @@ -440,6 +440,15 @@ func (impl K8sUtil) GetK8sInClusterConfigAndDynamicClients() (*rest.Config, *htt return restConfig, k8sHttpClient, dynamicClientSet, nil } +func (impl K8sUtil) GetK8sDynamicClient(restConfig *rest.Config, k8sHttpClient *http.Client) (dynamic.Interface, error) { + dynamicClientSet, err := dynamic.NewForConfigAndClient(restConfig, k8sHttpClient) + if err != nil { + impl.logger.Errorw("error in getting client set by rest config for in cluster", "err", err) + return nil, err + } + return dynamicClientSet, nil +} + func (impl K8sUtil) GetK8sConfigAndClients(clusterConfig *ClusterConfig) (*rest.Config, *http.Client, *kubernetes.Clientset, error) { restConfig, err := impl.GetRestConfigByCluster(clusterConfig) if err != nil { @@ -1108,7 +1117,7 @@ func (impl K8sUtil) ListEvents(restConfig *rest.Config, namespace string, groupV impl.logger.Errorw("error in getting dynamic interface for resource", "err", err, "resource", name) return nil, err } - groupVersionKind.Kind = "List" + if !namespaced { namespace = "default" } @@ -1124,10 +1133,10 @@ func (impl K8sUtil) ListEvents(restConfig *rest.Config, namespace string, groupV } eventsIf := eventsClient.Events(namespace) eventsExp := eventsIf.(v12.EventExpansion) - fieldSelector := eventsExp.GetFieldSelector(pointer.StringPtr(name), pointer.StringPtr(namespace), nil, nil) + fieldSelector := eventsExp.GetFieldSelector(pointer.StringPtr(name), pointer.StringPtr(namespace), pointer.StringPtr(groupVersionKind.Kind), nil) listOptions := metav1.ListOptions{ TypeMeta: metav1.TypeMeta{ - Kind: groupVersionKind.Kind, + Kind: "List", APIVersion: groupVersionKind.GroupVersion().String(), }, FieldSelector: fieldSelector.String(), @@ -1325,6 +1334,11 @@ func (impl K8sUtil) GetApiResources(restConfig *rest.Config, includeOnlyVerb str Version: version, Kind: apiResourceFromK8s.Kind, }, + Gvr: schema.GroupVersionResource{ + Group: group, + Version: version, + Resource: apiResourceFromK8s.Name, + }, Namespaced: apiResourceFromK8s.Namespaced, }) } diff --git a/vendor/github.com/devtron-labs/common-lib/utils/k8s/bean.go b/vendor/github.com/devtron-labs/common-lib/utils/k8s/bean.go index ec46ac4b74e..8999c5ad026 100644 --- a/vendor/github.com/devtron-labs/common-lib/utils/k8s/bean.go +++ b/vendor/github.com/devtron-labs/common-lib/utils/k8s/bean.go @@ -65,8 +65,9 @@ type GetAllApiResourcesResponse struct { } type K8sApiResource struct { - Gvk schema.GroupVersionKind `json:"gvk"` - Namespaced bool `json:"namespaced"` + Gvk schema.GroupVersionKind `json:"gvk"` + Gvr schema.GroupVersionResource `json:"gvr"` + Namespaced bool `json:"namespaced"` } type ApplyResourcesRequest struct { diff --git a/vendor/github.com/devtron-labs/common-lib/utils/k8s/commonBean/bean.go b/vendor/github.com/devtron-labs/common-lib/utils/k8s/commonBean/bean.go index c05ac1734ac..87e6124e10f 100644 --- a/vendor/github.com/devtron-labs/common-lib/utils/k8s/commonBean/bean.go +++ b/vendor/github.com/devtron-labs/common-lib/utils/k8s/commonBean/bean.go @@ -74,7 +74,9 @@ const K8sClusterResourceCellKey = "cells" const K8sClusterResourceColumnDefinitionKey = "columnDefinitions" const K8sClusterResourceObjectKey = "object" +const K8sClusterResourceGroupKey = "group" const K8sClusterResourceKindKey = "kind" +const K8sClusterResourceVersionKey = "version" const K8sClusterResourceApiVersionKey = "apiVersion" const K8sClusterResourceReplicationControllerKind = "ReplicationController" @@ -86,6 +88,16 @@ const V1VERSION = "v1" const BatchGroup = "batch" const AppsGroup = "apps" +const ( + K8sResourceColumnDefinitionName = "Name" + K8sResourceColumnDefinitionSyncStatus = "Sync Status" + K8sResourceColumnDefinitionHealthStatus = "Health Status" + K8sClusterResourceStatusKey = "status" + K8sClusterResourceHealthKey = "health" + K8sClusterResourceResourcesKey = "resources" + K8sClusterResourceSyncKey = "sync" +) + var KindVsChildrenGvk = map[string][]schema.GroupVersionKind{ DeploymentKind: append(make([]schema.GroupVersionKind, 0), schema.GroupVersionKind{Group: AppsGroup, Version: V1VERSION, Kind: ReplicaSetKind}, schema.GroupVersionKind{Version: V1VERSION, Kind: PodKind}), K8sClusterResourceRolloutKind: append(make([]schema.GroupVersionKind, 0), schema.GroupVersionKind{Group: AppsGroup, Version: V1VERSION, Kind: ReplicaSetKind}, schema.GroupVersionKind{Version: V1VERSION, Kind: PodKind}), diff --git a/vendor/modules.txt b/vendor/modules.txt index 6812cf4a4ff..9da6667c0d3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -349,7 +349,7 @@ github.com/devtron-labs/authenticator/jwt github.com/devtron-labs/authenticator/middleware github.com/devtron-labs/authenticator/oidc github.com/devtron-labs/authenticator/password -# github.com/devtron-labs/common-lib v0.0.5 +# github.com/devtron-labs/common-lib v0.0.7-0.20231116065433-cb0da4b34b69 ## explicit; go 1.20 github.com/devtron-labs/common-lib/blob-storage github.com/devtron-labs/common-lib/pubsub-lib @@ -872,7 +872,6 @@ github.com/robfig/cron/v3 github.com/russross/blackfriday # github.com/samber/lo v1.38.1 ## explicit; go 1.18 -github.com/samber/lo # github.com/satori/go.uuid v1.2.0 ## explicit github.com/satori/go.uuid From 2866d3ad7fb3e35cfae520d3b2f6b732366d577a Mon Sep 17 00:00:00 2001 From: Gireesh Naidu Date: Thu, 16 Nov 2023 13:11:13 +0530 Subject: [PATCH 2/3] common-lib version update --- go.mod | 2 +- go.sum | 4 ++++ vendor/modules.txt | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index c2587b3963a..c653abe6b1e 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.8.0 github.com/devtron-labs/authenticator v0.4.31 - github.com/devtron-labs/common-lib v0.0.7-0.20231116065433-cb0da4b34b69 + github.com/devtron-labs/common-lib v0.0.7-0.20231116073034-de159815f217 github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2 github.com/evanphx/json-patch v5.6.0+incompatible github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 diff --git a/go.sum b/go.sum index 10bb8e59e08..f418506a108 100644 --- a/go.sum +++ b/go.sum @@ -295,8 +295,12 @@ github.com/devtron-labs/authenticator v0.4.31 h1:CEMLek3JnMuH9ULsC6BHNJr+NiyGzBd github.com/devtron-labs/authenticator v0.4.31/go.mod h1:ozNfT8WcruiSgnUbyp48WVfc41++W6xYXhKFp67lNTU= github.com/devtron-labs/common-lib v0.0.5 h1:Y9FqAWhpdbIuRVLp75adSK55sh3H/rOt4zgPrvgLH4Q= github.com/devtron-labs/common-lib v0.0.5/go.mod h1:x6OdUIo2z9kxXtBfz7fJEfD4s8kiAtEmlApozOf7ECM= +github.com/devtron-labs/common-lib v0.0.6 h1:pbFER0Op9hWQXWRlmQGF8XMctG05tj2eWhUw+lhjPS0= +github.com/devtron-labs/common-lib v0.0.6/go.mod h1:x6OdUIo2z9kxXtBfz7fJEfD4s8kiAtEmlApozOf7ECM= github.com/devtron-labs/common-lib v0.0.7-0.20231116065433-cb0da4b34b69 h1:nt7l476p/gwTeJ9RxU5bJ/0fJyUkx2bdIZVnyQLwtHI= github.com/devtron-labs/common-lib v0.0.7-0.20231116065433-cb0da4b34b69/go.mod h1:x6OdUIo2z9kxXtBfz7fJEfD4s8kiAtEmlApozOf7ECM= +github.com/devtron-labs/common-lib v0.0.7-0.20231116073034-de159815f217 h1:tFi7BDTVDlyQmTTKnAzEBH0cB6dCpvsC34Cl6pyiUWg= +github.com/devtron-labs/common-lib v0.0.7-0.20231116073034-de159815f217/go.mod h1:x6OdUIo2z9kxXtBfz7fJEfD4s8kiAtEmlApozOf7ECM= github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2 h1:/IEIsJTxDZ3hv8uOoCaqdWCXqcv7nCAgX9AP/v84dUY= github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2/go.mod h1:l85jxWHlcSo910hdUfRycL40yGzC6glE93V1sVxVPto= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= diff --git a/vendor/modules.txt b/vendor/modules.txt index 9da6667c0d3..b3b6d6a3e02 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -349,7 +349,7 @@ github.com/devtron-labs/authenticator/jwt github.com/devtron-labs/authenticator/middleware github.com/devtron-labs/authenticator/oidc github.com/devtron-labs/authenticator/password -# github.com/devtron-labs/common-lib v0.0.7-0.20231116065433-cb0da4b34b69 +# github.com/devtron-labs/common-lib v0.0.7-0.20231116073034-de159815f217 ## explicit; go 1.20 github.com/devtron-labs/common-lib/blob-storage github.com/devtron-labs/common-lib/pubsub-lib From 72c2fd96030cc922fecab14bf1b6021ee335c698 Mon Sep 17 00:00:00 2001 From: Gireesh Naidu Date: Thu, 16 Nov 2023 13:13:18 +0530 Subject: [PATCH 3/3] query fix --- internal/sql/repository/CiArtifactsListingQueryBuilder.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/sql/repository/CiArtifactsListingQueryBuilder.go b/internal/sql/repository/CiArtifactsListingQueryBuilder.go index dea4a2cd784..cddec86121b 100644 --- a/internal/sql/repository/CiArtifactsListingQueryBuilder.go +++ b/internal/sql/repository/CiArtifactsListingQueryBuilder.go @@ -10,9 +10,9 @@ const EmptyLikeRegex = "%%" func BuildQueryForParentTypeCIOrWebhook(listingFilterOpts bean.ArtifactsListFilterOptions) string { commonPaginatedQueryPart := "" - if listingFilterOpts.SearchString != EmptyLikeRegex { - commonPaginatedQueryPart = fmt.Sprintf(" cia.image LIKE '%v' ", listingFilterOpts.SearchString) - } + //if listingFilterOpts.SearchString != EmptyLikeRegex { + commonPaginatedQueryPart = fmt.Sprintf(" cia.image LIKE '%v' ", listingFilterOpts.SearchString) + //} orderByClause := " ORDER BY cia.id DESC" limitOffsetQueryPart := fmt.Sprintf(" LIMIT %v OFFSET %v", listingFilterOpts.Limit, listingFilterOpts.Offset) finalQuery := ""