Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b196a2c
chore: refactored k8s resource service into common-lib
Ash-exp Jun 6, 2025
96e66dc
chore: updated kubelink imports to common-lib module
Ash-exp Jun 6, 2025
3c36ae9
chore: updated kubelink vendor files
Ash-exp Jun 6, 2025
e27caff
feat: dynamic default parent gvk mapping and support for new method G…
Ash-exp Jun 7, 2025
acc49e7
chore: updated common lib method signatrues as per new definitions
Ash-exp Jun 7, 2025
44e0476
chore: exported gvr constants
Ash-exp Jun 7, 2025
ea6c0f8
chore: common-lib dependency updated to 'origin/feat/k8s-resource-rec…
Ash-exp Jun 7, 2025
64c69e6
feat: added gvr const for rollout and cronjob
Ash-exp Jun 7, 2025
e746fdc
feat: added new service const for resource optimizer
Ash-exp Jun 7, 2025
d4ba231
feat: updated ManifestResponse struct
Ash-exp Jun 9, 2025
47e1d9d
feat: updated ManifestResponse struct with pointer
Ash-exp Jun 9, 2025
ea16410
fix: import cycle issue
Ash-exp Jun 9, 2025
490dc51
fix: added omitempty to ManifestResponse.RecommendedManifest
Ash-exp Jun 10, 2025
7d0da69
chore: removed dead code flow
Ash-exp Jun 18, 2025
800a9b6
Merge remote-tracking branch 'origin/develop' into feat/k8s-resource-…
Ash-exp Jun 18, 2025
31fb9a4
chore: dependency updated to 'origin/feat/k8s-resource-recommendation'
Ash-exp Jun 18, 2025
0dc768d
Merge remote-tracking branch 'origin/develop' into feat/k8s-resource-…
Ash-exp Jul 1, 2025
436b430
chore: dependency updated to 'origin/feat/k8s-resource-recommendation'
Ash-exp Jul 1, 2025
b856901
Merge remote-tracking branch 'origin/develop' into feat/k8s-resource-…
Ash-exp Jul 2, 2025
c03dcfb
chore: dependency updated to 'origin/feat/k8s-resource-recommendation'
Ash-exp Jul 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion chart-sync/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.24.0

toolchain go1.24.3

replace github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702064426-05664fd92d8c
replace github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702071043-b85690139d15

