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 application
import (
settings "k8s.libre.sh/application/settings"
"k8s.libre.sh/meta"
"k8s.libre.sh/status"
)
type Meta struct {
Version string
Instance string
// Name string
Component string
PartOf string
ManagedBy string
type Application struct {
meta.Instance
Settings map[string]settings.Component
Components map[string]Component
Jobs map[string]Component
Status *status.ApplicationStatus
func (app *Application) GetVersion() string { return app.Version }
func (app *Application) GetJobs() map[string]Component { return app.Jobs }
func (app *Application) GetApplicationStatus() *status.ApplicationStatus { return app.Status }
func (app *Application) GetComponents() map[string]Component { return app.Components }
func (app *Application) GetOwner() status.ObjectWithStatus { return app.Owner }
func (app *Application) GetSettings() map[string]settings.Component { return app.Settings }
/* func NewApplication(i Instance) *Application {
app := &Application{}
app.Settings = make(map[string]settings.Component, len(i.GetSettings()))
app.Components = make(map[string]Component, len(i.GetComponents()))
app.Jobs = make(map[string]Component, len(i.GetJobs()))
for k, v := range i.GetSettings() {
v.SetDefaults()
app.Settings[k] = settings.NewSettings(v.GetCreateOptions(), v.GetSources(), v.GetParameters())
}
for k, v := range i.GetComponents() {
v.SetDefaults()
app.Components[k] = v
}
for k, v := range i.GetJobs() {
v.Init()
v.SetDefaults()
app.Jobs[k] = v
}
om := &meta.ObjectMeta{
Labels: i.GetLabels(),
Annotations: i.GetLabels(),
Name: i.GetName(),
Namespace: i.GetNamespace(),
}
app.Instance = om
app.Owner = i.GetOwner()
app.Version = i.GetVersion()
app.Status = i.GetApplicationStatus()
*/
func NewApplication(setts map[string]settings.Component, cpts, jobs map[string]Component, owner status.ObjectWithStatus, m meta.Instance) *Application {
app := &Application{}
app.Settings = make(map[string]settings.Component, len(setts))
app.Components = make(map[string]Component, len(cpts))
app.Jobs = make(map[string]Component, len(jobs))
for k, v := range setts {
app.Settings[k] = settings.NewSettings(v.GetCreateOptions(), v.GetSources(), v.GetParameters())
}
for k, v := range cpts {
app.Components[k] = v
}
for k, v := range jobs {
// Labels: i.GetLabels(),
// Annotations: i.GetLabels(),
Name: m.GetName(),
Namespace: m.GetNamespace(),
app.Owner = owner
app.Version = m.GetVersion()
ownerStatus := owner.GetApplicationStatus()
app.Status = ownerStatus.DeepCopy()