Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable docker images #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/v1alpha1/constants.go
Original file line number Diff line number Diff line change
@@ -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"
48 changes: 35 additions & 13 deletions api/v1alpha1/valhalla_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
31 changes: 23 additions & 8 deletions api/v1alpha1/zz_generated.deepcopy.go

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

6 changes: 6 additions & 0 deletions config/crd/bases/valhalla.itayankri_valhallas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ spec:
properties:
image:
type: string
workerImage:
type: string
mapBuilderImage:
type: string
historicalTrafficDataFetcherImage:
type: string
maxReplicas:
format: int32
type: integer
Expand Down
2 changes: 0 additions & 2 deletions controllers/valhalla_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand Down
3 changes: 0 additions & 3 deletions internal/resource/constants.go
Original file line number Diff line number Diff line change
@@ -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 = ""
Expand Down
2 changes: 1 addition & 1 deletion internal/resource/cron_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion internal/resource/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion internal/resource/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down