Skip to content
job.go 2.41 KiB
Newer Older
/*

Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.gnu.org/licenses/agpl-3.0.html

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 components

import (
	"k8s.libre.sh/application"
	settings "k8s.libre.sh/application/settings"
	meta "k8s.libre.sh/meta"
	"k8s.libre.sh/objects"
	"k8s.libre.sh/objects/job"
)

// const DefaultComponent string = "app"

// +kubebuilder:object:generate=true
type Job struct {
	*job.Job `json:",inline"`
	Settings []string `json:"settings,omitempty"`
}

Timothee Gosselin's avatar
Timothee Gosselin committed
// +kubebuilder:object:generate=true
type Jobs struct {
	*meta.ObjectMeta `json:"commonMeta,omitempty"`
	Install          *Job `json:"install,omitempty"`
	Upgrade          *Job `json:"upgrade,omitempty"`
Timothee Gosselin's avatar
Timothee Gosselin committed
	//	StorageMigration Job
}

func (w *Jobs) Init() {
	if w.ObjectMeta == nil {
		w.ObjectMeta = &meta.ObjectMeta{}
	}
	if w.Install == nil {
		w.Install = &Job{}
	}
	if w.Upgrade == nil {
		w.Upgrade = &Job{}
	}
	w.Install.Init()
	w.Upgrade.Init()
}

func (w *Jobs) GetJobs() map[string]application.Component {

	cpts := make(map[string]application.Component)

	cpts["install"] = w.Install
	cpts["upgrade"] = w.Upgrade

	return cpts
}

Timothee Gosselin's avatar
Timothee Gosselin committed
func (w *Jobs) GetObjects() map[int]objects.Object {

	objects := make(map[int]objects.Object, 2)

	objects[0] = w.Install
	objects[1] = w.Upgrade

	return objects
}

func (w *Job) HasSettings() []string { return w.Settings }
func (w *Job) GetMeta() meta.Instance { return w.ObjectMeta }
func (w *Job) GetObjects() map[int]objects.Object {

	objects := make(map[int]objects.Object, 1)

	objects[0] = w.Job

	return objects
}

func (w *Job) GetConfig() settings.Config { return w.SettingsSpec }
func (w *Job) SetDefaults() {}
func (w *Job) Init() {
	if w.Job == nil {
		w.Job = &job.Job{}
	}

	w.Job.Init()

	if w.ObjectMeta == nil {
		w.ObjectMeta = &meta.ObjectMeta{}
	}

	if len(w.ObjectMeta.Labels) == 0 {
		w.ObjectMeta.Labels = make(map[string]string)
	}

	// TODO FIXME
	if len(w.ObjectMeta.GetComponent()) == 0 {
		w.ObjectMeta.SetComponent("job")
	if w.JobSpec == nil {
		w.JobSpec = &job.JobSpec{}