-
Notifications
You must be signed in to change notification settings - Fork 161
/
ippool.go
109 lines (93 loc) · 3.83 KB
/
ippool.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
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright (c) 2016 Tigera, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package api
import (
"fmt"
"github.com/projectcalico/libcalico-go/lib/api/unversioned"
"github.com/projectcalico/libcalico-go/lib/ipip"
"github.com/projectcalico/libcalico-go/lib/net"
)
// IPPool contains the details of a Calico IP pool resource.
// A pool resource is used by Calico in two ways:
// - to provide a set of IP addresses from which Calico IPAM assigns addresses
// for workloads.
// - to provide configuration specific to IP address range, such as configuration
// for the BGP daemon (e.g. when to use a GRE tunnel to encapsulate packets
// between compute hosts).
type IPPool struct {
unversioned.TypeMetadata
Metadata IPPoolMetadata `json:"metadata,omitempty"`
Spec IPPoolSpec `json:"spec,omitempty"`
}
func (t IPPool) GetResourceMetadata() unversioned.ResourceMetadata {
return t.Metadata
}
// String() returns the human-readable string representation of an IPPool instance
// which is defined by its CIDR.
func (t IPPool) String() string {
return fmt.Sprintf("IPPool(CIDR=%s)", t.Metadata.CIDR.String())
}
// IPPoolMetadata contains the metadata for an IP pool resource.
type IPPoolMetadata struct {
unversioned.ObjectMetadata
CIDR net.IPNet `json:"cidr"`
}
// IPPoolSpec contains the specification for an IP pool resource.
type IPPoolSpec struct {
// Contains configuration for ipip tunneling for this pool. If not specified,
// then ipip tunneling is disabled for this pool.
IPIP *IPIPConfiguration `json:"ipip,omitempty"`
// When nat-outgoing is true, packets sent from Calico networked containers in
// this pool to destinations outside of this pool will be masqueraded.
NATOutgoing bool `json:"nat-outgoing,omitempty"`
// When disabled is true, Calico IPAM will not assign addresses from this pool.
Disabled bool `json:"disabled,omitempty"`
}
type IPIPConfiguration struct {
// When enabled is true, ipip tunneling will be used to deliver packets to
// destinations within this pool.
Enabled bool `json:"enabled,omitempty"`
// The IPIP mode. This can be one of "always" or "cross-subnet". A mode
// of "always" will also use IPIP tunneling for routing to destination IP
// addresses within this pool. A mode of "cross-subnet" will only use IPIP
// tunneling when the destination node is on a different subnet to the
// originating node. The default value (if not specified) is "always".
Mode ipip.Mode `json:"mode,omitempty" validate:"ipipmode"`
}
// NewIPPool creates a new (zeroed) Pool struct with the TypeMetadata initialised to the current
// version.
func NewIPPool() *IPPool {
return &IPPool{
TypeMetadata: unversioned.TypeMetadata{
Kind: "ipPool",
APIVersion: unversioned.VersionCurrent,
},
}
}
// IPPoolList contains a list of IP pool resources. List types are returned from List()
// enumerations in the client interface.
type IPPoolList struct {
unversioned.TypeMetadata
Metadata unversioned.ListMetadata `json:"metadata,omitempty"`
Items []IPPool `json:"items" validate:"dive"`
}
// NewIPPool creates a new (zeroed) PoolList struct with the TypeMetadata initialised to the current
// version.
func NewIPPoolList() *IPPoolList {
return &IPPoolList{
TypeMetadata: unversioned.TypeMetadata{
Kind: "ipPoolList",
APIVersion: unversioned.VersionCurrent,
},
}
}