Skip to content

Commit

Permalink
refactor: add monitoring generator
Browse files Browse the repository at this point in the history
  • Loading branch information
镜烛 committed Mar 18, 2024
1 parent 6e50446 commit cb739e0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 94 deletions.
2 changes: 1 addition & 1 deletion models/generators/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.72.0
github.com/stretchr/testify v1.9.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.29.3
k8s.io/apimachinery v0.29.3
kusionstack.io/kube-api v0.2.0
kusionstack.io/kusion v0.10.1-0.20240317101727-ad86ddd001f6
Expand Down Expand Up @@ -57,7 +58,6 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.29.3 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/utils v0.0.0-20240310230437-4693a0247e57 // indirect
kcl-lang.io/kcl-plugin v0.5.0 // indirect
Expand Down
94 changes: 1 addition & 93 deletions models/generators/monitoring/monitoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,10 @@ import (
"kusionstack.io/kusion/pkg/modules"

"kusionstack.io/kusion-module-framework/pkg/module"
//v1 "kusionstack.io/kusion/pkg/apis/core/v1"
)

// type Fields struct {
// project *apiv1.Project
// stack *apiv1.Stack
// app *inputs.AppConfiguration
// ws map[string]apiv1.GenericConfig
// }

type TestCase struct {
name string
//fields Fields
name string
request module.GeneratorRequest
want *module.GeneratorResponse
wantErr bool
Expand Down Expand Up @@ -162,86 +153,3 @@ func TestMonitoringGenerator_Generate(t *testing.T) {
})
}
}

// func TestMonitoringModule_Generate(t *testing.T) {
// ctx := context.TODO()

// t.Run("Monitoring does not exist in AppConfig and workspace config", func(t *testing.T) {
// g := &MonitoringModule{}
// request := &module.GeneratorRequest{}
// response, err := g.Generate(ctx, request)
// assert.NoError(t, err)
// assert.Nil(t, response)
// })

// t.Run("Generate service monitor", func(t *testing.T) {
// g := &MonitoringModule{
// OperatorMode: true,
// MonitorType: ServiceMonitorType,
// }
// request := &module.GeneratorRequest{
// Project: "test-project",
// Stack: "test-stack",
// App: "test-app",
// PlatformModuleConfig: v1.GenericConfig{
// "monitoring": map[string]interface{}{
// "Timeout": "10s",
// "Interval": "30s",
// },
// },
// }
// response, err := g.Generate(ctx, request)
// assert.NoError(t, err)
// assert.NotNil(t, response)
// assert.Len(t, response.Resources, 1)
// assert.Equal(t, "ServiceMonitor", response.Resources[0].Attributes["kind"])
// assert.Equal(t, "monitoring.coreos.com/v1", response.Resources[0].Attributes["apiVersion"])
// assert.Equal(t, "test-project", response.Resources[0].Attributes["metadata"].(map[string]any)["namespace"])
// })

// t.Run("Generate pod monitor", func(t *testing.T) {
// g := &MonitoringModule{
// OperatorMode: false,
// MonitorType: PodMonitorType,
// }
// request := &module.GeneratorRequest{
// PlatformModuleConfig: v1.GenericConfig{
// "monitoring": map[string]interface{}{
// "Timeout": "10s",
// "Interval": "30s",
// },
// },
// }
// response, err := g.Generate(ctx, request)
// assert.NoError(t, err)
// assert.NotNil(t, response)
// t.Log(response.Resources[0].Patcher)
// assert.Len(t, response.Resources, 1)
// })

// t.Run("Invalid MonitorType", func(t *testing.T) {
// g := &MonitoringModule{
// OperatorMode: true,
// MonitorType: "invalid",
// }
// request := &module.GeneratorRequest{
// PlatformModuleConfig: v1.GenericConfig{
// "monitoring": map[string]interface{}{
// "Timeout": "10s",
// "Interval": "30s",
// },
// },
// }
// response, err := g.Generate(ctx, request)
// assert.Error(t, err)
// assert.Nil(t, response)
// })

// t.Run("No resources to generate", func(t *testing.T) {
// g := &MonitoringModule{}
// request := &module.GeneratorRequest{}
// response, err := g.Generate(ctx, request)
// assert.NoError(t, err)
// assert.Nil(t, response)
// })
// }

0 comments on commit cb739e0

Please sign in to comment.