-
Notifications
You must be signed in to change notification settings - Fork 593
/
common_workflows.go
97 lines (88 loc) · 3.37 KB
/
common_workflows.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
package sendconfig
import (
"context"
"time"
"github.com/kong/deck/file"
"github.com/sirupsen/logrus"
"github.com/kong/kubernetes-ingress-controller/internal/deckgen"
"github.com/kong/kubernetes-ingress-controller/internal/parser"
"github.com/kong/kubernetes-ingress-controller/internal/store"
"github.com/kong/kubernetes-ingress-controller/internal/util"
)
// -----------------------------------------------------------------------------
// Sendconfig - Workflow Functions
// -----------------------------------------------------------------------------
// UpdateKongAdminSimple is a helper function for the most common usage of PerformUpdate() with only minimal
// upfront configuration required. This function is specialized and highly opinionated.
//
// If you're implementation needs to expand on the configuration and usage of the following inner components:
//
// - store.Storer
// - kongstate.Kong
// - deckgen.ToDeckContent()
// - sendconfig.PerformUpdate()
//
// Or any other encapsulated components this function makes all of that opaque to the caller.
// Treat this function as a very specific "workflow" to update the Kong Admin API,
// and use it as a reference to implement the workflow you need.
func UpdateKongAdminSimple(ctx context.Context,
lastConfigSHA []byte,
cache *store.CacheStores,
ingressClassName string,
deprecatedLogger logrus.FieldLogger,
kongConfig Kong,
enableReverseSync bool,
diagnostic util.ConfigDumpDiagnostic,
) ([]byte, error) {
// build the kongstate object from the Kubernetes objects in the storer
storer := store.New(*cache, ingressClassName, false, false, false, deprecatedLogger)
kongstate, err := parser.Build(deprecatedLogger, storer)
if err != nil {
return nil, err
}
var diagnosticConfig *file.Content
// generate the deck configuration to be applied to the admin API
targetConfig := deckgen.ToDeckContent(ctx,
deprecatedLogger, kongstate,
kongConfig.PluginSchemaStore, kongConfig.FilterTags)
// generate diagnostic configuration if enabled
// "diagnostic" will be empty if --dump-config is not set
if diagnostic != (util.ConfigDumpDiagnostic{}) {
if !diagnostic.DumpsIncludeSensitive {
redactedConfig := deckgen.ToDeckContent(ctx,
deprecatedLogger, kongstate.SanitizedCopy(),
kongConfig.PluginSchemaStore, kongConfig.FilterTags)
diagnosticConfig = redactedConfig
} else {
diagnosticConfig = targetConfig
}
}
// apply the configuration update in Kong
timedCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
configSHA, err := PerformUpdate(timedCtx,
deprecatedLogger, &kongConfig,
kongConfig.InMemory, enableReverseSync,
targetConfig, kongConfig.FilterTags, nil, lastConfigSHA, false,
)
if err != nil {
if diagnostic != (util.ConfigDumpDiagnostic{}) {
select {
case diagnostic.Configs <- util.ConfigDump{Failed: true, Config: *diagnosticConfig}:
deprecatedLogger.Debug("shipping config to diagnostic server")
default:
deprecatedLogger.Error("config diagnostic buffer full, dropping diagnostic config")
}
}
return nil, err
}
if diagnostic != (util.ConfigDumpDiagnostic{}) {
select {
case diagnostic.Configs <- util.ConfigDump{Failed: false, Config: *diagnosticConfig}:
deprecatedLogger.Debug("shipping config to diagnostic server")
default:
deprecatedLogger.Error("config diagnostic buffer full, dropping diagnostic config")
}
}
return configSHA, nil
}