This repository has been archived by the owner on Jun 7, 2022. It is now read-only.
forked from atlassian/smith
/
controller_worker.go
50 lines (45 loc) · 1.66 KB
/
controller_worker.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
package bundlec
import (
"context"
"github.com/atlassian/ctrl"
smith_v1 "github.com/atlassian/smith/pkg/apis/smith/v1"
"github.com/pkg/errors"
"go.uber.org/zap"
api_errors "k8s.io/apimachinery/pkg/api/errors"
)
func (c *Controller) Process(pctx *ctrl.ProcessContext) (bool /*retriable*/, error) {
return c.ProcessBundle(pctx.Logger, pctx.Object.(*smith_v1.Bundle))
}
// ProcessBundle is only visible for testing purposes. Should not be called directly.
func (c *Controller) ProcessBundle(logger *zap.Logger, bundle *smith_v1.Bundle) (bool /*retriable*/, error) {
st := bundleSyncTask{
logger: logger,
bundleClient: c.BundleClient,
smartClient: c.SmartClient,
checker: c.Rc,
store: c.Store,
specChecker: c.SpecChecker,
bundle: bundle,
pluginContainers: c.PluginContainers,
scheme: c.Scheme,
catalog: c.Catalog,
bundleTransitionCounter: c.BundleTransitionCounter,
bundleResourceTransitionCounter: c.BundleResourceTransitionCounter,
recorder: c.Recorder,
}
var retriable bool
var err error
if st.bundle.DeletionTimestamp != nil {
retriable, err = st.processDeleted()
} else {
retriable, err = st.processNormal()
}
if err != nil {
cause := errors.Cause(err)
if api_errors.IsConflict(cause) || cause == context.Canceled || cause == context.DeadlineExceeded {
return retriable, err
}
// proceed to handleProcessResult() for all other errors
}
return st.handleProcessResult(retriable, err)
}