-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_or_update_result.go
56 lines (48 loc) · 1.33 KB
/
create_or_update_result.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
// Copyright (c) 2023, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
package capi
import (
"github.com/verrazzano/kontainer-engine-driver-oke-capi/pkg/capi/object"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
type NameAndNamespace struct {
Name string
Namespace string
}
type CreateOrUpdateResult struct {
result map[string]map[NameAndNamespace]bool
}
func NewCreateOrUpdateResult() *CreateOrUpdateResult {
return &CreateOrUpdateResult{
result: map[string]map[NameAndNamespace]bool{},
}
}
func (c *CreateOrUpdateResult) Add(resource string, u *unstructured.Unstructured) {
if u == nil {
return
}
if _, ok := c.result[resource]; !ok {
c.result[resource] = map[NameAndNamespace]bool{}
}
c.result[resource][NameAndNamespace{
Name: u.GetName(),
Namespace: object.DefaultingNamespace(u),
}] = true
}
func (c *CreateOrUpdateResult) Contains(resource string, u *unstructured.Unstructured) bool {
if u == nil {
return false
}
if _, ok := c.result[resource]; !ok {
return false
}
return c.result[resource][NameAndNamespace{
Name: u.GetName(),
Namespace: object.DefaultingNamespace(u),
}]
}
func (c *CreateOrUpdateResult) Merge(c2 *CreateOrUpdateResult) {
for k, v := range c2.result {
c.result[k] = v
}
}