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 (
"k8s.libre.sh/application/settings/parameters"
GetApplicationStatus() *status.ApplicationStatus
func GetTemplateValues(i Instance, setts map[string]settings.Component) map[string]interface{} {
values := make(map[string]interface{})
cptsVals := make(map[string]interface{})
settsVals := make(map[string]interface{})
// TODO create templateValues for Component interface
cptsVals[cpt.GetMeta().GetComponent()] = cpt.(interface{})
Timothee Gosselin
committed
for _, sett := range setts {
// TODO create templateValues for Settings interface
settsVals[sett.GetMeta().GetComponent()] = parameters.KeyPairValues(sett.GetConfig().GetParameters())
}
values["components"] = cptsVals
values["settings"] = settsVals
func InitSettings(i Instance, r interfaces.Reconcile) error {
appStatus := i.GetApplicationStatus()
setts := i.GetSettings()
// First we init external values and random values
for name, sett := range setts {
if len(appStatus.Settings[name].Resources.Objects) > 0 {
for _, o := range appStatus.Settings[name].Resources.Objects {
src := settings.Source{
Ref: o.Name,
Type: strings.ToLower(o.Kind),
}
*sett.GetConfig().GetSources() = append(*sett.GetConfig().GetSources(), src)
}
}
err := settings.Init(sett, r.GetClient(), i.GetOwner())
if err != nil {
return err
}
}
// Transform instance to template values used to init settings
values := GetTemplateValues(i, i.GetSettings())
// Init the values from templates & set defaults
for _, sett := range setts {
err := sett.GetConfig().GetParameters().InitTemplateValues(values)
if err != nil {
return err
}
// Initiatilize & Defaults
func Init(i Instance, r interfaces.Reconcile) error {
// Init Components
cpts := i.GetComponents()
InitComponentsFromSettings(cpts, i.GetSettings())