require (
github.com/caarlos0/env v3.5.0+incompatible
Expand Down
4 changes: 2 additions & 2 deletions chart-sync/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702064426-05664fd92d8c h1:19ve9SuKcmDmEH0Q4s13xgLyK1oMdGZeMcM/B54hYN4=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702064426-05664fd92d8c/go.mod h1:/Ciy9tD9OxZOWBDPIasM448H7uvSo4+ZJiExpfwBZpA=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702071043-b85690139d15 h1:WlUiwAkOdgCMRg1pZLAEC6nx+C7MWtYn5QaJrw64eFY=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702071043-b85690139d15/go.mod h1:/Ciy9tD9OxZOWBDPIasM448H7uvSo4+ZJiExpfwBZpA=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/distribution/distribution/v3 v3.0.0 h1:q4R8wemdRQDClzoNNStftB2ZAfqOiN6UX90KJc4HjyM=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions chart-sync/vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ github.com/containerd/platforms
# github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
## explicit
github.com/davecgh/go-spew/spew
# github.com/devtron-labs/common-lib v0.19.1 => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702064426-05664fd92d8c
# github.com/devtron-labs/common-lib v0.19.1 => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702071043-b85690139d15
## explicit; go 1.24.0
github.com/devtron-labs/common-lib/constants
github.com/devtron-labs/common-lib/fetchAllEnv
Expand Down Expand Up @@ -967,4 +967,4 @@ sigs.k8s.io/structured-merge-diff/v4/value
sigs.k8s.io/yaml
sigs.k8s.io/yaml/goyaml.v2
sigs.k8s.io/yaml/goyaml.v3
# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702064426-05664fd92d8c
# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702071043-b85690139d15
2 changes: 1 addition & 1 deletion ci-runner/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.24.0

toolchain go1.24.3

replace github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702064426-05664fd92d8c
replace github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702071043-b85690139d15

require (
github.com/Knetic/govaluate v3.0.0+incompatible
Expand Down
4 changes: 2 additions & 2 deletions ci-runner/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702064426-05664fd92d8c h1:19ve9SuKcmDmEH0Q4s13xgLyK1oMdGZeMcM/B54hYN4=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702064426-05664fd92d8c/go.mod h1:/Ciy9tD9OxZOWBDPIasM448H7uvSo4+ZJiExpfwBZpA=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702071043-b85690139d15 h1:WlUiwAkOdgCMRg1pZLAEC6nx+C7MWtYn5QaJrw64eFY=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702071043-b85690139d15/go.mod h1:/Ciy9tD9OxZOWBDPIasM448H7uvSo4+ZJiExpfwBZpA=
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/cli v28.1.1+incompatible h1:eyUemzeI45DY7eDPuwUcmDyDj1pM98oD5MdSpiItp8k=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ci-runner/vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ github.com/cncf/xds/go/xds/type/v3
# github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
## explicit
github.com/davecgh/go-spew/spew
# github.com/devtron-labs/common-lib v0.19.1 => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702064426-05664fd92d8c
# github.com/devtron-labs/common-lib v0.19.1 => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702071043-b85690139d15
## explicit; go 1.24.0
github.com/devtron-labs/common-lib/blob-storage
github.com/devtron-labs/common-lib/constants
Expand Down Expand Up @@ -1194,4 +1194,4 @@ sigs.k8s.io/structured-merge-diff/v4/value
## explicit; go 1.12
sigs.k8s.io/yaml
sigs.k8s.io/yaml/goyaml.v2
# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702064426-05664fd92d8c
# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250702071043-b85690139d15
11 changes: 6 additions & 5 deletions common-lib/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ func (m ServiceName) ToString() string {
}

const (
Orchestrator ServiceName = "ORCHESTRATOR"
Kubelink ServiceName = "KUBELINK"
GitSensor ServiceName = "GITSENSOR"
Kubewatch ServiceName = "KUBEWATCH"
ImageScanner ServiceName = "IMAGE_SCANNER"
Orchestrator ServiceName = "ORCHESTRATOR"
Kubelink ServiceName = "KUBELINK"
GitSensor ServiceName = "GITSENSOR"
Kubewatch ServiceName = "KUBEWATCH"
ImageScanner ServiceName = "IMAGE_SCANNER"
ResourceOptimizer ServiceName = "RESOURCE_OPTIMIZER"
)

// metrics name constants
Expand Down
197 changes: 197 additions & 0 deletions common-lib/k8sResource/bean.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
package k8sResource

import (
k8sCommonBean "github.com/devtron-labs/common-lib/utils/k8s/commonBean"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
)

type Identifier struct {
gvk schema.GroupVersionKind
name string
namespace string
}

func NewIdentifier(name, namespace string, gvk schema.GroupVersionKind) *Identifier {
return &Identifier{
gvk: gvk,
name: name,
namespace: namespace,
}
}

func (identifier *Identifier) GetGvk() schema.GroupVersionKind {
if identifier == nil {
return schema.GroupVersionKind{}
}
return identifier.gvk
}

func (identifier *Identifier) GetName() string {
if identifier == nil {
return ""
}
return identifier.name
}

func (identifier *Identifier) GetNamespace() string {
if identifier == nil {
return ""
}
return identifier.namespace
}

type PatchRequest struct {
// TODO: Use Identifier instead of Name, Namespace, Gvk
Name string
Namespace string
Gvk *schema.GroupVersionKind
Patch string
PatchType string
}

type ParentChildGvkMapping struct {
Group string `json:"group"`
Version string `json:"version"`
Kind string `json:"kind"`
ChildObjects []ChildObjects `json:"childObjects"`
}

type ChildObjects struct {
Group string `json:"group"`
Version string `json:"version"`
Resource string `json:"resource"`
Scope meta.RESTScopeName `json:"scope"`
}

func (r ChildObjects) GetGvrAndScopeForChildObject() *k8sCommonBean.GvrAndScope {
return &k8sCommonBean.GvrAndScope{
Gvr: schema.GroupVersionResource{
Group: r.Group,
Version: r.Version,
Resource: r.Resource,
},
Scope: r.Scope,
}
}

func (r ParentChildGvkMapping) GetParentGvk() schema.GroupVersionKind {
return schema.GroupVersionKind{
Group: r.Group,
Version: r.Version,
Kind: r.Kind,
}
}

type FilterChildrenObjectsResponse struct {
pvcs []unstructured.Unstructured
manifests []*unstructured.Unstructured
}

func NewFilterChildrenObjectsResponse() *FilterChildrenObjectsResponse {
return &FilterChildrenObjectsResponse{}
}

func (resp *FilterChildrenObjectsResponse) GetPvcs() []unstructured.Unstructured {
return resp.pvcs
}

func (resp *FilterChildrenObjectsResponse) GetManifests() []*unstructured.Unstructured {
return resp.manifests
}

func (resp *FilterChildrenObjectsResponse) WithPVCs(pvcs []unstructured.Unstructured) *FilterChildrenObjectsResponse {
resp.pvcs = append(resp.pvcs, pvcs...)
return resp
}

func (resp *FilterChildrenObjectsResponse) WithManifest(manifest *unstructured.Unstructured) *FilterChildrenObjectsResponse {
if manifest == nil {
return resp
}
resp.manifests = append(resp.manifests, manifest)
return resp
}

type FilterChildrenObjectsRequest struct {
childGvk schema.GroupVersionResource
pvcs []unstructured.Unstructured
listObjects *unstructured.UnstructuredList
// TODO: Use Identifier instead of Name, Namespace, Gvk
namespace string
parentGvk schema.GroupVersionKind
parentName string
}

func (req *FilterChildrenObjectsRequest) IsChildResourceTypePVC() bool {
return req.GetParentGvk().Kind == k8sCommonBean.StatefulSetKind && req.GetChildGvk().Resource == k8sCommonBean.PersistentVolumeClaimsResourceType
}

func (req *FilterChildrenObjectsRequest) GetLoggerMetadata(keysAndValues ...any) []any {
metaData := []any{
"namespace", req.namespace,
"childGvk", req.childGvk,
"parentGvk", req.parentGvk,
"parentName", req.parentName,
}
return append(metaData, keysAndValues...)
}

func (req *FilterChildrenObjectsRequest) GetChildGvk() schema.GroupVersionResource {
return req.childGvk
}

func (req *FilterChildrenObjectsRequest) GetPvcs() []unstructured.Unstructured {
return req.pvcs
}

func (req *FilterChildrenObjectsRequest) GetListObjects() *unstructured.UnstructuredList {
return req.listObjects
}

func (req *FilterChildrenObjectsRequest) GetNamespace() string {
return req.namespace
}

func (req *FilterChildrenObjectsRequest) GetParentGvk() schema.GroupVersionKind {
return req.parentGvk
}

func (req *FilterChildrenObjectsRequest) GetParentName() string {
return req.parentName
}

func NewFilterChildrenObjectsRequest() *FilterChildrenObjectsRequest {
return &FilterChildrenObjectsRequest{}
}

func (req *FilterChildrenObjectsRequest) WithChildGvk(gvr schema.GroupVersionResource) *FilterChildrenObjectsRequest {
req.childGvk = gvr
return req
}

func (req *FilterChildrenObjectsRequest) WithPvcs(pvcs []unstructured.Unstructured) *FilterChildrenObjectsRequest {
req.pvcs = pvcs
return req
}

func (req *FilterChildrenObjectsRequest) WithListObjects(objects *unstructured.UnstructuredList) *FilterChildrenObjectsRequest {
req.listObjects = objects
return req
}

func (req *FilterChildrenObjectsRequest) WithNamespace(namespace string) *FilterChildrenObjectsRequest {
req.namespace = namespace
return req
}

func (req *FilterChildrenObjectsRequest) WithParentGvk(parentGvk schema.GroupVersionKind) *FilterChildrenObjectsRequest {
req.parentGvk = parentGvk
return req
}

func (req *FilterChildrenObjectsRequest) WithParentName(parentName string) *FilterChildrenObjectsRequest {
req.parentName = parentName
return req
}
22 changes: 22 additions & 0 deletions common-lib/k8sResource/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package k8sResource

import "github.com/caarlos0/env"

// CATEGORY=K8S_RESOURCE_SERVICE_CONFIG
type ServiceConfig struct {
ParentChildGvkMapping string `env:"PARENT_CHILD_GVK_MAPPING" envDefault:"" description:"Parent child GVK mapping for resource tree" deprecated:"false" example:""`
ChildObjectListingPageSize int64 `env:"CHILD_OBJECT_LISTING_PAGE_SIZE" envDefault:"1000" description:"Resource tree child object listing page size" deprecated:"false" example:"100"`
}

func GetK8sResourceConfig() (*ServiceConfig, error) {
cfg := &ServiceConfig{}
err := env.Parse(cfg)
if err != nil {
return cfg, err
}
if cfg.ChildObjectListingPageSize <= 10 {
// set the default value for invalid values
cfg.ChildObjectListingPageSize = 1000
}
return cfg, nil
}
9 changes: 9 additions & 0 deletions common-lib/k8sResource/k8sResource_wire.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package k8sResource

import "github.com/google/wire"

var WireSet = wire.NewSet(
GetK8sResourceConfig,
NewK8sServiceImpl,
wire.Bind(new(K8sService), new(*K8sServiceImpl)),
)
Loading