diff --git a/go.mod b/go.mod index 6afdbfe9..c08c4102 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,7 @@ require ( ) require ( - github.com/devtron-labs/common-lib v0.16.1-0.20240923063129-ff2dc035435e + github.com/devtron-labs/common-lib v0.18.1-0.20250410084127-3148eb610369 github.com/google/go-querystring v1.1.0 // indirect github.com/google/wire v0.6.0 github.com/imdario/mergo v0.3.16 // indirect diff --git a/go.sum b/go.sum index fc22dae2..b7342680 100644 --- a/go.sum +++ b/go.sum @@ -719,8 +719,8 @@ github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxG github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/devtron-labs/common-lib v0.16.1-0.20240923063129-ff2dc035435e h1:siyAoJz9Nq26JrTzmSGd02EOmPV86tUgzgBW1Y5bSVU= -github.com/devtron-labs/common-lib v0.16.1-0.20240923063129-ff2dc035435e/go.mod h1:I+B+0ZeOV1Qv8dE/uNAFXOhw7lxfD6FqK6KzTBLBY7E= +github.com/devtron-labs/common-lib v0.18.1-0.20250410084127-3148eb610369 h1:sqQ6HsYNxIBpQ6781Pp9ZeJvCtx4fa1uaE9kiKTGivg= +github.com/devtron-labs/common-lib v0.18.1-0.20250410084127-3148eb610369/go.mod h1:I+B+0ZeOV1Qv8dE/uNAFXOhw7lxfD6FqK6KzTBLBY7E= 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/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= diff --git a/vendor/github.com/devtron-labs/common-lib/pubsub-lib/JetStreamUtil.go b/vendor/github.com/devtron-labs/common-lib/pubsub-lib/JetStreamUtil.go index a4fb42ee..d5d44ab0 100644 --- a/vendor/github.com/devtron-labs/common-lib/pubsub-lib/JetStreamUtil.go +++ b/vendor/github.com/devtron-labs/common-lib/pubsub-lib/JetStreamUtil.go @@ -125,10 +125,12 @@ type NatsTopic struct { } type ConfigJson struct { // StreamConfigJson is a json string of map[string]NatsStreamConfig - StreamConfigJson string `env:"STREAM_CONFIG_JSON"` + StreamConfigJson string `env:"STREAM_CONFIG_JSON" description:"This is json map of nats stream configurations per stream. eg: {"ORCHESTRATOR":{"max_age":3600,"replicas":1}}"` + // ConsumerConfigJson is a json string of map[string]NatsConsumerConfig // eg: "{\"ARGO_PIPELINE_STATUS_UPDATE_DURABLE-1\" : \"{\"natsMsgProcessingBatchSize\" : 3, \"natsMsgBufferSize\" : 3, \"ackWaitInSecs\": 300}\"}" - ConsumerConfigJson string `env:"CONSUMER_CONFIG_JSON"` + ConsumerConfigJson string `env:"CONSUMER_CONFIG_JSON" description:"ConsumerConfigJson is a json string of map[string]NatsConsumerConfig" ` + } var natsTopicMapping = map[string]NatsTopic{ diff --git a/vendor/github.com/devtron-labs/common-lib/pubsub-lib/NatsClient.go b/vendor/github.com/devtron-labs/common-lib/pubsub-lib/NatsClient.go index 1da3710c..c8c0eea9 100644 --- a/vendor/github.com/devtron-labs/common-lib/pubsub-lib/NatsClient.go +++ b/vendor/github.com/devtron-labs/common-lib/pubsub-lib/NatsClient.go @@ -36,7 +36,8 @@ type NatsClientConfig struct { // consumer wise // NatsMsgProcessingBatchSize is the number of messages that will be processed in one go - NatsMsgProcessingBatchSize int `env:"NATS_MSG_PROCESSING_BATCH_SIZE" envDefault:"1"` + NatsMsgProcessingBatchSize int `env:"NATS_MSG_PROCESSING_BATCH_SIZE" envDefault:"1" description:"NatsMsgProcessingBatchSize is the number of messages that will be processed in one go"` + // NatsMsgBufferSize is the number of messages that will be buffered in memory (channel size) // it is recommended to set this value equal to NatsMsgProcessingBatchSize as we want to process maximum messages in the buffer in one go. @@ -45,10 +46,10 @@ type NatsClientConfig struct { // NatsMsgBufferSize can be configured independently of NatsMsgProcessingBatchSize if needed by setting its value to positive value in env. // if NatsMsgBufferSize set to a non-positive value then it will take the value of NatsMsgProcessingBatchSize. // Note: always get this value by calling GetNatsMsgBufferSize method - NatsMsgBufferSize int `env:"NATS_MSG_BUFFER_SIZE" envDefault:"-1"` - NatsMsgMaxAge int `env:"NATS_MSG_MAX_AGE" envDefault:"86400"` - NatsMsgAckWaitInSecs int `env:"NATS_MSG_ACK_WAIT_IN_SECS" envDefault:"120"` - NatsMsgReplicas int `env:"NATS_MSG_REPLICAS" envDefault:"0"` + NatsMsgBufferSize int `env:"NATS_MSG_BUFFER_SIZE" envDefault:"-1" description:"NatsMsgBufferSize is the number of messages that will be buffered in memory (channel size)"` + NatsMsgMaxAge int `env:"NATS_MSG_MAX_AGE" envDefault:"86400" description:"Age for the message to persist"` + NatsMsgAckWaitInSecs int `env:"NATS_MSG_ACK_WAIT_IN_SECS" envDefault:"120" description:"Time to wait for acknowledging the message"` + NatsMsgReplicas int `env:"NATS_MSG_REPLICAS" envDefault:"0" description:"Replica count for runnings nats instance"` } func (ncc NatsClientConfig) GetNatsMsgBufferSize() int { 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 7734f432..2a02540f 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 @@ -113,8 +113,9 @@ type K8sService interface { CreateConfigMap(namespace string, cm *v1.ConfigMap, client *v12.CoreV1Client) (*v1.ConfigMap, error) GetConfigMap(namespace string, name string, client *v12.CoreV1Client) (*v1.ConfigMap, error) GetConfigMapWithCtx(ctx context.Context, namespace string, name string, client *v12.CoreV1Client) (*v1.ConfigMap, error) - CheckIfNsExists(namespace string, client *v12.CoreV1Client) (exists bool, err error) - CreateNsIfNotExists(namespace string, clusterConfig *ClusterConfig) (err 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) + UpdateNSLabels(namespace *v1.Namespace, labels map[string]string, clusterConfig *ClusterConfig) (ns *v1.Namespace, err error) GetK8sDiscoveryClientInCluster() (*discovery.DiscoveryClient, error) GetK8sDiscoveryClient(clusterConfig *ClusterConfig) (*discovery.DiscoveryClient, error) GetClientForInCluster() (*v12.CoreV1Client, error) @@ -290,37 +291,58 @@ func (impl *K8sServiceImpl) GetK8sDiscoveryClientInCluster() (*discovery.Discove return discoveryClient, err } -func (impl *K8sServiceImpl) CreateNsIfNotExists(namespace string, clusterConfig *ClusterConfig) (err error) { +func (impl *K8sServiceImpl) CreateNsIfNotExists(namespace string, clusterConfig *ClusterConfig) (ns *v1.Namespace, nsCreated bool, err error) { v12Client, err := impl.GetCoreV1Client(clusterConfig) if err != nil { impl.logger.Errorw("error", "error", err, "clusterConfig", clusterConfig) - return err + return nil, false, err } - exists, err := impl.CheckIfNsExists(namespace, v12Client) + ns, exists, err := impl.GetNsIfExists(namespace, v12Client) if err != nil { impl.logger.Errorw("error", "error", err, "clusterConfig", clusterConfig) - return err + return ns, false, err } if exists { + nsCreated = false impl.logger.Infow("namesapce already exist") - return nil + return ns, nsCreated, nil } impl.logger.Infow("ns not exists creating", "ns", namespace) - _, err = impl.CreateNs(namespace, v12Client) - return err + ns, err = impl.CreateNs(namespace, v12Client) + if err != nil { + impl.logger.Errorw("error in creating ns", "namespace", namespace, "err", err) + return nil, false, err + } + nsCreated = true + return ns, nsCreated, err } -func (impl *K8sServiceImpl) CheckIfNsExists(namespace string, client *v12.CoreV1Client) (exists bool, err error) { - ns, err := client.Namespaces().Get(context.Background(), namespace, metav1.GetOptions{}) +func (impl *K8sServiceImpl) UpdateNSLabels(namespace *v1.Namespace, labels map[string]string, clusterConfig *ClusterConfig) (ns *v1.Namespace, err error) { + v12Client, err := impl.GetCoreV1Client(clusterConfig) + if err != nil { + impl.logger.Errorw("error", "error", err, "clusterConfig", clusterConfig) + return nil, err + } + namespace.Labels = labels + ns, err = v12Client.Namespaces().Update(context.Background(), namespace, metav1.UpdateOptions{}) + if err != nil { + impl.logger.Errorw("error in updating ns", "namespace", namespace, "err", err) + return nil, err + } + return ns, nil +} + +func (impl *K8sServiceImpl) GetNsIfExists(namespace string, client *v12.CoreV1Client) (ns *v1.Namespace, exists bool, err error) { + ns, err = client.Namespaces().Get(context.Background(), namespace, metav1.GetOptions{}) //ns, err := impl.k8sClient.CoreV1().Namespaces().Get(namespace, metav1.GetOptions{}) impl.logger.Debugw("ns fetch", "name", namespace, "res", ns) if errors.IsNotFound(err) { - return false, nil + return nil, false, nil } else if err != nil { impl.logger.Errorw("error in checking if ns exist", "err", err) - return false, err + return nil, false, err } else { - return true, nil + return ns, true, nil } } 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 05f5220e..33527e07 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 @@ -185,18 +185,19 @@ func GetResourceKey(obj *unstructured.Unstructured) ResourceKey { } type CustomK8sHttpTransportConfig struct { - UseCustomTransport bool `env:"USE_CUSTOM_HTTP_TRANSPORT" envDefault:"false"` - TimeOut int `env:"K8s_TCP_TIMEOUT" envDefault:"30"` - KeepAlive int `env:"K8s_TCP_KEEPALIVE" envDefault:"30"` - TLSHandshakeTimeout int `env:"K8s_TLS_HANDSHAKE_TIMEOUT" envDefault:"10"` - MaxIdleConnsPerHost int `env:"K8s_CLIENT_MAX_IDLE_CONNS_PER_HOST" envDefault:"25"` - IdleConnTimeout int `env:"K8s_TCP_IDLE_CONN_TIMEOUT" envDefault:"300"` + UseCustomTransport bool `env:"USE_CUSTOM_HTTP_TRANSPORT" envDefault:"false" description:"There is an issue in updating cluster bearer token with same cluster url due to transport layer token caching in k8s client lib. so we added a custom transport while calling k8s api server. this flag controls the usage of this transport.(custom or k8s)"` + TimeOut int `env:"K8s_TCP_TIMEOUT" envDefault:"30" description:"Is the maximum amount of time a dial will wait for a connect to complete, required only if USE_CUSTOM_HTTP_TRANSPORT is true."` + KeepAlive int `env:"K8s_TCP_KEEPALIVE" envDefault:"30" description:"Specifies the interval between keep-alive probes for an active, required only if USE_CUSTOM_HTTP_TRANSPORT is true."` + TLSHandshakeTimeout int `env:"K8s_TLS_HANDSHAKE_TIMEOUT" envDefault:"10" description:"Specifies the maximum amount of time to wait for a TLS handshake. Zero means no timeout, required only if USE_CUSTOM_HTTP_TRANSPORT is true."` + MaxIdleConnsPerHost int `env:"K8s_CLIENT_MAX_IDLE_CONNS_PER_HOST" envDefault:"25" description:"k8s client max idle connections per host"` + IdleConnTimeout int `env:"K8s_TCP_IDLE_CONN_TIMEOUT" envDefault:"300" description:"Maximum amount of time an idle (keep-alive) connection will remain idle before closing itself, required only if USE_CUSTOM_HTTP_TRANSPORT is true."` } type LocalDevMode bool type RuntimeConfig struct { - LocalDevMode LocalDevMode `env:"RUNTIME_CONFIG_LOCAL_DEV" envDefault:"false"` + LocalDevMode LocalDevMode `env:"RUNTIME_CONFIG_LOCAL_DEV" envDefault:"false" description: "Used in local development process. Allows to read from local kube config file path for default cluster operations."` + } func GetRuntimeConfig() (*RuntimeConfig, error) { diff --git a/vendor/modules.txt b/vendor/modules.txt index cb566123..b46a7d0c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -211,7 +211,7 @@ github.com/cyphar/filepath-securejoin # github.com/davecgh/go-spew v1.1.1 ## explicit github.com/davecgh/go-spew/spew -# github.com/devtron-labs/common-lib v0.16.1-0.20240923063129-ff2dc035435e +# github.com/devtron-labs/common-lib v0.18.1-0.20250410084127-3148eb610369 ## explicit; go 1.21 github.com/devtron-labs/common-lib/constants github.com/devtron-labs/common-lib/git-manager/util