Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions generate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

//go:generate mockgen -destination=./tests/mocks/stream_reconciler_factory.go -package=mocks github.com/SneaksAndData/arcane-operator/services/controllers/stream_class StreamReconcilerFactory
//go:generate mockgen -destination=./tests/mocks/cache_provider.go -package=mocks github.com/SneaksAndData/arcane-operator/services/controllers/stream_class CacheProvider
//go:generate mockgen -destination=./tests/mocks/stream_reconciler.go -package=mocks github.com/SneaksAndData/arcane-operator/services/controllers StreamReconciler
//go:generate mockgen -destination=./tests/mocks/stream_reconciler_factory.go -package=mocks github.com/SneaksAndData/arcane-operator/services/controllers/stream_class StreamReconcilerFactory
//go:generate mockgen -destination=./tests/mocks/cache_provider.go -package=mocks github.com/SneaksAndData/arcane-operator/services/controllers/stream_class CacheProvider
//go:generate mockgen -destination=./tests/mocks/stream_reconciler.go -package=mocks github.com/SneaksAndData/arcane-operator/services/controllers StreamReconciler
//go:generate mockgen -destination=./tests/mocks/controller.go -package=mocks sigs.k8s.io/controller-runtime/pkg/controller Controller
//go:generate mockgen -destination=./tests/mocks/job_builder.go -package=mocks github.com/SneaksAndData/arcane-operator/services/controllers/stream JobBuilder
7 changes: 6 additions & 1 deletion services/controllers/stream/basic_job_configurator.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package stream

Check failure on line 1 in services/controllers/stream/basic_job_configurator.go

View workflow job for this annotation

GitHub Actions / Validate commit

File test coverage below threshold

File test coverage below threshold: coverage: 0.0% (0/3); threshold: 70%

import (
"github.com/SneaksAndData/arcane-operator/services"
batchv1 "k8s.io/api/batch/v1"
)

var _ JobConfigurator = &BasicJobConfigurator{}
var _ services.JobConfigurator = &BasicJobConfigurator{}

type BasicJobConfigurator struct {
definition Definition
}

func (f BasicJobConfigurator) AddNext(configurator *services.JobConfigurator) services.JobConfigurator {
panic("not implemented")
}

func (f BasicJobConfigurator) ConfigureJob(job *batchv1.Job) error {
panic("not implemented")
}
Expand Down
11 changes: 11 additions & 0 deletions services/controllers/stream/job_builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package stream

import (
"context"
"github.com/SneaksAndData/arcane-operator/services"
batchv1 "k8s.io/api/batch/v1"
)

type JobBuilder interface {
BuildJob(ctx context.Context, jobType services.JobTemplateType, configurator services.JobConfigurator) (*batchv1.Job, error)
}
7 changes: 0 additions & 7 deletions services/controllers/stream/job_configurator.go

This file was deleted.

3 changes: 0 additions & 3 deletions services/controllers/stream/stream_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ type Definition interface {

// ToOwnerReference converts the stream definition to an owner reference.
ToOwnerReference() v1.OwnerReference

// JobConfigurator returns a JobConfigurator for the stream definition.
JobConfigurator() JobConfigurator
}

func fromUnstructured(obj *unstructured.Unstructured) (Definition, error) {
Expand Down
8 changes: 6 additions & 2 deletions services/controllers/stream/unstructured_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/SneaksAndData/arcane-operator/services"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
)

var _ Definition = (*unstructuredWrapper)(nil)
var (
_ Definition = (*unstructuredWrapper)(nil)
_ services.JobConfiguratorProvider = (*unstructuredWrapper)(nil)
)

type unstructuredWrapper struct {
underlying *unstructured.Unstructured
Expand Down Expand Up @@ -116,7 +120,7 @@ func (u *unstructuredWrapper) ToOwnerReference() metav1.OwnerReference {
}
}

func (u *unstructuredWrapper) JobConfigurator() JobConfigurator {
func (u *unstructuredWrapper) JobConfigurator() services.JobConfigurator {
return NewFromStreamDefinition(u)
}

Expand Down
4 changes: 0 additions & 4 deletions services/job_builder.go

This file was deleted.

22 changes: 22 additions & 0 deletions services/job_configurator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package services

import batchv1 "k8s.io/api/batch/v1"

type JobTemplateType string

const (
BackfillJobTemplate JobTemplateType = "backfill"
StreamingJobTemplate JobTemplateType = "streaming"
)

// JobConfigurator defines an interface for configuring Kubernetes Jobs. Each implementer
// can modify the Job object and chain to the next configurator in the sequence.
type JobConfigurator interface {

// ConfigureJob modifies the provided Job object according to the configurator's logic.
ConfigureJob(job *batchv1.Job) error

// AddNext sets the next JobConfigurator in the chain.
// Returns self to allow for method chaining.
AddNext(configurator *JobConfigurator) JobConfigurator
}
8 changes: 8 additions & 0 deletions services/job_configurator_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package services

// JobConfiguratorProvider defines an interface for types that can provide a JobConfigurator.
type JobConfiguratorProvider interface {

// JobConfigurator returns a JobConfigurator for the current instance.
JobConfigurator() JobConfigurator
}
58 changes: 58 additions & 0 deletions tests/mocks/job_builder.go

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

Loading