Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for service monitor on NIM Service #58

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Changes from 1 commit
Commits
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
Next Next commit
Adding support for service monitor on NIM Service
Signed-off-by: Vishesh Tanksale <vtanksale@nvidia.com>
  • Loading branch information
visheshtanksale committed Aug 16, 2024
commit 1910402da8bd460f23ecbfb57b5b4f53c3e33b30
9 changes: 2 additions & 7 deletions api/apps/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
promv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
autoscalingv2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
@@ -40,13 +41,7 @@ type Service struct {
type Metrics struct {
Enabled *bool `json:"enabled,omitempty"`
// for use with the Prometheus Operator and the primary service object
ServiceMonitor ServiceMonitor `json:"serviceMonitor,omitempty"`
}

// ServiceMonitor defines attributes to create a service monitor
type ServiceMonitor struct {
Create *bool `json:"enabled,omitempty"`
AdditionalLabels map[string]string `json:"additionalLabels,omitempty"`
ServiceMonitorSpec promv1.ServiceMonitorSpec `json:"serviceMonitorSpec,omitempty"`
}

// Autoscaling defines attributes to automatically scale the service based on metrics
22 changes: 22 additions & 0 deletions api/apps/v1alpha1/nimservice_types.go
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ import (

rendertypes "github.com/NVIDIA/k8s-nim-operator/internal/render/types"
utils "github.com/NVIDIA/k8s-nim-operator/internal/utils"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
autoscalingv2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
@@ -439,6 +440,11 @@ func (n *NIMService) GetHPA() HorizontalPodAutoscalerSpec {
return n.Spec.Scale.HPA
}

// GetServiceMonitorSpec returns the Service Monitor spec for the NIMService deployment
func (n *NIMService) GetServiceMonitorSpec() monitoringv1.ServiceMonitorSpec {
return n.Spec.Metrics.ServiceMonitorSpec
}

// GetReplicas returns replicas for the NIMService deployment
func (n *NIMService) GetReplicas() int {
if n.IsAutoScalingEnabled() {
@@ -689,6 +695,22 @@ func (n *NIMService) GetSCCParams() *rendertypes.SCCParams {
return params
}

// GetServiceMonitorParams return params to render Service Monitor from templates
func (n *NIMService) GetServiceMonitorParams() *rendertypes.ServiceMonitorParams {
params := &rendertypes.ServiceMonitorParams{}
params.Enabled = n.IsServiceMonitorEnabled()
params.Name = n.GetName()
params.Namespace = n.GetNamespace()
params.Labels = n.GetServiceLabels()
params.Annotations = n.GetServiceAnnotations()

// Set Service Monitor spec
spec := n.GetServiceMonitorSpec()
spec.NamespaceSelector = monitoringv1.NamespaceSelector{MatchNames: []string{n.Namespace}}
params.SMSpec = spec
return params
}

func init() {
SchemeBuilder.Register(&NIMService{}, &NIMServiceList{})
}
29 changes: 1 addition & 28 deletions api/apps/v1alpha1/zz_generated.deepcopy.go

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

967 changes: 962 additions & 5 deletions bundle/manifests/apps.nvidia.com_nimpipelines.yaml

Large diffs are not rendered by default.

947 changes: 942 additions & 5 deletions bundle/manifests/apps.nvidia.com_nimservices.yaml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ import (
"flag"
"os"

monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"
@@ -51,8 +52,8 @@ var (

func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))

utilruntime.Must(appsv1alpha1.AddToScheme(scheme))
utilruntime.Must(monitoring.AddToScheme(scheme))
// +kubebuilder:scaffold:scheme
}

Loading