diff --git a/api/v1alpha1/constants.go b/api/v1alpha1/constants.go new file mode 100644 index 0000000..c3714ad --- /dev/null +++ b/api/v1alpha1/constants.go @@ -0,0 +1,5 @@ +package v1alpha1 + +const workerImage = "itayankri/valhalla-worker:latest" +const mapBuilderImage = "itayankri/valhalla-builder:latest" +const historicalTrafficDataFetcherImage = "itayankri/valhalla-predicted-traffic:latest" diff --git a/api/v1alpha1/valhalla_types.go b/api/v1alpha1/valhalla_types.go index 5b548f8..dc800d6 100644 --- a/api/v1alpha1/valhalla_types.go +++ b/api/v1alpha1/valhalla_types.go @@ -62,16 +62,39 @@ const ( type ValhallaSpec struct { // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster // Important: Run "make" to regenerate code after modifying this file - PBFURL string `json:"pbfUrl,omitempty"` - Image *string `json:"image,omitempty"` - Persistence PersistenceSpec `json:"persistence,omitempty"` - Service *ServiceSpec `json:"service,omitempty"` - MinReplicas *int32 `json:"minReplicas,omitempty"` - MaxReplicas *int32 `json:"maxReplicas,omitempty"` - MinAvailable *int32 `json:"minAvailable,omitempty"` - ThreadsPerPod *int32 `json:"threadsPerPod,omitempty"` - Resources *corev1.ResourceRequirements `json:"resources,omitempty"` - PredictedTraffic *PredictedTrafficSpec `json:"predictedTraffic,omitempty"` + PBFURL string `json:"pbfUrl,omitempty"` + WorkerImage *string `json:"workerImage,omitempty"` + MapBuilderImage *string `json:"mapBuilderImage,omitempty"` + HistoricalTrafficDataFetcherImage *string `json:"historicalTrafficDataFetcherImage,omitempty"` + Persistence PersistenceSpec `json:"persistence,omitempty"` + Service *ServiceSpec `json:"service,omitempty"` + MinReplicas *int32 `json:"minReplicas,omitempty"` + MaxReplicas *int32 `json:"maxReplicas,omitempty"` + MinAvailable *int32 `json:"minAvailable,omitempty"` + ThreadsPerPod *int32 `json:"threadsPerPod,omitempty"` + Resources *corev1.ResourceRequirements `json:"resources,omitempty"` + PredictedTraffic *PredictedTrafficSpec `json:"predictedTraffic,omitempty"` +} + +func (spec *ValhallaSpec) GetWorkerImage() string { + if spec.WorkerImage == nil { + return workerImage + } + return *spec.WorkerImage +} + +func (spec *ValhallaSpec) GetMapBuilderImage() string { + if spec.MapBuilderImage == nil { + return mapBuilderImage + } + return *spec.MapBuilderImage +} + +func (spec *ValhallaSpec) GetHistoricalTrafficDataFetcherImage() string { + if spec.HistoricalTrafficDataFetcherImage == nil { + return historicalTrafficDataFetcherImage + } + return *spec.HistoricalTrafficDataFetcherImage } func (spec *ValhallaSpec) GetResources() *corev1.ResourceRequirements { @@ -121,9 +144,8 @@ type ServiceSpec struct { } type PredictedTrafficSpec struct { - URL string `json:"url,omitempty"` - Schedule string `json:"schedule,omitempty"` - Image *string `json:"image,omitempty"` + URL string `json:"url,omitempty"` + Schedule string `json:"schedule,omitempty"` } // ValhallaStatus defines the observed state of Valhalla diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 3a11c28..68db624 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -35,6 +35,11 @@ func (in *PersistenceSpec) DeepCopyInto(out *PersistenceSpec) { x := (*in).DeepCopy() *out = &x } + if in.AccessMode != nil { + in, out := &in.AccessMode, &out.AccessMode + *out = new(v1.PersistentVolumeAccessMode) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PersistenceSpec. @@ -50,11 +55,6 @@ func (in *PersistenceSpec) DeepCopy() *PersistenceSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PredictedTrafficSpec) DeepCopyInto(out *PredictedTrafficSpec) { *out = *in - if in.Image != nil { - in, out := &in.Image, &out.Image - *out = new(string) - **out = **in - } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PredictedTrafficSpec. @@ -77,6 +77,11 @@ func (in *ServiceSpec) DeepCopyInto(out *ServiceSpec) { (*out)[key] = val } } + if in.LoadBalancerIP != nil { + in, out := &in.LoadBalancerIP, &out.LoadBalancerIP + *out = new(string) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceSpec. @@ -151,8 +156,18 @@ func (in *ValhallaList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ValhallaSpec) DeepCopyInto(out *ValhallaSpec) { *out = *in - if in.Image != nil { - in, out := &in.Image, &out.Image + if in.WorkerImage != nil { + in, out := &in.WorkerImage, &out.WorkerImage + *out = new(string) + **out = **in + } + if in.MapBuilderImage != nil { + in, out := &in.MapBuilderImage, &out.MapBuilderImage + *out = new(string) + **out = **in + } + if in.HistoricalTrafficDataFetcherImage != nil { + in, out := &in.HistoricalTrafficDataFetcherImage, &out.HistoricalTrafficDataFetcherImage *out = new(string) **out = **in } @@ -190,7 +205,7 @@ func (in *ValhallaSpec) DeepCopyInto(out *ValhallaSpec) { if in.PredictedTraffic != nil { in, out := &in.PredictedTraffic, &out.PredictedTraffic *out = new(PredictedTrafficSpec) - (*in).DeepCopyInto(*out) + **out = **in } } diff --git a/config/crd/bases/valhalla.itayankri_valhallas.yaml b/config/crd/bases/valhalla.itayankri_valhallas.yaml index b8bafc0..586742e 100644 --- a/config/crd/bases/valhalla.itayankri_valhallas.yaml +++ b/config/crd/bases/valhalla.itayankri_valhallas.yaml @@ -37,6 +37,12 @@ spec: properties: image: type: string + workerImage: + type: string + mapBuilderImage: + type: string + historicalTrafficDataFetcherImage: + type: string maxReplicas: format: int32 type: integer diff --git a/controllers/valhalla_controller_test.go b/controllers/valhalla_controller_test.go index 2c480bd..a1a9638 100644 --- a/controllers/valhalla_controller_test.go +++ b/controllers/valhalla_controller_test.go @@ -220,7 +220,6 @@ var _ = Describe("ValhallaController", func() { func generateValhallaCluster(name string) *valhallav1alpha1.Valhalla { storage := resource.MustParse("10Mi") - image := "itayankri/valhalla:latest" minReplicas := int32(1) maxReplicas := int32(3) valhalla := &valhallav1alpha1.Valhalla{ @@ -230,7 +229,6 @@ func generateValhallaCluster(name string) *valhallav1alpha1.Valhalla { }, Spec: valhallav1alpha1.ValhallaSpec{ PBFURL: "https://download.geofabrik.de/australia-oceania/marshall-islands-latest.osm.pbf", - Image: &image, MinReplicas: &minReplicas, MaxReplicas: &maxReplicas, Persistence: valhallav1alpha1.PersistenceSpec{ diff --git a/internal/resource/constants.go b/internal/resource/constants.go index 511692e..5e410a5 100644 --- a/internal/resource/constants.go +++ b/internal/resource/constants.go @@ -1,9 +1,6 @@ package resource const valhallaDataPath = "/data" -const workerImage = "itayankri/valhalla-worker:latest" -const mapBuilderImage = "itayankri/valhalla-builder:latest" -const hirtoricalTrafficDataFetcherImage = "itayankri/valhalla-predicted-traffic:latest" const DeploymentSuffix = "" const HorizontalPodAutoscalerSuffix = "" diff --git a/internal/resource/cron_job.go b/internal/resource/cron_job.go index 9c30ed2..a072518 100644 --- a/internal/resource/cron_job.go +++ b/internal/resource/cron_job.go @@ -47,7 +47,7 @@ func (builder *CronJobBuilder) Update(object client.Object) error { Containers: []corev1.Container{ { Name: builder.Instance.ChildResourceName(CronJobSuffix), - Image: hirtoricalTrafficDataFetcherImage, + Image: builder.Instance.Spec.GetHistoricalTrafficDataFetcherImage(), Resources: corev1.ResourceRequirements{ Requests: map[corev1.ResourceName]resource.Quantity{ "memory": resource.MustParse("100M"), diff --git a/internal/resource/deployment.go b/internal/resource/deployment.go index 2c65186..40ab8bb 100644 --- a/internal/resource/deployment.go +++ b/internal/resource/deployment.go @@ -50,7 +50,7 @@ func (builder *DeploymentBuilder) Update(object client.Object) error { Containers: []corev1.Container{ { Name: name, - Image: workerImage, + Image: builder.Instance.Spec.GetWorkerImage(), Ports: []corev1.ContainerPort{ { ContainerPort: containerPort, diff --git a/internal/resource/job.go b/internal/resource/job.go index aa4bc7a..6d442f3 100644 --- a/internal/resource/job.go +++ b/internal/resource/job.go @@ -43,7 +43,7 @@ func (builder *JobBuilder) Update(object client.Object) error { Containers: []corev1.Container{ { Name: "map-builder", - Image: mapBuilderImage, + Image: builder.Instance.Spec.GetMapBuilderImage(), Resources: corev1.ResourceRequirements{ Requests: map[corev1.ResourceName]resource.Quantity{ "memory": resource.MustParse("1000M"),