Skip to content

Commit

Permalink
fix: add purge executions option
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io>
  • Loading branch information
vsukhin committed Aug 5, 2024
1 parent d7bd9c5 commit f75f730
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 27 deletions.
34 changes: 19 additions & 15 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type config struct {
TemplateCronjob string `split_words:"true"`
Registry string
UseArgocdSync bool `split_words:"true"`
PurgeExecutions bool `split_words:"true"`
}

func init() {
Expand Down Expand Up @@ -163,21 +164,23 @@ func main() {
os.Exit(1)
}
if err = (&testscontrollers.TestReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
CronJobClient: cronJobClient,
ServiceName: httpConfig.Fullname,
ServicePort: httpConfig.Port,
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
CronJobClient: cronJobClient,
ServiceName: httpConfig.Fullname,
ServicePort: httpConfig.Port,
PurgeExecutions: httpConfig.PurgeExecutions,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Test")
os.Exit(1)
}
if err = (&testsuitecontrollers.TestSuiteReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
CronJobClient: cronJobClient,
ServiceName: httpConfig.Fullname,
ServicePort: httpConfig.Port,
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
CronJobClient: cronJobClient,
ServiceName: httpConfig.Fullname,
ServicePort: httpConfig.Port,
PurgeExecutions: httpConfig.PurgeExecutions,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "TestSuite")
os.Exit(1)
Expand Down Expand Up @@ -230,11 +233,12 @@ func main() {
os.Exit(1)
}
if err = (&testworkflowscontrollers.TestWorkflowReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
CronJobClient: cronJobClient,
ServiceName: httpConfig.Fullname,
ServicePort: httpConfig.Port,
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
CronJobClient: cronJobClient,
ServiceName: httpConfig.Fullname,
ServicePort: httpConfig.Port,
PurgeExecutions: httpConfig.PurgeExecutions,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "TestWorkflow")
os.Exit(1)
Expand Down
13 changes: 9 additions & 4 deletions internal/controller/tests/test_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ import (
// TestReconciler reconciles a Test object
type TestReconciler struct {
client.Client
Scheme *runtime.Scheme
CronJobClient *cronjob.Client
ServiceName string
ServicePort int
Scheme *runtime.Scheme
CronJobClient *cronjob.Client
ServiceName string
ServicePort int
PurgeExecutions bool
}

//+kubebuilder:rbac:groups=tests.testkube.io,resources=tests,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -168,6 +169,10 @@ func (r *TestReconciler) SetupWithManager(mgr ctrl.Manager) error {
}

func (r *TestReconciler) deleteTest(testName, namespace string) (out string, err error) {
if !r.PurgeExecutions {
return out, nil
}

request, err := http.NewRequest(http.MethodDelete,
fmt.Sprintf("http://%s.%s.svc.cluster.local:%d/v1/tests/%s?skipDeleteCRD=true",
r.ServiceName, namespace, r.ServicePort, testName), nil)
Expand Down
13 changes: 9 additions & 4 deletions internal/controller/testsuite/testsuite_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ import (
// TestSuiteReconciler reconciles a TestSuite object
type TestSuiteReconciler struct {
client.Client
Scheme *runtime.Scheme
CronJobClient *cronjob.Client
ServiceName string
ServicePort int
Scheme *runtime.Scheme
CronJobClient *cronjob.Client
ServiceName string
ServicePort int
PurgeExecutions bool
}

//+kubebuilder:rbac:groups=tests.testkube.io,resources=testsuites,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -168,6 +169,10 @@ func (r *TestSuiteReconciler) SetupWithManager(mgr ctrl.Manager) error {
}

func (r *TestSuiteReconciler) deleteTestSuite(testSuiteName, namespace string) (out string, err error) {
if !r.PurgeExecutions {
return out, nil
}

request, err := http.NewRequest(http.MethodDelete,
fmt.Sprintf("http://%s.%s.svc.cluster.local:%d/v1/test-suites/%s?skipDeleteCRD=true",
r.ServiceName, namespace, r.ServicePort, testSuiteName), nil)
Expand Down
13 changes: 9 additions & 4 deletions internal/controller/testworkflows/testworkflow_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ import (
// TestWorkflowReconciler reconciles a TestWorkflow object
type TestWorkflowReconciler struct {
client.Client
Scheme *runtime.Scheme
CronJobClient *cronjob.Client
ServiceName string
ServicePort int
Scheme *runtime.Scheme
CronJobClient *cronjob.Client
ServiceName string
ServicePort int
PurgeExecutions bool
}

//+kubebuilder:rbac:groups=testworkflows.testkube.io,resources=testworkflows,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -225,6 +226,10 @@ func (r *TestWorkflowReconciler) SetupWithManager(mgr ctrl.Manager) error {
}

func (r *TestWorkflowReconciler) deleteTestWorkflow(testWorkflowName, namespace string) (out string, err error) {
if !r.PurgeExecutions {
return out, nil
}

request, err := http.NewRequest(http.MethodDelete,
fmt.Sprintf("http://%s.%s.svc.cluster.local:%d/v1/test-workflows/%s?skipDeleteCRD=true",
r.ServiceName, namespace, r.ServicePort, testWorkflowName), nil)
Expand Down

0 comments on commit f75f730

Please sign in to comment.