-
Notifications
You must be signed in to change notification settings - Fork 290
/
keys.go
61 lines (52 loc) · 1.48 KB
/
keys.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
package kubernetesdiscovery
import (
"time"
"k8s.io/apimachinery/pkg/types"
"github.com/tilt-dev/tilt/pkg/apis"
"github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1"
)
// nsKey is a tuple of Cluster metadata and the K8s namespace being watched.
//
// If multiple clusters are are in use, it's possible to watch the same namespace
// in both, so the namespace name alone is not sufficient. Similarly, a Cluster
// object can change, so there might be multiple revisions active at once.
type nsKey struct {
cluster clusterKey
namespace string
}
func newNsKey(cluster *v1alpha1.Cluster, ns string) nsKey {
return nsKey{
cluster: newClusterKey(cluster),
namespace: ns,
}
}
// uidKey is a tuple of Cluster metadata and the UID being watched.
//
// If multiple clusters are are in use, it's possible (albeit very unlikely) to
// watch the same UID in both, so the UID alone is not sufficient. Similarly, a
// Cluster object can change, so there might be multiple revisions active at
// once.
type uidKey struct {
cluster clusterKey
uid types.UID
}
func newUIDKey(cluster *v1alpha1.Cluster, uid types.UID) uidKey {
return uidKey{
cluster: newClusterKey(cluster),
uid: uid,
}
}
type clusterKey struct {
name types.NamespacedName
revision time.Time
}
func newClusterKey(cluster *v1alpha1.Cluster) clusterKey {
rev := time.Time{}
if cluster.Status.ConnectedAt != nil {
rev = cluster.Status.ConnectedAt.Time
}
return clusterKey{
name: apis.Key(cluster),
revision: rev,
}
}