-
Notifications
You must be signed in to change notification settings - Fork 33
/
controller.go
100 lines (86 loc) · 3.65 KB
/
controller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// SPDX-FileCopyrightText: 2020 SAP SE or an SAP affiliate company and Gardener contributors.
//
// SPDX-License-Identifier: Apache-2.0
package manifest
import (
"context"
"time"
manifestv1alpha2 "github.com/gardener/landscaper/apis/deployer/manifest/v1alpha2"
"github.com/gardener/landscaper/controller-utils/pkg/logging"
"sigs.k8s.io/controller-runtime/pkg/client"
lsv1alpha1 "github.com/gardener/landscaper/apis/core/v1alpha1"
crval "github.com/gardener/landscaper/apis/deployer/utils/continuousreconcile/validation"
deployerlib "github.com/gardener/landscaper/pkg/deployer/lib"
cr "github.com/gardener/landscaper/pkg/deployer/lib/continuousreconcile"
"github.com/gardener/landscaper/pkg/deployer/lib/extension"
)
const (
TimeoutCheckpointManifestStartReconcile = "manifest deployer: start reconcile"
TimeoutCheckpointManifestBeforeReadinessCheck = "manifest deployer: before readiness check"
TimeoutCheckpointManifestBeforeReadingExportValues = "manifest deployer: before reading export values"
TimeoutCheckpointManifestDefaultReadinessChecks = "manifest deployer: default readiness checks"
TimeoutCheckpointManifestCustomReadinessChecks = "manifest deployer: custom readiness checks"
TimeoutCheckpointManifestStartDelete = "manifest deployer: start delete"
)
// NewDeployer creates a new deployer that reconciles deploy items of type helm.
func NewDeployer(lsUncachedClient, lsCachedClient, hostUncachedClient, hostCachedClient client.Client,
log logging.Logger,
config manifestv1alpha2.Configuration) (deployerlib.Deployer, error) {
dep := &deployer{
lsUncachedClient: lsUncachedClient,
lsCachedClient: lsCachedClient,
hostUncachedClient: hostUncachedClient,
hostCachedClient: hostCachedClient,
log: log,
config: config,
hooks: extension.ReconcileExtensionHooks{},
}
dep.hooks.RegisterHookSetup(cr.ContinuousReconcileExtensionSetup(dep.NextReconcile))
return dep, nil
}
type deployer struct {
lsUncachedClient client.Client
lsCachedClient client.Client
hostUncachedClient client.Client
hostCachedClient client.Client
log logging.Logger
config manifestv1alpha2.Configuration
hooks extension.ReconcileExtensionHooks
}
func (d *deployer) Reconcile(ctx context.Context, _ *lsv1alpha1.Context, di *lsv1alpha1.DeployItem, rt *lsv1alpha1.ResolvedTarget) error {
manifest, err := New(d.lsUncachedClient, d.hostUncachedClient, &d.config, di, rt)
if err != nil {
return err
}
return manifest.Reconcile(ctx)
}
func (d deployer) Delete(ctx context.Context, _ *lsv1alpha1.Context, di *lsv1alpha1.DeployItem, rt *lsv1alpha1.ResolvedTarget) error {
manifest, err := New(d.lsUncachedClient, d.hostUncachedClient, &d.config, di, rt)
if err != nil {
return err
}
return manifest.Delete(ctx)
}
func (d *deployer) Abort(ctx context.Context, lsCtx *lsv1alpha1.Context, di *lsv1alpha1.DeployItem, rt *lsv1alpha1.ResolvedTarget) error {
d.log.Info("abort is not yet implemented")
return nil
}
func (d *deployer) ExtensionHooks() extension.ReconcileExtensionHooks {
return d.hooks
}
func (d *deployer) NextReconcile(ctx context.Context, last time.Time, di *lsv1alpha1.DeployItem) (*time.Time, error) {
manifest, err := New(d.lsUncachedClient, d.hostUncachedClient, &d.config, di, nil)
if err != nil {
return nil, err
}
if crval.ContinuousReconcileSpecIsEmpty(manifest.ProviderConfiguration.ContinuousReconcile) {
// no continuous reconciliation configured
return nil, nil
}
schedule, err := cr.Schedule(manifest.ProviderConfiguration.ContinuousReconcile)
if err != nil {
return nil, err
}
next := schedule.Next(last)
return &next, nil
}