diff --git a/Makefile b/Makefile index b8d3e10334..49484797c3 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ EOL_IMG ?= docker.io/library/alpine:3.1 BUSYBOX_BASE_IMG ?= busybox:1.36.0 NON_VULNERABLE_IMG ?= ghcr.io/eraser-dev/non-vulnerable:latest E2E_TESTS ?= $(shell find ./test/e2e/tests/ -mindepth 1 -type d) -API_VERSIONS ?= ./api/v1alpha1,./api/v1,./api/v1alpha2 +API_VERSIONS ?= ./api/v1alpha1,./api/v1,./api/v1alpha2,./api/v1alpha3 HELM_UPGRADE_TEST ?= TEST_LOGDIR ?= $(PWD)/test_logs diff --git a/api/unversioned/config/config.go b/api/unversioned/config/config.go index c469755bfe..4184354a75 100644 --- a/api/unversioned/config/config.go +++ b/api/unversioned/config/config.go @@ -78,7 +78,10 @@ const ( func Default() *unversioned.EraserConfig { return &unversioned.EraserConfig{ Manager: unversioned.ManagerConfig{ - Runtime: "containerd", + Runtime: unversioned.RuntimeSpec{ + Name: unversioned.RuntimeContainerd, + Address: "unix:///run/containerd/containerd.sock", + }, OTLPEndpoint: "", LogLevel: "info", Scheduling: unversioned.ScheduleConfig{ diff --git a/api/unversioned/eraserconfig_types.go b/api/unversioned/eraserconfig_types.go index 9c854a7d99..73a6fd70a6 100644 --- a/api/unversioned/eraserconfig_types.go +++ b/api/unversioned/eraserconfig_types.go @@ -19,6 +19,7 @@ package unversioned import ( "encoding/json" "fmt" + "net/url" "time" "k8s.io/apimachinery/pkg/api/resource" @@ -28,14 +29,40 @@ import ( type ( Duration time.Duration Runtime string + + RuntimeSpec struct { + Name Runtime `json:"name"` + Address string `json:"address"` + } ) const ( RuntimeContainerd Runtime = "containerd" RuntimeDockerShim Runtime = "dockershim" RuntimeCrio Runtime = "crio" + + ContainerdPath = "/run/containerd/containerd.sock" + DockerPath = "/run/dockershim.sock" + CrioPath = "/run/crio/crio.sock" ) +func ConvertRuntimeToRuntimeSpec(r Runtime) (RuntimeSpec, error) { + var rs RuntimeSpec + + switch r { + case RuntimeContainerd: + rs = RuntimeSpec{Name: RuntimeContainerd, Address: fmt.Sprintf("unix://%s", ContainerdPath)} + case RuntimeDockerShim: + rs = RuntimeSpec{Name: RuntimeDockerShim, Address: fmt.Sprintf("unix://%s", DockerPath)} + case RuntimeCrio: + rs = RuntimeSpec{Name: RuntimeCrio, Address: fmt.Sprintf("unix://%s", CrioPath)} + default: + return rs, fmt.Errorf("invalid runtime: valid names are %s, %s, %s", RuntimeContainerd, RuntimeDockerShim, RuntimeCrio) + } + + return rs, nil +} + func (td *Duration) UnmarshalJSON(b []byte) error { var str string err := json.Unmarshal(b, &str) @@ -52,27 +79,58 @@ func (td *Duration) UnmarshalJSON(b []byte) error { return nil } -func (r *Runtime) UnmarshalJSON(b []byte) error { - var str string - err := json.Unmarshal(b, &str) +func (td *Duration) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, time.Duration(*td).String())), nil +} + +func (r *RuntimeSpec) UnmarshalJSON(b []byte) error { + // create temp RuntimeSpec to prevent recursive error into this function when using unmarshall to check validity of provided RuntimeSpec + type TempRuntimeSpec struct { + Name string `json:"name"` + Address string `json:"address"` + } + var rs TempRuntimeSpec + err := json.Unmarshal(b, &rs) if err != nil { - return err + return fmt.Errorf("error unmarshalling into TempRuntimeSpec %v %s", err, string(b)) } - switch rt := Runtime(str); rt { + switch rt := Runtime(rs.Name); rt { + // make sure user provided Runtime is valid case RuntimeContainerd, RuntimeDockerShim, RuntimeCrio: - *r = rt + if rs.Address != "" { + // check that provided RuntimeAddress is valid + u, err := url.Parse(rs.Address) + if err != nil { + return err + } + + switch u.Scheme { + case "tcp", "unix": + default: + return fmt.Errorf("invalid RuntimeAddress scheme: valid schemes for runtime socket address are `tcp` and `unix`") + } + + r.Name = Runtime(rs.Name) + r.Address = rs.Address + + return nil + } + + // if RuntimeAddress is not provided, get defaults + converted, err := ConvertRuntimeToRuntimeSpec(rt) + if err != nil { + return err + } + + *r = converted default: - return fmt.Errorf("cannot determine runtime type: %s. valid values are containerd, dockershim, or crio", str) + return fmt.Errorf("invalid runtime: valid names are %s, %s, %s", RuntimeContainerd, RuntimeDockerShim, RuntimeCrio) } return nil } -func (td *Duration) MarshalJSON() ([]byte, error) { - return []byte(fmt.Sprintf(`"%s"`, time.Duration(*td).String())), nil -} - // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. @@ -89,7 +147,7 @@ type ContainerConfig struct { } type ManagerConfig struct { - Runtime Runtime `json:"runtime,omitempty"` + Runtime RuntimeSpec `json:"runtime,omitempty"` OTLPEndpoint string `json:"otlpEndpoint,omitempty"` LogLevel string `json:"logLevel,omitempty"` Scheduling ScheduleConfig `json:"scheduling,omitempty"` diff --git a/api/unversioned/zz_generated.deepcopy.go b/api/unversioned/zz_generated.deepcopy.go index 05c96758fe..189bcd3ec7 100644 --- a/api/unversioned/zz_generated.deepcopy.go +++ b/api/unversioned/zz_generated.deepcopy.go @@ -294,6 +294,7 @@ func (in *ImageListStatus) DeepCopy() *ImageListStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ManagerConfig) DeepCopyInto(out *ManagerConfig) { *out = *in + out.Runtime = in.Runtime out.Scheduling = in.Scheduling out.Profile = in.Profile out.ImageJob = in.ImageJob @@ -398,6 +399,21 @@ func (in *ResourceRequirements) DeepCopy() *ResourceRequirements { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RuntimeSpec) DeepCopyInto(out *RuntimeSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RuntimeSpec. +func (in *RuntimeSpec) DeepCopy() *RuntimeSpec { + if in == nil { + return nil + } + out := new(RuntimeSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ScheduleConfig) DeepCopyInto(out *ScheduleConfig) { *out = *in diff --git a/api/v1alpha1/config/config.go b/api/v1alpha1/config/config.go index a1d678031e..cb64795f0c 100644 --- a/api/v1alpha1/config/config.go +++ b/api/v1alpha1/config/config.go @@ -2,7 +2,6 @@ package config import ( "fmt" - "sync" "time" v1alpha1 "github.com/eraser-dev/eraser/api/v1alpha1" @@ -29,46 +28,6 @@ severities: - LOW ` -type Manager struct { - mtx sync.Mutex - cfg *v1alpha1.EraserConfig -} - -func (m *Manager) Read() (v1alpha1.EraserConfig, error) { - m.mtx.Lock() - defer m.mtx.Unlock() - - if m.cfg == nil { - return v1alpha1.EraserConfig{}, fmt.Errorf("ConfigManager configuration is nil, aborting") - } - - cfg := *m.cfg - return cfg, nil -} - -func (m *Manager) Update(newC *v1alpha1.EraserConfig) error { - m.mtx.Lock() - defer m.mtx.Unlock() - - if m.cfg == nil { - return fmt.Errorf("ConfigManager configuration is nil, aborting") - } - - if newC == nil { - return fmt.Errorf("new configuration is nil, aborting") - } - - *m.cfg = *newC - return nil -} - -func NewManager(cfg *v1alpha1.EraserConfig) *Manager { - return &Manager{ - mtx: sync.Mutex{}, - cfg: cfg, - } -} - const ( noDelay = v1alpha1.Duration(0) oneDay = v1alpha1.Duration(time.Hour * 24) diff --git a/api/v1alpha1/custom_conversions.go b/api/v1alpha1/custom_conversions.go new file mode 100644 index 0000000000..b2928e09ae --- /dev/null +++ b/api/v1alpha1/custom_conversions.go @@ -0,0 +1,39 @@ +package v1alpha1 + +import ( + unversioned "github.com/eraser-dev/eraser/api/unversioned" + conversion "k8s.io/apimachinery/pkg/conversion" +) + +//nolint:revive +func Convert_v1alpha1_ManagerConfig_To_unversioned_ManagerConfig(in *ManagerConfig, out *unversioned.ManagerConfig, s conversion.Scope) error { + return autoConvert_v1alpha1_ManagerConfig_To_unversioned_ManagerConfig(in, out, s) +} + +//nolint:revive +func manualConvert_v1alpha1_Runtime_To_unversioned_RuntimeSpec(in *Runtime, out *unversioned.RuntimeSpec, _ conversion.Scope) error { + out.Name = unversioned.Runtime(string(*in)) + out.Address = "" + return nil +} + +//nolint:revive +func Convert_v1alpha1_Runtime_To_unversioned_RuntimeSpec(in *Runtime, out *unversioned.RuntimeSpec, s conversion.Scope) error { + return manualConvert_v1alpha1_Runtime_To_unversioned_RuntimeSpec(in, out, s) +} + +//nolint:revive +func Convert_unversioned_ManagerConfig_To_v1alpha1_ManagerConfig(in *unversioned.ManagerConfig, out *ManagerConfig, s conversion.Scope) error { + return autoConvert_unversioned_ManagerConfig_To_v1alpha1_ManagerConfig(in, out, s) +} + +//nolint:revive +func manualConvert_unversioned_RuntimeSpec_To_v1alpha1_Runtime(in *unversioned.RuntimeSpec, out *Runtime, _ conversion.Scope) error { + *out = Runtime(in.Name) + return nil +} + +//nolint:revive +func Convert_unversioned_RuntimeSpec_To_v1alpha1_Runtime(in *unversioned.RuntimeSpec, out *Runtime, s conversion.Scope) error { + return manualConvert_unversioned_RuntimeSpec_To_v1alpha1_Runtime(in, out, s) +} diff --git a/api/v1alpha1/zz_generated.conversion.go b/api/v1alpha1/zz_generated.conversion.go index 70c4d3e92e..18dc66b827 100644 --- a/api/v1alpha1/zz_generated.conversion.go +++ b/api/v1alpha1/zz_generated.conversion.go @@ -156,16 +156,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*ManagerConfig)(nil), (*unversioned.ManagerConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha1_ManagerConfig_To_unversioned_ManagerConfig(a.(*ManagerConfig), b.(*unversioned.ManagerConfig), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*unversioned.ManagerConfig)(nil), (*ManagerConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_unversioned_ManagerConfig_To_v1alpha1_ManagerConfig(a.(*unversioned.ManagerConfig), b.(*ManagerConfig), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*NodeFilterConfig)(nil), (*unversioned.NodeFilterConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha1_NodeFilterConfig_To_unversioned_NodeFilterConfig(a.(*NodeFilterConfig), b.(*unversioned.NodeFilterConfig), scope) }); err != nil { @@ -231,11 +221,31 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*unversioned.ManagerConfig)(nil), (*ManagerConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_unversioned_ManagerConfig_To_v1alpha1_ManagerConfig(a.(*unversioned.ManagerConfig), b.(*ManagerConfig), scope) + }); err != nil { + return err + } + if err := s.AddConversionFunc((*unversioned.RuntimeSpec)(nil), (*Runtime)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_unversioned_RuntimeSpec_To_v1alpha1_Runtime(a.(*unversioned.RuntimeSpec), b.(*Runtime), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*Components)(nil), (*unversioned.Components)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha1_Components_To_unversioned_Components(a.(*Components), b.(*unversioned.Components), scope) }); err != nil { return err } + if err := s.AddConversionFunc((*ManagerConfig)(nil), (*unversioned.ManagerConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_ManagerConfig_To_unversioned_ManagerConfig(a.(*ManagerConfig), b.(*unversioned.ManagerConfig), scope) + }); err != nil { + return err + } + if err := s.AddConversionFunc((*Runtime)(nil), (*unversioned.RuntimeSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_Runtime_To_unversioned_RuntimeSpec(a.(*Runtime), b.(*unversioned.RuntimeSpec), scope) + }); err != nil { + return err + } return nil } @@ -580,7 +590,9 @@ func Convert_unversioned_ImageListStatus_To_v1alpha1_ImageListStatus(in *unversi } func autoConvert_v1alpha1_ManagerConfig_To_unversioned_ManagerConfig(in *ManagerConfig, out *unversioned.ManagerConfig, s conversion.Scope) error { - out.Runtime = unversioned.Runtime(in.Runtime) + if err := Convert_v1alpha1_Runtime_To_unversioned_RuntimeSpec(&in.Runtime, &out.Runtime, s); err != nil { + return err + } out.OTLPEndpoint = in.OTLPEndpoint out.LogLevel = in.LogLevel if err := Convert_v1alpha1_ScheduleConfig_To_unversioned_ScheduleConfig(&in.Scheduling, &out.Scheduling, s); err != nil { @@ -600,13 +612,10 @@ func autoConvert_v1alpha1_ManagerConfig_To_unversioned_ManagerConfig(in *Manager return nil } -// Convert_v1alpha1_ManagerConfig_To_unversioned_ManagerConfig is an autogenerated conversion function. -func Convert_v1alpha1_ManagerConfig_To_unversioned_ManagerConfig(in *ManagerConfig, out *unversioned.ManagerConfig, s conversion.Scope) error { - return autoConvert_v1alpha1_ManagerConfig_To_unversioned_ManagerConfig(in, out, s) -} - func autoConvert_unversioned_ManagerConfig_To_v1alpha1_ManagerConfig(in *unversioned.ManagerConfig, out *ManagerConfig, s conversion.Scope) error { - out.Runtime = Runtime(in.Runtime) + if err := Convert_unversioned_RuntimeSpec_To_v1alpha1_Runtime(&in.Runtime, &out.Runtime, s); err != nil { + return err + } out.OTLPEndpoint = in.OTLPEndpoint out.LogLevel = in.LogLevel if err := Convert_unversioned_ScheduleConfig_To_v1alpha1_ScheduleConfig(&in.Scheduling, &out.Scheduling, s); err != nil { @@ -626,11 +635,6 @@ func autoConvert_unversioned_ManagerConfig_To_v1alpha1_ManagerConfig(in *unversi return nil } -// Convert_unversioned_ManagerConfig_To_v1alpha1_ManagerConfig is an autogenerated conversion function. -func Convert_unversioned_ManagerConfig_To_v1alpha1_ManagerConfig(in *unversioned.ManagerConfig, out *ManagerConfig, s conversion.Scope) error { - return autoConvert_unversioned_ManagerConfig_To_v1alpha1_ManagerConfig(in, out, s) -} - func autoConvert_v1alpha1_NodeFilterConfig_To_unversioned_NodeFilterConfig(in *NodeFilterConfig, out *unversioned.NodeFilterConfig, s conversion.Scope) error { out.Type = in.Type out.Selectors = *(*[]string)(unsafe.Pointer(&in.Selectors)) diff --git a/api/v1alpha2/config/config.go b/api/v1alpha2/config/config.go index 1bf0524f9b..bdd7bcf675 100644 --- a/api/v1alpha2/config/config.go +++ b/api/v1alpha2/config/config.go @@ -2,7 +2,6 @@ package config import ( "fmt" - "sync" "time" "github.com/eraser-dev/eraser/api/v1alpha2" @@ -29,46 +28,6 @@ severities: - LOW ` -type Manager struct { - mtx sync.Mutex - cfg *v1alpha2.EraserConfig -} - -func (m *Manager) Read() (v1alpha2.EraserConfig, error) { - m.mtx.Lock() - defer m.mtx.Unlock() - - if m.cfg == nil { - return v1alpha2.EraserConfig{}, fmt.Errorf("ConfigManager configuration is nil, aborting") - } - - cfg := *m.cfg - return cfg, nil -} - -func (m *Manager) Update(newC *v1alpha2.EraserConfig) error { - m.mtx.Lock() - defer m.mtx.Unlock() - - if m.cfg == nil { - return fmt.Errorf("ConfigManager configuration is nil, aborting") - } - - if newC == nil { - return fmt.Errorf("new configuration is nil, aborting") - } - - *m.cfg = *newC - return nil -} - -func NewManager(cfg *v1alpha2.EraserConfig) *Manager { - return &Manager{ - mtx: sync.Mutex{}, - cfg: cfg, - } -} - const ( noDelay = v1alpha2.Duration(0) oneDay = v1alpha2.Duration(time.Hour * 24) diff --git a/api/v1alpha2/custom_conversions.go b/api/v1alpha2/custom_conversions.go new file mode 100644 index 0000000000..e9704a8cee --- /dev/null +++ b/api/v1alpha2/custom_conversions.go @@ -0,0 +1,39 @@ +package v1alpha2 + +import ( + unversioned "github.com/eraser-dev/eraser/api/unversioned" + conversion "k8s.io/apimachinery/pkg/conversion" +) + +//nolint:revive +func Convert_v1alpha2_ManagerConfig_To_unversioned_ManagerConfig(in *ManagerConfig, out *unversioned.ManagerConfig, s conversion.Scope) error { + return autoConvert_v1alpha2_ManagerConfig_To_unversioned_ManagerConfig(in, out, s) +} + +//nolint:revive +func manualConvert_v1alpha2_Runtime_To_unversioned_RuntimeSpec(in *Runtime, out *unversioned.RuntimeSpec, _ conversion.Scope) error { + out.Name = unversioned.Runtime(string(*in)) + out.Address = "" + return nil +} + +//nolint:revive +func Convert_v1alpha2_Runtime_To_unversioned_RuntimeSpec(in *Runtime, out *unversioned.RuntimeSpec, s conversion.Scope) error { + return manualConvert_v1alpha2_Runtime_To_unversioned_RuntimeSpec(in, out, s) +} + +//nolint:revive +func Convert_unversioned_ManagerConfig_To_v1alpha2_ManagerConfig(in *unversioned.ManagerConfig, out *ManagerConfig, s conversion.Scope) error { + return autoConvert_unversioned_ManagerConfig_To_v1alpha2_ManagerConfig(in, out, s) +} + +//nolint:revive +func manualConvert_unversioned_RuntimeSpec_To_v1alpha2_Runtime(in *unversioned.RuntimeSpec, out *Runtime, _ conversion.Scope) error { + *out = Runtime(in.Name) + return nil +} + +//nolint:revive +func Convert_unversioned_RuntimeSpec_To_v1alpha2_Runtime(in *unversioned.RuntimeSpec, out *Runtime, s conversion.Scope) error { + return manualConvert_unversioned_RuntimeSpec_To_v1alpha2_Runtime(in, out, s) +} diff --git a/api/v1alpha2/zz_generated.conversion.go b/api/v1alpha2/zz_generated.conversion.go index d0b8be8dab..0a0440450d 100644 --- a/api/v1alpha2/zz_generated.conversion.go +++ b/api/v1alpha2/zz_generated.conversion.go @@ -85,16 +85,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*ManagerConfig)(nil), (*unversioned.ManagerConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha2_ManagerConfig_To_unversioned_ManagerConfig(a.(*ManagerConfig), b.(*unversioned.ManagerConfig), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*unversioned.ManagerConfig)(nil), (*ManagerConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_unversioned_ManagerConfig_To_v1alpha2_ManagerConfig(a.(*unversioned.ManagerConfig), b.(*ManagerConfig), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*NodeFilterConfig)(nil), (*unversioned.NodeFilterConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha2_NodeFilterConfig_To_unversioned_NodeFilterConfig(a.(*NodeFilterConfig), b.(*unversioned.NodeFilterConfig), scope) }); err != nil { @@ -155,6 +145,26 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*unversioned.ManagerConfig)(nil), (*ManagerConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_unversioned_ManagerConfig_To_v1alpha2_ManagerConfig(a.(*unversioned.ManagerConfig), b.(*ManagerConfig), scope) + }); err != nil { + return err + } + if err := s.AddConversionFunc((*unversioned.RuntimeSpec)(nil), (*Runtime)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_unversioned_RuntimeSpec_To_v1alpha2_Runtime(a.(*unversioned.RuntimeSpec), b.(*Runtime), scope) + }); err != nil { + return err + } + if err := s.AddConversionFunc((*ManagerConfig)(nil), (*unversioned.ManagerConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha2_ManagerConfig_To_unversioned_ManagerConfig(a.(*ManagerConfig), b.(*unversioned.ManagerConfig), scope) + }); err != nil { + return err + } + if err := s.AddConversionFunc((*Runtime)(nil), (*unversioned.RuntimeSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha2_Runtime_To_unversioned_RuntimeSpec(a.(*Runtime), b.(*unversioned.RuntimeSpec), scope) + }); err != nil { + return err + } return nil } @@ -311,7 +321,9 @@ func Convert_unversioned_ImageJobConfig_To_v1alpha2_ImageJobConfig(in *unversion } func autoConvert_v1alpha2_ManagerConfig_To_unversioned_ManagerConfig(in *ManagerConfig, out *unversioned.ManagerConfig, s conversion.Scope) error { - out.Runtime = unversioned.Runtime(in.Runtime) + if err := Convert_v1alpha2_Runtime_To_unversioned_RuntimeSpec(&in.Runtime, &out.Runtime, s); err != nil { + return err + } out.OTLPEndpoint = in.OTLPEndpoint out.LogLevel = in.LogLevel if err := Convert_v1alpha2_ScheduleConfig_To_unversioned_ScheduleConfig(&in.Scheduling, &out.Scheduling, s); err != nil { @@ -331,13 +343,10 @@ func autoConvert_v1alpha2_ManagerConfig_To_unversioned_ManagerConfig(in *Manager return nil } -// Convert_v1alpha2_ManagerConfig_To_unversioned_ManagerConfig is an autogenerated conversion function. -func Convert_v1alpha2_ManagerConfig_To_unversioned_ManagerConfig(in *ManagerConfig, out *unversioned.ManagerConfig, s conversion.Scope) error { - return autoConvert_v1alpha2_ManagerConfig_To_unversioned_ManagerConfig(in, out, s) -} - func autoConvert_unversioned_ManagerConfig_To_v1alpha2_ManagerConfig(in *unversioned.ManagerConfig, out *ManagerConfig, s conversion.Scope) error { - out.Runtime = Runtime(in.Runtime) + if err := Convert_unversioned_RuntimeSpec_To_v1alpha2_Runtime(&in.Runtime, &out.Runtime, s); err != nil { + return err + } out.OTLPEndpoint = in.OTLPEndpoint out.LogLevel = in.LogLevel if err := Convert_unversioned_ScheduleConfig_To_v1alpha2_ScheduleConfig(&in.Scheduling, &out.Scheduling, s); err != nil { @@ -357,11 +366,6 @@ func autoConvert_unversioned_ManagerConfig_To_v1alpha2_ManagerConfig(in *unversi return nil } -// Convert_unversioned_ManagerConfig_To_v1alpha2_ManagerConfig is an autogenerated conversion function. -func Convert_unversioned_ManagerConfig_To_v1alpha2_ManagerConfig(in *unversioned.ManagerConfig, out *ManagerConfig, s conversion.Scope) error { - return autoConvert_unversioned_ManagerConfig_To_v1alpha2_ManagerConfig(in, out, s) -} - func autoConvert_v1alpha2_NodeFilterConfig_To_unversioned_NodeFilterConfig(in *NodeFilterConfig, out *unversioned.NodeFilterConfig, s conversion.Scope) error { out.Type = in.Type out.Selectors = *(*[]string)(unsafe.Pointer(&in.Selectors)) diff --git a/api/v1alpha3/config/config.go b/api/v1alpha3/config/config.go new file mode 100644 index 0000000000..1ca8f536c0 --- /dev/null +++ b/api/v1alpha3/config/config.go @@ -0,0 +1,130 @@ +package config + +import ( + "fmt" + "time" + + "github.com/eraser-dev/eraser/api/v1alpha3" + "github.com/eraser-dev/eraser/version" + "k8s.io/apimachinery/pkg/api/resource" +) + +var defaultScannerConfig = ` +cacheDir: /var/lib/trivy +dbRepo: ghcr.io/aquasecurity/trivy-db +deleteFailedImages: true +deleteEOLImages: true +vulnerabilities: + ignoreUnfixed: true + types: + - os + - library +securityChecks: # need to be documented; determined by trivy, not us + - vuln +severities: + - CRITICAL + - HIGH + - MEDIUM + - LOW +` + +const ( + noDelay = v1alpha3.Duration(0) + oneDay = v1alpha3.Duration(time.Hour * 24) +) + +func Default() *v1alpha3.EraserConfig { + return &v1alpha3.EraserConfig{ + Manager: v1alpha3.ManagerConfig{ + Runtime: v1alpha3.RuntimeSpec{ + Name: v1alpha3.RuntimeContainerd, + Address: "unix:///run/containerd/containerd.sock", + }, + OTLPEndpoint: "", + LogLevel: "info", + Scheduling: v1alpha3.ScheduleConfig{ + RepeatInterval: v1alpha3.Duration(oneDay), + BeginImmediately: true, + }, + Profile: v1alpha3.ProfileConfig{ + Enabled: false, + Port: 6060, + }, + ImageJob: v1alpha3.ImageJobConfig{ + SuccessRatio: 1.0, + Cleanup: v1alpha3.ImageJobCleanupConfig{ + DelayOnSuccess: noDelay, + DelayOnFailure: oneDay, + }, + }, + PullSecrets: []string{}, + NodeFilter: v1alpha3.NodeFilterConfig{ + Type: "exclude", + Selectors: []string{ + "eraser.sh/cleanup.filter", + }, + }, + }, + Components: v1alpha3.Components{ + Collector: v1alpha3.OptionalContainerConfig{ + Enabled: false, + ContainerConfig: v1alpha3.ContainerConfig{ + Image: v1alpha3.RepoTag{ + Repo: repo("collector"), + Tag: version.BuildVersion, + }, + Request: v1alpha3.ResourceRequirements{ + Mem: resource.MustParse("25Mi"), + CPU: resource.MustParse("7m"), + }, + Limit: v1alpha3.ResourceRequirements{ + Mem: resource.MustParse("500Mi"), + CPU: resource.Quantity{}, + }, + Config: nil, + }, + }, + Scanner: v1alpha3.OptionalContainerConfig{ + Enabled: false, + ContainerConfig: v1alpha3.ContainerConfig{ + Image: v1alpha3.RepoTag{ + Repo: repo("eraser-trivy-scanner"), + Tag: version.BuildVersion, + }, + Request: v1alpha3.ResourceRequirements{ + Mem: resource.MustParse("500Mi"), + CPU: resource.MustParse("1000m"), + }, + Limit: v1alpha3.ResourceRequirements{ + Mem: resource.MustParse("2Gi"), + CPU: resource.MustParse("1500m"), + }, + Config: &defaultScannerConfig, + }, + }, + Remover: v1alpha3.ContainerConfig{ + Image: v1alpha3.RepoTag{ + Repo: repo("remover"), + Tag: version.BuildVersion, + }, + Request: v1alpha3.ResourceRequirements{ + Mem: resource.MustParse("25Mi"), + CPU: resource.MustParse("7m"), + }, + Limit: v1alpha3.ResourceRequirements{ + Mem: resource.MustParse("30Mi"), + CPU: resource.Quantity{}, + }, + Config: nil, + }, + }, + } +} + +func repo(basename string) string { + if version.DefaultRepo == "" { + return basename + } + + return fmt.Sprintf("%s/%s", version.DefaultRepo, basename) +} diff --git a/api/v1alpha3/doc.go b/api/v1alpha3/doc.go new file mode 100644 index 0000000000..6b47abf263 --- /dev/null +++ b/api/v1alpha3/doc.go @@ -0,0 +1,2 @@ +// +k8s:conversion-gen=github.com/eraser-dev/eraser/api/unversioned +package v1alpha3 diff --git a/api/v1alpha3/eraserconfig_types.go b/api/v1alpha3/eraserconfig_types.go new file mode 100644 index 0000000000..846c20fd93 --- /dev/null +++ b/api/v1alpha3/eraserconfig_types.go @@ -0,0 +1,213 @@ +/* +Copyright 2021. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha3 + +import ( + "encoding/json" + "fmt" + "net/url" + "time" + + "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type ( + Duration time.Duration + Runtime string + + RuntimeSpec struct { + Name Runtime `json:"name"` + Address string `json:"address"` + } +) + +const ( + RuntimeContainerd Runtime = "containerd" + RuntimeDockerShim Runtime = "dockershim" + RuntimeCrio Runtime = "crio" + + ContainerdPath = "/run/containerd/containerd.sock" + DockerPath = "/run/dockershim.sock" + CrioPath = "/run/crio/crio.sock" +) + +func ConvertRuntimeToRuntimeSpec(r Runtime) (RuntimeSpec, error) { + var rs RuntimeSpec + + switch r { + case RuntimeContainerd: + rs = RuntimeSpec{Name: RuntimeContainerd, Address: fmt.Sprintf("unix://%s", ContainerdPath)} + case RuntimeDockerShim: + rs = RuntimeSpec{Name: RuntimeDockerShim, Address: fmt.Sprintf("unix://%s", DockerPath)} + case RuntimeCrio: + rs = RuntimeSpec{Name: RuntimeCrio, Address: fmt.Sprintf("unix://%s", CrioPath)} + default: + return rs, fmt.Errorf("invalid runtime: valid names are %s, %s, %s", RuntimeContainerd, RuntimeDockerShim, RuntimeCrio) + } + + return rs, nil +} + +func (td *Duration) UnmarshalJSON(b []byte) error { + var str string + err := json.Unmarshal(b, &str) + if err != nil { + return err + } + + pd, err := time.ParseDuration(str) + if err != nil { + return err + } + + *td = Duration(pd) + return nil +} + +func (td *Duration) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, time.Duration(*td).String())), nil +} + +func (r *RuntimeSpec) UnmarshalJSON(b []byte) error { + // create temp RuntimeSpec to prevent recursive error into this function when using unmarshall to check validity of provided RuntimeSpec + type TempRuntimeSpec struct { + Name string `json:"name"` + Address string `json:"address"` + } + var rs TempRuntimeSpec + err := json.Unmarshal(b, &rs) + if err != nil { + return fmt.Errorf("error unmarshalling into TempRuntimeSpec %v %s", err, string(b)) + } + + switch rt := Runtime(rs.Name); rt { + // make sure user provided Runtime is valid + case RuntimeContainerd, RuntimeDockerShim, RuntimeCrio: + if rs.Address != "" { + // check that provided RuntimeAddress is valid + u, err := url.Parse(rs.Address) + if err != nil { + return err + } + + switch u.Scheme { + case "tcp", "unix": + default: + return fmt.Errorf("invalid RuntimeAddress scheme: valid schemes for runtime socket address are `tcp` and `unix`") + } + + r.Name = Runtime(rs.Name) + r.Address = rs.Address + + return nil + } + + // if RuntimeAddress is not provided, get defaults + converted, err := ConvertRuntimeToRuntimeSpec(rt) + if err != nil { + return err + } + + *r = converted + default: + return fmt.Errorf("invalid runtime: valid names are %s, %s, %s", RuntimeContainerd, RuntimeDockerShim, RuntimeCrio) + } + + return nil +} + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. + +type OptionalContainerConfig struct { + Enabled bool `json:"enabled,omitempty"` + ContainerConfig `json:",inline"` +} + +type ContainerConfig struct { + Image RepoTag `json:"image,omitempty"` + Request ResourceRequirements `json:"request,omitempty"` + Limit ResourceRequirements `json:"limit,omitempty"` + Config *string `json:"config,omitempty"` +} + +type ManagerConfig struct { + Runtime RuntimeSpec `json:"runtime,omitempty"` + OTLPEndpoint string `json:"otlpEndpoint,omitempty"` + LogLevel string `json:"logLevel,omitempty"` + Scheduling ScheduleConfig `json:"scheduling,omitempty"` + Profile ProfileConfig `json:"profile,omitempty"` + ImageJob ImageJobConfig `json:"imageJob,omitempty"` + PullSecrets []string `json:"pullSecrets,omitempty"` + NodeFilter NodeFilterConfig `json:"nodeFilter,omitempty"` + PriorityClassName string `json:"priorityClassName,omitempty"` +} + +type ScheduleConfig struct { + RepeatInterval Duration `json:"repeatInterval,omitempty"` + BeginImmediately bool `json:"beginImmediately,omitempty"` +} + +type ProfileConfig struct { + Enabled bool `json:"enabled,omitempty"` + Port int `json:"port,omitempty"` +} + +type ImageJobConfig struct { + SuccessRatio float64 `json:"successRatio,omitempty"` + Cleanup ImageJobCleanupConfig `json:"cleanup,omitempty"` +} + +type ImageJobCleanupConfig struct { + DelayOnSuccess Duration `json:"delayOnSuccess,omitempty"` + DelayOnFailure Duration `json:"delayOnFailure,omitempty"` +} + +type NodeFilterConfig struct { + Type string `json:"type,omitempty"` + Selectors []string `json:"selectors,omitempty"` +} + +type ResourceRequirements struct { + Mem resource.Quantity `json:"mem,omitempty"` + CPU resource.Quantity `json:"cpu,omitempty"` +} + +type RepoTag struct { + Repo string `json:"repo,omitempty"` + Tag string `json:"tag,omitempty"` +} + +type Components struct { + Collector OptionalContainerConfig `json:"collector,omitempty"` + Scanner OptionalContainerConfig `json:"scanner,omitempty"` + Remover ContainerConfig `json:"remover,omitempty"` +} + +//+kubebuilder:object:root=true + +// EraserConfig is the Schema for the eraserconfigs API. +type EraserConfig struct { + metav1.TypeMeta `json:",inline"` + Manager ManagerConfig `json:"manager"` + Components Components `json:"components"` +} + +func init() { + SchemeBuilder.Register(&EraserConfig{}) +} diff --git a/api/v1alpha3/groupversion_info.go b/api/v1alpha3/groupversion_info.go new file mode 100644 index 0000000000..159d2efd97 --- /dev/null +++ b/api/v1alpha3/groupversion_info.go @@ -0,0 +1,39 @@ +/* +Copyright 2021. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Package v1alpha3 contains API Schema definitions for the eraser.sh v1alpha3 API group +// +kubebuilder:object:generate=true +// +groupName=eraser.sh +package v1alpha3 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/scheme" +) + +var ( + // GroupVersion is group version used to register these objects. + GroupVersion = schema.GroupVersion{Group: "eraser.sh", Version: "v1alpha3"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme. + SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} + + localSchemeBuilder = runtime.NewSchemeBuilder(SchemeBuilder.AddToScheme) + + // AddToScheme adds the types in this group-version to the given scheme. + AddToScheme = SchemeBuilder.AddToScheme +) diff --git a/api/v1alpha3/runtime_spec_test.go b/api/v1alpha3/runtime_spec_test.go new file mode 100644 index 0000000000..15a52fc7b9 --- /dev/null +++ b/api/v1alpha3/runtime_spec_test.go @@ -0,0 +1,111 @@ +package v1alpha3 + +import ( + "encoding/json" + "fmt" + "testing" +) + +func TestConvertRuntimeToRuntimeSpec(t *testing.T) { + type testCase struct { + input Runtime + expected RuntimeSpec + shouldErr bool + } + + tests := map[string]testCase{ + "Containerd": { + input: RuntimeContainerd, + expected: RuntimeSpec{Name: RuntimeContainerd, Address: fmt.Sprintf("unix://%s", ContainerdPath)}, + shouldErr: false, + }, + "DockerShim": { + input: RuntimeDockerShim, + expected: RuntimeSpec{Name: RuntimeDockerShim, Address: fmt.Sprintf("unix://%s", DockerPath)}, + shouldErr: false, + }, + "Crio": { + input: RuntimeCrio, + expected: RuntimeSpec{Name: RuntimeCrio, Address: fmt.Sprintf("unix://%s", CrioPath)}, + shouldErr: false, + }, + "InvalidRuntime": { + input: "invalid", + expected: RuntimeSpec{}, + shouldErr: true, + }, + } + + for name, test := range tests { + t.Run(name, func(t *testing.T) { + result, err := ConvertRuntimeToRuntimeSpec(test.input) + + if test.shouldErr && err == nil { + t.Errorf("Expected an error but got nil") + } + + if !test.shouldErr && err != nil { + t.Errorf("Error: %v", err) + } + + if result != test.expected { + t.Errorf("Unexpected result. Expected %v, but got %v", test.expected, result) + } + }) + } +} + +func TestUnmarshalJSON(t *testing.T) { + type testCase struct { + input []byte + expected RuntimeSpec + shouldErr bool + } + + tests := map[string]testCase{ + "ValidContainerd": { + input: []byte(`{"name": "containerd", "address": "unix:///run/containerd/containerd.sock"}`), + expected: RuntimeSpec{Name: RuntimeContainerd, Address: fmt.Sprintf("unix://%s", ContainerdPath)}, + shouldErr: false, + }, + "ValidDockerShim": { + input: []byte(`{"name": "dockershim", "address": "unix:///run/dockershim.sock"}`), + expected: RuntimeSpec{Name: RuntimeDockerShim, Address: fmt.Sprintf("unix://%s", DockerPath)}, + shouldErr: false, + }, + "ValidCrio": { + input: []byte(`{"name": "crio", "address": "unix:///run/crio/crio.sock"}`), + expected: RuntimeSpec{Name: RuntimeCrio, Address: fmt.Sprintf("unix://%s", CrioPath)}, + shouldErr: false, + }, + "InvalidName": { + input: []byte(`{"name": "invalid", "address": "unix:///invalid"}`), + expected: RuntimeSpec{}, + shouldErr: true, + }, + "InvalidAddressScheme": { + input: []byte(`{"name": "containerd", "address": "http://invalid"}`), + expected: RuntimeSpec{}, + shouldErr: true, + }, + } + + for name, test := range tests { + t.Run(name, func(t *testing.T) { + var rs RuntimeSpec + err := json.Unmarshal(test.input, &rs) + + if test.shouldErr && err == nil { + t.Error("Expected an error but got nil") + } + + if !test.shouldErr && err != nil { + t.Errorf("Error: %v", err) + } + + if rs != test.expected { + t.Errorf("Unexpected result. Expected %v, but got %v", test.expected, rs) + } + }) + } +} diff --git a/api/v1alpha3/zz_generated.conversion.go b/api/v1alpha3/zz_generated.conversion.go new file mode 100644 index 0000000000..b5655e6d7e --- /dev/null +++ b/api/v1alpha3/zz_generated.conversion.go @@ -0,0 +1,535 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright 2021. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +// Code generated by conversion-gen. DO NOT EDIT. + +package v1alpha3 + +import ( + unsafe "unsafe" + + unversioned "github.com/eraser-dev/eraser/api/unversioned" + conversion "k8s.io/apimachinery/pkg/conversion" + runtime "k8s.io/apimachinery/pkg/runtime" +) + +func init() { + localSchemeBuilder.Register(RegisterConversions) +} + +// RegisterConversions adds conversion functions to the given scheme. +// Public to allow building arbitrary schemes. +func RegisterConversions(s *runtime.Scheme) error { + if err := s.AddGeneratedConversionFunc((*Components)(nil), (*unversioned.Components)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_Components_To_unversioned_Components(a.(*Components), b.(*unversioned.Components), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*unversioned.Components)(nil), (*Components)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_unversioned_Components_To_v1alpha3_Components(a.(*unversioned.Components), b.(*Components), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*ContainerConfig)(nil), (*unversioned.ContainerConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_ContainerConfig_To_unversioned_ContainerConfig(a.(*ContainerConfig), b.(*unversioned.ContainerConfig), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*unversioned.ContainerConfig)(nil), (*ContainerConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_unversioned_ContainerConfig_To_v1alpha3_ContainerConfig(a.(*unversioned.ContainerConfig), b.(*ContainerConfig), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*EraserConfig)(nil), (*unversioned.EraserConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_EraserConfig_To_unversioned_EraserConfig(a.(*EraserConfig), b.(*unversioned.EraserConfig), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*unversioned.EraserConfig)(nil), (*EraserConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_unversioned_EraserConfig_To_v1alpha3_EraserConfig(a.(*unversioned.EraserConfig), b.(*EraserConfig), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*ImageJobCleanupConfig)(nil), (*unversioned.ImageJobCleanupConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_ImageJobCleanupConfig_To_unversioned_ImageJobCleanupConfig(a.(*ImageJobCleanupConfig), b.(*unversioned.ImageJobCleanupConfig), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*unversioned.ImageJobCleanupConfig)(nil), (*ImageJobCleanupConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_unversioned_ImageJobCleanupConfig_To_v1alpha3_ImageJobCleanupConfig(a.(*unversioned.ImageJobCleanupConfig), b.(*ImageJobCleanupConfig), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*ImageJobConfig)(nil), (*unversioned.ImageJobConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_ImageJobConfig_To_unversioned_ImageJobConfig(a.(*ImageJobConfig), b.(*unversioned.ImageJobConfig), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*unversioned.ImageJobConfig)(nil), (*ImageJobConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_unversioned_ImageJobConfig_To_v1alpha3_ImageJobConfig(a.(*unversioned.ImageJobConfig), b.(*ImageJobConfig), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*ManagerConfig)(nil), (*unversioned.ManagerConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_ManagerConfig_To_unversioned_ManagerConfig(a.(*ManagerConfig), b.(*unversioned.ManagerConfig), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*unversioned.ManagerConfig)(nil), (*ManagerConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_unversioned_ManagerConfig_To_v1alpha3_ManagerConfig(a.(*unversioned.ManagerConfig), b.(*ManagerConfig), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*NodeFilterConfig)(nil), (*unversioned.NodeFilterConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_NodeFilterConfig_To_unversioned_NodeFilterConfig(a.(*NodeFilterConfig), b.(*unversioned.NodeFilterConfig), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*unversioned.NodeFilterConfig)(nil), (*NodeFilterConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_unversioned_NodeFilterConfig_To_v1alpha3_NodeFilterConfig(a.(*unversioned.NodeFilterConfig), b.(*NodeFilterConfig), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*OptionalContainerConfig)(nil), (*unversioned.OptionalContainerConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_OptionalContainerConfig_To_unversioned_OptionalContainerConfig(a.(*OptionalContainerConfig), b.(*unversioned.OptionalContainerConfig), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*unversioned.OptionalContainerConfig)(nil), (*OptionalContainerConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_unversioned_OptionalContainerConfig_To_v1alpha3_OptionalContainerConfig(a.(*unversioned.OptionalContainerConfig), b.(*OptionalContainerConfig), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*ProfileConfig)(nil), (*unversioned.ProfileConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_ProfileConfig_To_unversioned_ProfileConfig(a.(*ProfileConfig), b.(*unversioned.ProfileConfig), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*unversioned.ProfileConfig)(nil), (*ProfileConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_unversioned_ProfileConfig_To_v1alpha3_ProfileConfig(a.(*unversioned.ProfileConfig), b.(*ProfileConfig), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*RepoTag)(nil), (*unversioned.RepoTag)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_RepoTag_To_unversioned_RepoTag(a.(*RepoTag), b.(*unversioned.RepoTag), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*unversioned.RepoTag)(nil), (*RepoTag)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_unversioned_RepoTag_To_v1alpha3_RepoTag(a.(*unversioned.RepoTag), b.(*RepoTag), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*ResourceRequirements)(nil), (*unversioned.ResourceRequirements)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_ResourceRequirements_To_unversioned_ResourceRequirements(a.(*ResourceRequirements), b.(*unversioned.ResourceRequirements), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*unversioned.ResourceRequirements)(nil), (*ResourceRequirements)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_unversioned_ResourceRequirements_To_v1alpha3_ResourceRequirements(a.(*unversioned.ResourceRequirements), b.(*ResourceRequirements), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*RuntimeSpec)(nil), (*unversioned.RuntimeSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_RuntimeSpec_To_unversioned_RuntimeSpec(a.(*RuntimeSpec), b.(*unversioned.RuntimeSpec), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*unversioned.RuntimeSpec)(nil), (*RuntimeSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_unversioned_RuntimeSpec_To_v1alpha3_RuntimeSpec(a.(*unversioned.RuntimeSpec), b.(*RuntimeSpec), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*ScheduleConfig)(nil), (*unversioned.ScheduleConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_ScheduleConfig_To_unversioned_ScheduleConfig(a.(*ScheduleConfig), b.(*unversioned.ScheduleConfig), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*unversioned.ScheduleConfig)(nil), (*ScheduleConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_unversioned_ScheduleConfig_To_v1alpha3_ScheduleConfig(a.(*unversioned.ScheduleConfig), b.(*ScheduleConfig), scope) + }); err != nil { + return err + } + return nil +} + +func autoConvert_v1alpha3_Components_To_unversioned_Components(in *Components, out *unversioned.Components, s conversion.Scope) error { + if err := Convert_v1alpha3_OptionalContainerConfig_To_unversioned_OptionalContainerConfig(&in.Collector, &out.Collector, s); err != nil { + return err + } + if err := Convert_v1alpha3_OptionalContainerConfig_To_unversioned_OptionalContainerConfig(&in.Scanner, &out.Scanner, s); err != nil { + return err + } + if err := Convert_v1alpha3_ContainerConfig_To_unversioned_ContainerConfig(&in.Remover, &out.Remover, s); err != nil { + return err + } + return nil +} + +// Convert_v1alpha3_Components_To_unversioned_Components is an autogenerated conversion function. +func Convert_v1alpha3_Components_To_unversioned_Components(in *Components, out *unversioned.Components, s conversion.Scope) error { + return autoConvert_v1alpha3_Components_To_unversioned_Components(in, out, s) +} + +func autoConvert_unversioned_Components_To_v1alpha3_Components(in *unversioned.Components, out *Components, s conversion.Scope) error { + if err := Convert_unversioned_OptionalContainerConfig_To_v1alpha3_OptionalContainerConfig(&in.Collector, &out.Collector, s); err != nil { + return err + } + if err := Convert_unversioned_OptionalContainerConfig_To_v1alpha3_OptionalContainerConfig(&in.Scanner, &out.Scanner, s); err != nil { + return err + } + if err := Convert_unversioned_ContainerConfig_To_v1alpha3_ContainerConfig(&in.Remover, &out.Remover, s); err != nil { + return err + } + return nil +} + +// Convert_unversioned_Components_To_v1alpha3_Components is an autogenerated conversion function. +func Convert_unversioned_Components_To_v1alpha3_Components(in *unversioned.Components, out *Components, s conversion.Scope) error { + return autoConvert_unversioned_Components_To_v1alpha3_Components(in, out, s) +} + +func autoConvert_v1alpha3_ContainerConfig_To_unversioned_ContainerConfig(in *ContainerConfig, out *unversioned.ContainerConfig, s conversion.Scope) error { + if err := Convert_v1alpha3_RepoTag_To_unversioned_RepoTag(&in.Image, &out.Image, s); err != nil { + return err + } + if err := Convert_v1alpha3_ResourceRequirements_To_unversioned_ResourceRequirements(&in.Request, &out.Request, s); err != nil { + return err + } + if err := Convert_v1alpha3_ResourceRequirements_To_unversioned_ResourceRequirements(&in.Limit, &out.Limit, s); err != nil { + return err + } + out.Config = (*string)(unsafe.Pointer(in.Config)) + return nil +} + +// Convert_v1alpha3_ContainerConfig_To_unversioned_ContainerConfig is an autogenerated conversion function. +func Convert_v1alpha3_ContainerConfig_To_unversioned_ContainerConfig(in *ContainerConfig, out *unversioned.ContainerConfig, s conversion.Scope) error { + return autoConvert_v1alpha3_ContainerConfig_To_unversioned_ContainerConfig(in, out, s) +} + +func autoConvert_unversioned_ContainerConfig_To_v1alpha3_ContainerConfig(in *unversioned.ContainerConfig, out *ContainerConfig, s conversion.Scope) error { + if err := Convert_unversioned_RepoTag_To_v1alpha3_RepoTag(&in.Image, &out.Image, s); err != nil { + return err + } + if err := Convert_unversioned_ResourceRequirements_To_v1alpha3_ResourceRequirements(&in.Request, &out.Request, s); err != nil { + return err + } + if err := Convert_unversioned_ResourceRequirements_To_v1alpha3_ResourceRequirements(&in.Limit, &out.Limit, s); err != nil { + return err + } + out.Config = (*string)(unsafe.Pointer(in.Config)) + return nil +} + +// Convert_unversioned_ContainerConfig_To_v1alpha3_ContainerConfig is an autogenerated conversion function. +func Convert_unversioned_ContainerConfig_To_v1alpha3_ContainerConfig(in *unversioned.ContainerConfig, out *ContainerConfig, s conversion.Scope) error { + return autoConvert_unversioned_ContainerConfig_To_v1alpha3_ContainerConfig(in, out, s) +} + +func autoConvert_v1alpha3_EraserConfig_To_unversioned_EraserConfig(in *EraserConfig, out *unversioned.EraserConfig, s conversion.Scope) error { + if err := Convert_v1alpha3_ManagerConfig_To_unversioned_ManagerConfig(&in.Manager, &out.Manager, s); err != nil { + return err + } + if err := Convert_v1alpha3_Components_To_unversioned_Components(&in.Components, &out.Components, s); err != nil { + return err + } + return nil +} + +// Convert_v1alpha3_EraserConfig_To_unversioned_EraserConfig is an autogenerated conversion function. +func Convert_v1alpha3_EraserConfig_To_unversioned_EraserConfig(in *EraserConfig, out *unversioned.EraserConfig, s conversion.Scope) error { + return autoConvert_v1alpha3_EraserConfig_To_unversioned_EraserConfig(in, out, s) +} + +func autoConvert_unversioned_EraserConfig_To_v1alpha3_EraserConfig(in *unversioned.EraserConfig, out *EraserConfig, s conversion.Scope) error { + if err := Convert_unversioned_ManagerConfig_To_v1alpha3_ManagerConfig(&in.Manager, &out.Manager, s); err != nil { + return err + } + if err := Convert_unversioned_Components_To_v1alpha3_Components(&in.Components, &out.Components, s); err != nil { + return err + } + return nil +} + +// Convert_unversioned_EraserConfig_To_v1alpha3_EraserConfig is an autogenerated conversion function. +func Convert_unversioned_EraserConfig_To_v1alpha3_EraserConfig(in *unversioned.EraserConfig, out *EraserConfig, s conversion.Scope) error { + return autoConvert_unversioned_EraserConfig_To_v1alpha3_EraserConfig(in, out, s) +} + +func autoConvert_v1alpha3_ImageJobCleanupConfig_To_unversioned_ImageJobCleanupConfig(in *ImageJobCleanupConfig, out *unversioned.ImageJobCleanupConfig, s conversion.Scope) error { + out.DelayOnSuccess = unversioned.Duration(in.DelayOnSuccess) + out.DelayOnFailure = unversioned.Duration(in.DelayOnFailure) + return nil +} + +// Convert_v1alpha3_ImageJobCleanupConfig_To_unversioned_ImageJobCleanupConfig is an autogenerated conversion function. +func Convert_v1alpha3_ImageJobCleanupConfig_To_unversioned_ImageJobCleanupConfig(in *ImageJobCleanupConfig, out *unversioned.ImageJobCleanupConfig, s conversion.Scope) error { + return autoConvert_v1alpha3_ImageJobCleanupConfig_To_unversioned_ImageJobCleanupConfig(in, out, s) +} + +func autoConvert_unversioned_ImageJobCleanupConfig_To_v1alpha3_ImageJobCleanupConfig(in *unversioned.ImageJobCleanupConfig, out *ImageJobCleanupConfig, s conversion.Scope) error { + out.DelayOnSuccess = Duration(in.DelayOnSuccess) + out.DelayOnFailure = Duration(in.DelayOnFailure) + return nil +} + +// Convert_unversioned_ImageJobCleanupConfig_To_v1alpha3_ImageJobCleanupConfig is an autogenerated conversion function. +func Convert_unversioned_ImageJobCleanupConfig_To_v1alpha3_ImageJobCleanupConfig(in *unversioned.ImageJobCleanupConfig, out *ImageJobCleanupConfig, s conversion.Scope) error { + return autoConvert_unversioned_ImageJobCleanupConfig_To_v1alpha3_ImageJobCleanupConfig(in, out, s) +} + +func autoConvert_v1alpha3_ImageJobConfig_To_unversioned_ImageJobConfig(in *ImageJobConfig, out *unversioned.ImageJobConfig, s conversion.Scope) error { + out.SuccessRatio = in.SuccessRatio + if err := Convert_v1alpha3_ImageJobCleanupConfig_To_unversioned_ImageJobCleanupConfig(&in.Cleanup, &out.Cleanup, s); err != nil { + return err + } + return nil +} + +// Convert_v1alpha3_ImageJobConfig_To_unversioned_ImageJobConfig is an autogenerated conversion function. +func Convert_v1alpha3_ImageJobConfig_To_unversioned_ImageJobConfig(in *ImageJobConfig, out *unversioned.ImageJobConfig, s conversion.Scope) error { + return autoConvert_v1alpha3_ImageJobConfig_To_unversioned_ImageJobConfig(in, out, s) +} + +func autoConvert_unversioned_ImageJobConfig_To_v1alpha3_ImageJobConfig(in *unversioned.ImageJobConfig, out *ImageJobConfig, s conversion.Scope) error { + out.SuccessRatio = in.SuccessRatio + if err := Convert_unversioned_ImageJobCleanupConfig_To_v1alpha3_ImageJobCleanupConfig(&in.Cleanup, &out.Cleanup, s); err != nil { + return err + } + return nil +} + +// Convert_unversioned_ImageJobConfig_To_v1alpha3_ImageJobConfig is an autogenerated conversion function. +func Convert_unversioned_ImageJobConfig_To_v1alpha3_ImageJobConfig(in *unversioned.ImageJobConfig, out *ImageJobConfig, s conversion.Scope) error { + return autoConvert_unversioned_ImageJobConfig_To_v1alpha3_ImageJobConfig(in, out, s) +} + +func autoConvert_v1alpha3_ManagerConfig_To_unversioned_ManagerConfig(in *ManagerConfig, out *unversioned.ManagerConfig, s conversion.Scope) error { + if err := Convert_v1alpha3_RuntimeSpec_To_unversioned_RuntimeSpec(&in.Runtime, &out.Runtime, s); err != nil { + return err + } + out.OTLPEndpoint = in.OTLPEndpoint + out.LogLevel = in.LogLevel + if err := Convert_v1alpha3_ScheduleConfig_To_unversioned_ScheduleConfig(&in.Scheduling, &out.Scheduling, s); err != nil { + return err + } + if err := Convert_v1alpha3_ProfileConfig_To_unversioned_ProfileConfig(&in.Profile, &out.Profile, s); err != nil { + return err + } + if err := Convert_v1alpha3_ImageJobConfig_To_unversioned_ImageJobConfig(&in.ImageJob, &out.ImageJob, s); err != nil { + return err + } + out.PullSecrets = *(*[]string)(unsafe.Pointer(&in.PullSecrets)) + if err := Convert_v1alpha3_NodeFilterConfig_To_unversioned_NodeFilterConfig(&in.NodeFilter, &out.NodeFilter, s); err != nil { + return err + } + out.PriorityClassName = in.PriorityClassName + return nil +} + +// Convert_v1alpha3_ManagerConfig_To_unversioned_ManagerConfig is an autogenerated conversion function. +func Convert_v1alpha3_ManagerConfig_To_unversioned_ManagerConfig(in *ManagerConfig, out *unversioned.ManagerConfig, s conversion.Scope) error { + return autoConvert_v1alpha3_ManagerConfig_To_unversioned_ManagerConfig(in, out, s) +} + +func autoConvert_unversioned_ManagerConfig_To_v1alpha3_ManagerConfig(in *unversioned.ManagerConfig, out *ManagerConfig, s conversion.Scope) error { + if err := Convert_unversioned_RuntimeSpec_To_v1alpha3_RuntimeSpec(&in.Runtime, &out.Runtime, s); err != nil { + return err + } + out.OTLPEndpoint = in.OTLPEndpoint + out.LogLevel = in.LogLevel + if err := Convert_unversioned_ScheduleConfig_To_v1alpha3_ScheduleConfig(&in.Scheduling, &out.Scheduling, s); err != nil { + return err + } + if err := Convert_unversioned_ProfileConfig_To_v1alpha3_ProfileConfig(&in.Profile, &out.Profile, s); err != nil { + return err + } + if err := Convert_unversioned_ImageJobConfig_To_v1alpha3_ImageJobConfig(&in.ImageJob, &out.ImageJob, s); err != nil { + return err + } + out.PullSecrets = *(*[]string)(unsafe.Pointer(&in.PullSecrets)) + if err := Convert_unversioned_NodeFilterConfig_To_v1alpha3_NodeFilterConfig(&in.NodeFilter, &out.NodeFilter, s); err != nil { + return err + } + out.PriorityClassName = in.PriorityClassName + return nil +} + +// Convert_unversioned_ManagerConfig_To_v1alpha3_ManagerConfig is an autogenerated conversion function. +func Convert_unversioned_ManagerConfig_To_v1alpha3_ManagerConfig(in *unversioned.ManagerConfig, out *ManagerConfig, s conversion.Scope) error { + return autoConvert_unversioned_ManagerConfig_To_v1alpha3_ManagerConfig(in, out, s) +} + +func autoConvert_v1alpha3_NodeFilterConfig_To_unversioned_NodeFilterConfig(in *NodeFilterConfig, out *unversioned.NodeFilterConfig, s conversion.Scope) error { + out.Type = in.Type + out.Selectors = *(*[]string)(unsafe.Pointer(&in.Selectors)) + return nil +} + +// Convert_v1alpha3_NodeFilterConfig_To_unversioned_NodeFilterConfig is an autogenerated conversion function. +func Convert_v1alpha3_NodeFilterConfig_To_unversioned_NodeFilterConfig(in *NodeFilterConfig, out *unversioned.NodeFilterConfig, s conversion.Scope) error { + return autoConvert_v1alpha3_NodeFilterConfig_To_unversioned_NodeFilterConfig(in, out, s) +} + +func autoConvert_unversioned_NodeFilterConfig_To_v1alpha3_NodeFilterConfig(in *unversioned.NodeFilterConfig, out *NodeFilterConfig, s conversion.Scope) error { + out.Type = in.Type + out.Selectors = *(*[]string)(unsafe.Pointer(&in.Selectors)) + return nil +} + +// Convert_unversioned_NodeFilterConfig_To_v1alpha3_NodeFilterConfig is an autogenerated conversion function. +func Convert_unversioned_NodeFilterConfig_To_v1alpha3_NodeFilterConfig(in *unversioned.NodeFilterConfig, out *NodeFilterConfig, s conversion.Scope) error { + return autoConvert_unversioned_NodeFilterConfig_To_v1alpha3_NodeFilterConfig(in, out, s) +} + +func autoConvert_v1alpha3_OptionalContainerConfig_To_unversioned_OptionalContainerConfig(in *OptionalContainerConfig, out *unversioned.OptionalContainerConfig, s conversion.Scope) error { + out.Enabled = in.Enabled + if err := Convert_v1alpha3_ContainerConfig_To_unversioned_ContainerConfig(&in.ContainerConfig, &out.ContainerConfig, s); err != nil { + return err + } + return nil +} + +// Convert_v1alpha3_OptionalContainerConfig_To_unversioned_OptionalContainerConfig is an autogenerated conversion function. +func Convert_v1alpha3_OptionalContainerConfig_To_unversioned_OptionalContainerConfig(in *OptionalContainerConfig, out *unversioned.OptionalContainerConfig, s conversion.Scope) error { + return autoConvert_v1alpha3_OptionalContainerConfig_To_unversioned_OptionalContainerConfig(in, out, s) +} + +func autoConvert_unversioned_OptionalContainerConfig_To_v1alpha3_OptionalContainerConfig(in *unversioned.OptionalContainerConfig, out *OptionalContainerConfig, s conversion.Scope) error { + out.Enabled = in.Enabled + if err := Convert_unversioned_ContainerConfig_To_v1alpha3_ContainerConfig(&in.ContainerConfig, &out.ContainerConfig, s); err != nil { + return err + } + return nil +} + +// Convert_unversioned_OptionalContainerConfig_To_v1alpha3_OptionalContainerConfig is an autogenerated conversion function. +func Convert_unversioned_OptionalContainerConfig_To_v1alpha3_OptionalContainerConfig(in *unversioned.OptionalContainerConfig, out *OptionalContainerConfig, s conversion.Scope) error { + return autoConvert_unversioned_OptionalContainerConfig_To_v1alpha3_OptionalContainerConfig(in, out, s) +} + +func autoConvert_v1alpha3_ProfileConfig_To_unversioned_ProfileConfig(in *ProfileConfig, out *unversioned.ProfileConfig, s conversion.Scope) error { + out.Enabled = in.Enabled + out.Port = in.Port + return nil +} + +// Convert_v1alpha3_ProfileConfig_To_unversioned_ProfileConfig is an autogenerated conversion function. +func Convert_v1alpha3_ProfileConfig_To_unversioned_ProfileConfig(in *ProfileConfig, out *unversioned.ProfileConfig, s conversion.Scope) error { + return autoConvert_v1alpha3_ProfileConfig_To_unversioned_ProfileConfig(in, out, s) +} + +func autoConvert_unversioned_ProfileConfig_To_v1alpha3_ProfileConfig(in *unversioned.ProfileConfig, out *ProfileConfig, s conversion.Scope) error { + out.Enabled = in.Enabled + out.Port = in.Port + return nil +} + +// Convert_unversioned_ProfileConfig_To_v1alpha3_ProfileConfig is an autogenerated conversion function. +func Convert_unversioned_ProfileConfig_To_v1alpha3_ProfileConfig(in *unversioned.ProfileConfig, out *ProfileConfig, s conversion.Scope) error { + return autoConvert_unversioned_ProfileConfig_To_v1alpha3_ProfileConfig(in, out, s) +} + +func autoConvert_v1alpha3_RepoTag_To_unversioned_RepoTag(in *RepoTag, out *unversioned.RepoTag, s conversion.Scope) error { + out.Repo = in.Repo + out.Tag = in.Tag + return nil +} + +// Convert_v1alpha3_RepoTag_To_unversioned_RepoTag is an autogenerated conversion function. +func Convert_v1alpha3_RepoTag_To_unversioned_RepoTag(in *RepoTag, out *unversioned.RepoTag, s conversion.Scope) error { + return autoConvert_v1alpha3_RepoTag_To_unversioned_RepoTag(in, out, s) +} + +func autoConvert_unversioned_RepoTag_To_v1alpha3_RepoTag(in *unversioned.RepoTag, out *RepoTag, s conversion.Scope) error { + out.Repo = in.Repo + out.Tag = in.Tag + return nil +} + +// Convert_unversioned_RepoTag_To_v1alpha3_RepoTag is an autogenerated conversion function. +func Convert_unversioned_RepoTag_To_v1alpha3_RepoTag(in *unversioned.RepoTag, out *RepoTag, s conversion.Scope) error { + return autoConvert_unversioned_RepoTag_To_v1alpha3_RepoTag(in, out, s) +} + +func autoConvert_v1alpha3_ResourceRequirements_To_unversioned_ResourceRequirements(in *ResourceRequirements, out *unversioned.ResourceRequirements, s conversion.Scope) error { + out.Mem = in.Mem + out.CPU = in.CPU + return nil +} + +// Convert_v1alpha3_ResourceRequirements_To_unversioned_ResourceRequirements is an autogenerated conversion function. +func Convert_v1alpha3_ResourceRequirements_To_unversioned_ResourceRequirements(in *ResourceRequirements, out *unversioned.ResourceRequirements, s conversion.Scope) error { + return autoConvert_v1alpha3_ResourceRequirements_To_unversioned_ResourceRequirements(in, out, s) +} + +func autoConvert_unversioned_ResourceRequirements_To_v1alpha3_ResourceRequirements(in *unversioned.ResourceRequirements, out *ResourceRequirements, s conversion.Scope) error { + out.Mem = in.Mem + out.CPU = in.CPU + return nil +} + +// Convert_unversioned_ResourceRequirements_To_v1alpha3_ResourceRequirements is an autogenerated conversion function. +func Convert_unversioned_ResourceRequirements_To_v1alpha3_ResourceRequirements(in *unversioned.ResourceRequirements, out *ResourceRequirements, s conversion.Scope) error { + return autoConvert_unversioned_ResourceRequirements_To_v1alpha3_ResourceRequirements(in, out, s) +} + +func autoConvert_v1alpha3_RuntimeSpec_To_unversioned_RuntimeSpec(in *RuntimeSpec, out *unversioned.RuntimeSpec, s conversion.Scope) error { + out.Name = unversioned.Runtime(in.Name) + out.Address = in.Address + return nil +} + +// Convert_v1alpha3_RuntimeSpec_To_unversioned_RuntimeSpec is an autogenerated conversion function. +func Convert_v1alpha3_RuntimeSpec_To_unversioned_RuntimeSpec(in *RuntimeSpec, out *unversioned.RuntimeSpec, s conversion.Scope) error { + return autoConvert_v1alpha3_RuntimeSpec_To_unversioned_RuntimeSpec(in, out, s) +} + +func autoConvert_unversioned_RuntimeSpec_To_v1alpha3_RuntimeSpec(in *unversioned.RuntimeSpec, out *RuntimeSpec, s conversion.Scope) error { + out.Name = Runtime(in.Name) + out.Address = in.Address + return nil +} + +// Convert_unversioned_RuntimeSpec_To_v1alpha3_RuntimeSpec is an autogenerated conversion function. +func Convert_unversioned_RuntimeSpec_To_v1alpha3_RuntimeSpec(in *unversioned.RuntimeSpec, out *RuntimeSpec, s conversion.Scope) error { + return autoConvert_unversioned_RuntimeSpec_To_v1alpha3_RuntimeSpec(in, out, s) +} + +func autoConvert_v1alpha3_ScheduleConfig_To_unversioned_ScheduleConfig(in *ScheduleConfig, out *unversioned.ScheduleConfig, s conversion.Scope) error { + out.RepeatInterval = unversioned.Duration(in.RepeatInterval) + out.BeginImmediately = in.BeginImmediately + return nil +} + +// Convert_v1alpha3_ScheduleConfig_To_unversioned_ScheduleConfig is an autogenerated conversion function. +func Convert_v1alpha3_ScheduleConfig_To_unversioned_ScheduleConfig(in *ScheduleConfig, out *unversioned.ScheduleConfig, s conversion.Scope) error { + return autoConvert_v1alpha3_ScheduleConfig_To_unversioned_ScheduleConfig(in, out, s) +} + +func autoConvert_unversioned_ScheduleConfig_To_v1alpha3_ScheduleConfig(in *unversioned.ScheduleConfig, out *ScheduleConfig, s conversion.Scope) error { + out.RepeatInterval = Duration(in.RepeatInterval) + out.BeginImmediately = in.BeginImmediately + return nil +} + +// Convert_unversioned_ScheduleConfig_To_v1alpha3_ScheduleConfig is an autogenerated conversion function. +func Convert_unversioned_ScheduleConfig_To_v1alpha3_ScheduleConfig(in *unversioned.ScheduleConfig, out *ScheduleConfig, s conversion.Scope) error { + return autoConvert_unversioned_ScheduleConfig_To_v1alpha3_ScheduleConfig(in, out, s) +} diff --git a/api/v1alpha3/zz_generated.deepcopy.go b/api/v1alpha3/zz_generated.deepcopy.go new file mode 100644 index 0000000000..9952c98b34 --- /dev/null +++ b/api/v1alpha3/zz_generated.deepcopy.go @@ -0,0 +1,262 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright 2021. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by controller-gen. DO NOT EDIT. + +package v1alpha3 + +import ( + "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Components) DeepCopyInto(out *Components) { + *out = *in + in.Collector.DeepCopyInto(&out.Collector) + in.Scanner.DeepCopyInto(&out.Scanner) + in.Remover.DeepCopyInto(&out.Remover) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Components. +func (in *Components) DeepCopy() *Components { + if in == nil { + return nil + } + out := new(Components) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ContainerConfig) DeepCopyInto(out *ContainerConfig) { + *out = *in + out.Image = in.Image + in.Request.DeepCopyInto(&out.Request) + in.Limit.DeepCopyInto(&out.Limit) + if in.Config != nil { + in, out := &in.Config, &out.Config + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContainerConfig. +func (in *ContainerConfig) DeepCopy() *ContainerConfig { + if in == nil { + return nil + } + out := new(ContainerConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *EraserConfig) DeepCopyInto(out *EraserConfig) { + *out = *in + out.TypeMeta = in.TypeMeta + in.Manager.DeepCopyInto(&out.Manager) + in.Components.DeepCopyInto(&out.Components) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EraserConfig. +func (in *EraserConfig) DeepCopy() *EraserConfig { + if in == nil { + return nil + } + out := new(EraserConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *EraserConfig) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ImageJobCleanupConfig) DeepCopyInto(out *ImageJobCleanupConfig) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ImageJobCleanupConfig. +func (in *ImageJobCleanupConfig) DeepCopy() *ImageJobCleanupConfig { + if in == nil { + return nil + } + out := new(ImageJobCleanupConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ImageJobConfig) DeepCopyInto(out *ImageJobConfig) { + *out = *in + out.Cleanup = in.Cleanup +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ImageJobConfig. +func (in *ImageJobConfig) DeepCopy() *ImageJobConfig { + if in == nil { + return nil + } + out := new(ImageJobConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ManagerConfig) DeepCopyInto(out *ManagerConfig) { + *out = *in + out.Runtime = in.Runtime + out.Scheduling = in.Scheduling + out.Profile = in.Profile + out.ImageJob = in.ImageJob + if in.PullSecrets != nil { + in, out := &in.PullSecrets, &out.PullSecrets + *out = make([]string, len(*in)) + copy(*out, *in) + } + in.NodeFilter.DeepCopyInto(&out.NodeFilter) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ManagerConfig. +func (in *ManagerConfig) DeepCopy() *ManagerConfig { + if in == nil { + return nil + } + out := new(ManagerConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NodeFilterConfig) DeepCopyInto(out *NodeFilterConfig) { + *out = *in + if in.Selectors != nil { + in, out := &in.Selectors, &out.Selectors + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeFilterConfig. +func (in *NodeFilterConfig) DeepCopy() *NodeFilterConfig { + if in == nil { + return nil + } + out := new(NodeFilterConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *OptionalContainerConfig) DeepCopyInto(out *OptionalContainerConfig) { + *out = *in + in.ContainerConfig.DeepCopyInto(&out.ContainerConfig) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OptionalContainerConfig. +func (in *OptionalContainerConfig) DeepCopy() *OptionalContainerConfig { + if in == nil { + return nil + } + out := new(OptionalContainerConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ProfileConfig) DeepCopyInto(out *ProfileConfig) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProfileConfig. +func (in *ProfileConfig) DeepCopy() *ProfileConfig { + if in == nil { + return nil + } + out := new(ProfileConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RepoTag) DeepCopyInto(out *RepoTag) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RepoTag. +func (in *RepoTag) DeepCopy() *RepoTag { + if in == nil { + return nil + } + out := new(RepoTag) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ResourceRequirements) DeepCopyInto(out *ResourceRequirements) { + *out = *in + out.Mem = in.Mem.DeepCopy() + out.CPU = in.CPU.DeepCopy() +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceRequirements. +func (in *ResourceRequirements) DeepCopy() *ResourceRequirements { + if in == nil { + return nil + } + out := new(ResourceRequirements) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RuntimeSpec) DeepCopyInto(out *RuntimeSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RuntimeSpec. +func (in *RuntimeSpec) DeepCopy() *RuntimeSpec { + if in == nil { + return nil + } + out := new(RuntimeSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ScheduleConfig) DeepCopyInto(out *ScheduleConfig) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ScheduleConfig. +func (in *ScheduleConfig) DeepCopy() *ScheduleConfig { + if in == nil { + return nil + } + out := new(ScheduleConfig) + in.DeepCopyInto(out) + return out +} diff --git a/config/manager/controller_manager_config.yaml b/config/manager/controller_manager_config.yaml index e871c65a38..25b6e9b797 100644 --- a/config/manager/controller_manager_config.yaml +++ b/config/manager/controller_manager_config.yaml @@ -1,7 +1,9 @@ -apiVersion: eraser.sh/v1alpha2 +apiVersion: eraser.sh/v1alpha3 kind: EraserConfig manager: - runtime: containerd + runtime: + name: containerd + address: unix:///run/containerd/containerd.sock otlpEndpoint: "" logLevel: info scheduling: diff --git a/main.go b/main.go index bdfcdbea19..489ee43dbd 100644 --- a/main.go +++ b/main.go @@ -46,6 +46,8 @@ import ( v1alpha1Config "github.com/eraser-dev/eraser/api/v1alpha1/config" eraserv1alpha2 "github.com/eraser-dev/eraser/api/v1alpha2" v1alpha2Config "github.com/eraser-dev/eraser/api/v1alpha2/config" + eraserv1alpha3 "github.com/eraser-dev/eraser/api/v1alpha3" + v1alpha3Config "github.com/eraser-dev/eraser/api/v1alpha3/config" "github.com/eraser-dev/eraser/controllers" "github.com/eraser-dev/eraser/pkg/logger" "github.com/eraser-dev/eraser/version" @@ -58,6 +60,7 @@ var ( fromV1alpha1 = eraserv1alpha1.Convert_v1alpha1_EraserConfig_To_unversioned_EraserConfig fromV1alpha2 = eraserv1alpha2.Convert_v1alpha2_EraserConfig_To_unversioned_EraserConfig + fromV1alpha3 = eraserv1alpha3.Convert_v1alpha3_EraserConfig_To_unversioned_EraserConfig ) func init() { @@ -196,6 +199,8 @@ func getConfig(configFile string) (*unversioned.EraserConfig, error) { return getUnversioned(fileBytes, v1alpha1Config.Default(), fromV1alpha1) case "eraser.sh/v1alpha2": return getUnversioned(fileBytes, v1alpha2Config.Default(), fromV1alpha2) + case "eraser.sh/v1alpha3": + return getUnversioned(fileBytes, v1alpha3Config.Default(), fromV1alpha3) default: setupLog.Error(fmt.Errorf("unknown api version"), "error", "apiVersion", av.APIVersion) return nil, err diff --git a/manifest_staging/charts/eraser/values.yaml b/manifest_staging/charts/eraser/values.yaml index aed59757ee..6053e45f96 100644 --- a/manifest_staging/charts/eraser/values.yaml +++ b/manifest_staging/charts/eraser/values.yaml @@ -1,5 +1,5 @@ runtimeConfig: - apiVersion: eraser.sh/v1alpha2 + apiVersion: eraser.sh/v1alpha3 kind: EraserConfig health: {} # healthProbeBindAddress: :8081 @@ -11,7 +11,9 @@ runtimeConfig: # leaderElect: true # resourceName: e29e094a.k8s.io manager: - runtime: containerd + runtime: + name: containerd + address: unix:///run/containerd/containerd.sock otlpEndpoint: "" logLevel: info scheduling: {} diff --git a/manifest_staging/deploy/eraser.yaml b/manifest_staging/deploy/eraser.yaml index 06f7fc5856..90fe701322 100644 --- a/manifest_staging/deploy/eraser.yaml +++ b/manifest_staging/deploy/eraser.yaml @@ -382,10 +382,12 @@ subjects: apiVersion: v1 data: controller_manager_config.yaml: | - apiVersion: eraser.sh/v1alpha2 + apiVersion: eraser.sh/v1alpha3 kind: EraserConfig manager: - runtime: containerd + runtime: + name: containerd + address: unix:///run/containerd/containerd.sock otlpEndpoint: "" logLevel: info scheduling: diff --git a/pkg/scanners/trivy/helpers.go b/pkg/scanners/trivy/helpers.go index 248e891d0a..695fd4adf8 100644 --- a/pkg/scanners/trivy/helpers.go +++ b/pkg/scanners/trivy/helpers.go @@ -12,13 +12,14 @@ func loadConfig(filename string) (Config, error) { b, err := os.ReadFile(filename) if err != nil { + log.Error(err, "unable to read eraser config") return cfg, err } var eraserConfig unversioned.EraserConfig err = yaml.Unmarshal(b, &eraserConfig) if err != nil { - return cfg, err + log.Error(err, "unable to unmarshal eraser config") } scanCfgYaml := eraserConfig.Components.Scanner.Config @@ -29,6 +30,7 @@ func loadConfig(filename string) (Config, error) { err = yaml.Unmarshal(scanCfgBytes, &cfg) if err != nil { + log.Error(err, "unable to unmarshal scanner config") return cfg, err } diff --git a/test/e2e/test-data/helm-empty-values.yaml b/test/e2e/test-data/helm-empty-values.yaml index d445f09394..dfe09ea260 100644 --- a/test/e2e/test-data/helm-empty-values.yaml +++ b/test/e2e/test-data/helm-empty-values.yaml @@ -13,7 +13,11 @@ # used, the test will fail. runtimeConfig: - apiVersion: eraser.sh/v1alpha2 + apiVersion: eraser.sh/v1alpha3 + manager: + runtime: + name: containerd + address: unix:///run/containerd/containerd.sock components: collector: image: diff --git a/third_party/open-policy-agent/gatekeeper/helmify/static/values.yaml b/third_party/open-policy-agent/gatekeeper/helmify/static/values.yaml index aed59757ee..6053e45f96 100644 --- a/third_party/open-policy-agent/gatekeeper/helmify/static/values.yaml +++ b/third_party/open-policy-agent/gatekeeper/helmify/static/values.yaml @@ -1,5 +1,5 @@ runtimeConfig: - apiVersion: eraser.sh/v1alpha2 + apiVersion: eraser.sh/v1alpha3 kind: EraserConfig health: {} # healthProbeBindAddress: :8081 @@ -11,7 +11,9 @@ runtimeConfig: # leaderElect: true # resourceName: e29e094a.k8s.io manager: - runtime: containerd + runtime: + name: containerd + address: unix:///run/containerd/containerd.sock otlpEndpoint: "" logLevel: info scheduling: {}