Skip to content

Commit

Permalink
Add support for earliest conduit version available
Browse files Browse the repository at this point in the history
  • Loading branch information
lyuboxa committed Oct 2, 2024
1 parent 3c12f12 commit 7f9a5bf
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 35 deletions.
4 changes: 2 additions & 2 deletions api/v1alpha/conduit_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ const (
)

var (
ConduitPipelineFile = path.Join(ConduitPipelinePath, "pipeline.yaml")
ConduitWithProcessorsVersion = "0.9.0"
ConduitPipelineFile = path.Join(ConduitPipelinePath, "pipeline.yaml")
ConduitEarliestAvailable = "v0.11.1"
)

// ConduitSpec defines the desired state of Conduit
Expand Down
29 changes: 29 additions & 0 deletions api/v1alpha/conduit_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"path/filepath"
"strings"

"github.com/Masterminds/semver/v3"
"github.com/hashicorp/go-multierror"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -13,6 +14,18 @@ import (
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

var conduitVerConstraint *semver.Constraints

func init() {
var err error
// validate constraint
sanitized, _ := strings.CutPrefix(ConduitEarliestAvailable, "v")
conduitVerConstraint, err = semver.NewConstraint(fmt.Sprint(">= ", sanitized))
if err != nil {
panic(fmt.Errorf("failed to create version constraint: %w", err))
}
}

func (r *Conduit) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).
Expand Down Expand Up @@ -103,6 +116,13 @@ var _ webhook.Validator = &Conduit{}
func (r *Conduit) ValidateCreate() (admission.Warnings, error) {
var errs error

if ok := validateConduitVersion(r.Spec.Version); !ok {
errs = multierror.Append(errs, fmt.Errorf("unsupported conduit version %s, minimum required %s",
r.Spec.Version,
ConduitEarliestAvailable,
))
}

if _, err := validateConnectors(r.Spec.Connectors); err != nil {
errs = multierror.Append(errs, err)
}
Expand Down Expand Up @@ -165,3 +185,12 @@ func validateProcessors(pp []*ConduitProcessor) (admission.Warnings, error) {

return nil, errs
}

func validateConduitVersion(ver string) bool {
sanitized, _ := strings.CutPrefix(ver, "v")
v, err := semver.NewVersion(sanitized)
if err != nil {
return false
}
return conduitVerConstraint.Check(v)
}
5 changes: 1 addition & 4 deletions controllers/conduit_containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ func ConduitRuntimeContainer(image, version string, envVars []corev1.EnvVar) cor
"-db.type", "badger",
"-db.badger.path", v1alpha.ConduitDBPath,
"-pipelines.exit-on-error",
}

if withProcessors(version) {
args = append(args, "-processors.path", v1alpha.ConduitProcessorsPath)
"-processors.path", v1alpha.ConduitProcessorsPath,
}

return corev1.Container{
Expand Down
29 changes: 0 additions & 29 deletions controllers/conduit_ver.go

This file was deleted.

0 comments on commit 7f9a5bf

Please sign in to comment.