From abf15bdd182b54c41fbb09d745ecea3e62ea9319 Mon Sep 17 00:00:00 2001 From: Scott Cotton Date: Wed, 9 Jul 2025 19:51:14 +0200 Subject: [PATCH] add virtual workloads to sandbox spec --- generate/swagger.json | 22 +++++++- go.mod | 6 +- go.sum | 12 ++-- models/local_from.go | 2 +- models/sandbox_fork_of.go | 2 +- models/sandbox_spec.go | 62 +++++++++++++++++++++ models/virtual.go | 112 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 205 insertions(+), 13 deletions(-) create mode 100644 models/virtual.go diff --git a/generate/swagger.json b/generate/swagger.json index 359b370..0d31547 100644 --- a/generate/swagger.json +++ b/generate/swagger.json @@ -1382,7 +1382,7 @@ "local.From": { "properties": { "kind": { - "description": "Kind of entity that we want to route to. One of (Service or Deployment or Rollout).", + "description": "Kind of the baseline workload.", "example": "Deployment", "type": "string" }, @@ -2001,7 +2001,7 @@ "sandbox.ForkOf": { "properties": { "kind": { - "description": "Kind of entity that we want to route to. One of (Service or Deployment or Rollout).", + "description": "Kind of the baseline workload.", "example": "Deployment", "type": "string" }, @@ -2194,6 +2194,13 @@ }, "ttl": { "$ref": "#/definitions/sandbox.TTL" + }, + "virtual": { + "description": "Virtual Workloads", + "items": { + "$ref": "#/definitions/virtual" + }, + "type": "array" } }, "required": [ @@ -2376,6 +2383,17 @@ } }, "type": "object" + }, + "virtual": { + "properties": { + "name": { + "type": "string" + }, + "workload": { + "$ref": "#/definitions/local.From" + } + }, + "type": "object" } }, "host": "api.signadot.com", diff --git a/go.mod b/go.mod index 7b5281d..dfcbbfb 100644 --- a/go.mod +++ b/go.mod @@ -27,9 +27,9 @@ require ( github.com/opentracing/opentracing-go v1.2.0 // indirect go.mongodb.org/mongo-driver v1.17.4 // indirect go.opentelemetry.io/auto/sdk v1.1.0 // indirect - go.opentelemetry.io/otel v1.36.0 // indirect - go.opentelemetry.io/otel/metric v1.36.0 // indirect - go.opentelemetry.io/otel/trace v1.36.0 // indirect + go.opentelemetry.io/otel v1.37.0 // indirect + go.opentelemetry.io/otel/metric v1.37.0 // indirect + go.opentelemetry.io/otel/trace v1.37.0 // indirect golang.org/x/sync v0.15.0 // indirect golang.org/x/sys v0.33.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 3e2ee21..2babf37 100644 --- a/go.sum +++ b/go.sum @@ -58,14 +58,14 @@ go.mongodb.org/mongo-driver v1.17.4 h1:jUorfmVzljjr0FLzYQsGP8cgN/qzzxlY9Vh0C9KFX go.mongodb.org/mongo-driver v1.17.4/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ= go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= -go.opentelemetry.io/otel v1.36.0 h1:UumtzIklRBY6cI/lllNZlALOF5nNIzJVb16APdvgTXg= -go.opentelemetry.io/otel v1.36.0/go.mod h1:/TcFMXYjyRNh8khOAO9ybYkqaDBb/70aVwkNML4pP8E= -go.opentelemetry.io/otel/metric v1.36.0 h1:MoWPKVhQvJ+eeXWHFBOPoBOi20jh6Iq2CcCREuTYufE= -go.opentelemetry.io/otel/metric v1.36.0/go.mod h1:zC7Ks+yeyJt4xig9DEw9kuUFe5C3zLbVjV2PzT6qzbs= +go.opentelemetry.io/otel v1.37.0 h1:9zhNfelUvx0KBfu/gb+ZgeAfAgtWrfHJZcAqFC228wQ= +go.opentelemetry.io/otel v1.37.0/go.mod h1:ehE/umFRLnuLa/vSccNq9oS1ErUlkkK71gMcN34UG8I= +go.opentelemetry.io/otel/metric v1.37.0 h1:mvwbQS5m0tbmqML4NqK+e3aDiO02vsf/WgbsdpcPoZE= +go.opentelemetry.io/otel/metric v1.37.0/go.mod h1:04wGrZurHYKOc+RKeye86GwKiTb9FKm1WHtO+4EVr2E= go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw= go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg= -go.opentelemetry.io/otel/trace v1.36.0 h1:ahxWNuqZjpdiFAyrIoQ4GIiAIhxAunQR6MUoKrsNd4w= -go.opentelemetry.io/otel/trace v1.36.0/go.mod h1:gQ+OnDZzrybY4k4seLzPAWNwVBBVlF2szhehOBB/tGA= +go.opentelemetry.io/otel/trace v1.37.0 h1:HLdcFNbRQBE2imdSEgm/kwqmQj1Or1l/7bW6mxVK7z4= +go.opentelemetry.io/otel/trace v1.37.0/go.mod h1:TlgrlQ+PtQO5XFerSPUYG0JSgGyryXewPGyayAWSBS0= golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8= golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= diff --git a/models/local_from.go b/models/local_from.go index abca99e..d3aa38c 100644 --- a/models/local_from.go +++ b/models/local_from.go @@ -19,7 +19,7 @@ import ( // swagger:model local.From type LocalFrom struct { - // Kind of entity that we want to route to. One of (Service or Deployment or Rollout). + // Kind of the baseline workload. // Example: Deployment // Required: true Kind *string `json:"kind"` diff --git a/models/sandbox_fork_of.go b/models/sandbox_fork_of.go index 43ef611..322cd72 100644 --- a/models/sandbox_fork_of.go +++ b/models/sandbox_fork_of.go @@ -19,7 +19,7 @@ import ( // swagger:model sandbox.ForkOf type SandboxForkOf struct { - // Kind of entity that we want to route to. One of (Service or Deployment or Rollout). + // Kind of the baseline workload. // Example: Deployment // Required: true Kind *string `json:"kind"` diff --git a/models/sandbox_spec.go b/models/sandbox_spec.go index be775e1..cdf25b1 100644 --- a/models/sandbox_spec.go +++ b/models/sandbox_spec.go @@ -56,6 +56,9 @@ type SandboxSpec struct { // ttl TTL *SandboxTTL `json:"ttl,omitempty"` + + // Virtual Workloads + Virtual []*Virtual `json:"virtual"` } // Validate validates this sandbox spec @@ -90,6 +93,10 @@ func (m *SandboxSpec) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateVirtual(formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } @@ -248,6 +255,32 @@ func (m *SandboxSpec) validateTTL(formats strfmt.Registry) error { return nil } +func (m *SandboxSpec) validateVirtual(formats strfmt.Registry) error { + if swag.IsZero(m.Virtual) { // not required + return nil + } + + for i := 0; i < len(m.Virtual); i++ { + if swag.IsZero(m.Virtual[i]) { // not required + continue + } + + if m.Virtual[i] != nil { + if err := m.Virtual[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("virtual" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("virtual" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + // ContextValidate validate this sandbox spec based on the context it is used func (m *SandboxSpec) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error @@ -276,6 +309,10 @@ func (m *SandboxSpec) ContextValidate(ctx context.Context, formats strfmt.Regist res = append(res, err) } + if err := m.contextValidateVirtual(ctx, formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } @@ -424,6 +461,31 @@ func (m *SandboxSpec) contextValidateTTL(ctx context.Context, formats strfmt.Reg return nil } +func (m *SandboxSpec) contextValidateVirtual(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Virtual); i++ { + + if m.Virtual[i] != nil { + + if swag.IsZero(m.Virtual[i]) { // not required + return nil + } + + if err := m.Virtual[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("virtual" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("virtual" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + // MarshalBinary interface implementation func (m *SandboxSpec) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/models/virtual.go b/models/virtual.go new file mode 100644 index 0000000..a831a67 --- /dev/null +++ b/models/virtual.go @@ -0,0 +1,112 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// Virtual virtual +// +// swagger:model virtual +type Virtual struct { + + // name + Name string `json:"name,omitempty"` + + // workload + Workload *LocalFrom `json:"workload,omitempty"` +} + +// Validate validates this virtual +func (m *Virtual) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateWorkload(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *Virtual) validateWorkload(formats strfmt.Registry) error { + if swag.IsZero(m.Workload) { // not required + return nil + } + + if m.Workload != nil { + if err := m.Workload.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("workload") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("workload") + } + return err + } + } + + return nil +} + +// ContextValidate validate this virtual based on the context it is used +func (m *Virtual) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateWorkload(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *Virtual) contextValidateWorkload(ctx context.Context, formats strfmt.Registry) error { + + if m.Workload != nil { + + if swag.IsZero(m.Workload) { // not required + return nil + } + + if err := m.Workload.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("workload") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("workload") + } + return err + } + } + + return nil +} + +// MarshalBinary interface implementation +func (m *Virtual) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *Virtual) UnmarshalBinary(b []byte) error { + var res Virtual + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +}