MCPcopy Index your code
hub / github.com/kptdev/kpt / PreProcess

Function PreProcess

pkg/live/preprocess/process.go:15–48  ·  view source on GitHub ↗
(p provider.Provider, inv inventory.InventoryInfo, strategy common.DryRunStrategy)

Source from the content-addressed store, hash-verified

13)
14
15func PreProcess(p provider.Provider, inv inventory.InventoryInfo, strategy common.DryRunStrategy) (inventory.InventoryPolicy, error) {
16 invClient, err := p.InventoryClient()
17 if err != nil {
18 return inventory.InventoryPolicyMustMatch, err
19 }
20 obj, err := invClient.GetClusterInventoryInfo(inv)
21 if err != nil {
22 if apierrors.IsNotFound(err) {
23 return inventory.InventoryPolicyMustMatch, nil
24 }
25 return inventory.InventoryPolicyMustMatch, err
26 }
27
28 if obj == nil {
29 return inventory.InventoryPolicyMustMatch, nil
30 }
31
32 managedByKey := "apps.kubernetes.io/managed-by"
33 managedByVal := "kpt"
34 labels := obj.GetLabels()
35 val, found := labels[managedByKey]
36 if found {
37 if val != managedByVal {
38 return inventory.InventoryPolicyMustMatch, fmt.Errorf("can't apply the current package since it is managed by %s", val)
39 }
40 return inventory.InventoryPolicyMustMatch, nil
41 }
42 labels[managedByKey] = managedByVal
43 if strategy.ClientOrServerDryRun() {
44 return inventory.AdoptIfNoInventory, nil
45 }
46 err = invClient.UpdateLabels(inv, labels)
47 return inventory.AdoptIfNoInventory, err
48}

Callers 4

RunEMethod · 0.92
RunEMethod · 0.92
RunEMethod · 0.92
TestPreProcessFunction · 0.85

Calls 3

UpdateLabelsMethod · 0.80
InventoryClientMethod · 0.45

Tested by 1

TestPreProcessFunction · 0.68