forked from projectcalico/libcalico-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hostendpoint.go
98 lines (84 loc) · 4.05 KB
/
hostendpoint.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
// 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 (
"github.com/projectcalico/libcalico-go/lib/api/unversioned"
"github.com/projectcalico/libcalico-go/lib/net"
)
// HostEndpoint contains information about a “bare-metal” interfaces attached to the host that is
// running Calico’s agent, Felix. By default, Calico doesn’t apply any policy to such interfaces.
type HostEndpoint struct {
unversioned.TypeMetadata
Metadata HostEndpointMetadata `json:"metadata,omitempty"`
Spec HostEndpointSpec `json:"spec,omitempty"`
}
// HostEndpointMetadata contains the Metadata for a HostEndpoint resource.
type HostEndpointMetadata struct {
unversioned.ObjectMetadata
// The name of the endpoint.
Name string `json:"name,omitempty" validate:"omitempty,namespacedname"`
// The node name identifying the Calico node instance.
Node string `json:"node,omitempty" validate:"omitempty,name"`
// The labels applied to the host endpoint. It is expected that many endpoints share
// the same labels. For example, they could be used to label all “production” workloads
// with “deployment=prod” so that security policy can be applied to production workloads.
Labels map[string]string `json:"labels,omitempty" validate:"omitempty,labels"`
}
// HostEndpointSpec contains the specification for a HostEndpoint resource.
type HostEndpointSpec struct {
// The name of the linux interface to apply policy to; for example “eth0”.
// If "InterfaceName" is not present then at least one expected IP must be specified.
InterfaceName string `json:"interfaceName,omitempty" validate:"omitempty,interface"`
// The expected IP addresses (IPv4 and IPv6) of the endpoint.
// If "InterfaceName" is not present, Calico will look for an interface matching any
// of the IPs in the list and apply policy to that.
//
// Note:
// When using the selector|tag match criteria in an ingress or egress security Policy
// or Profile, Calico converts the selector into a set of IP addresses. For host
// endpoints, the ExpectedIPs field is used for that purpose. (If only the interface
// name is specified, Calico does not learn the IPs of the interface for use in match
// criteria.)
ExpectedIPs []net.IP `json:"expectedIPs,omitempty" validate:"omitempty"`
// A list of identifiers of security Profile objects that apply to this endpoint. Each
// profile is applied in the order that they appear in this list. Profile rules are applied
// after the selector-based security policy.
Profiles []string `json:"profiles,omitempty" validate:"omitempty,dive,namespacedname"`
}
// NewHostEndpoint creates a new (zeroed) HostEndpoint struct with the TypeMetadata initialised to the current
// version.
func NewHostEndpoint() *HostEndpoint {
return &HostEndpoint{
TypeMetadata: unversioned.TypeMetadata{
Kind: "hostEndpoint",
APIVersion: unversioned.VersionCurrent,
},
}
}
// HostEndpointList contains a list of Host Endpoint resources. List types are returned from List()
// enumerations in the client interface.
type HostEndpointList struct {
unversioned.TypeMetadata
Metadata unversioned.ListMetadata `json:"metadata,omitempty"`
Items []HostEndpoint `json:"items" validate:"dive"`
}
// NewHostEndpoint creates a new (zeroed) HostEndpointList struct with the TypeMetadata initialised to the current
// version.
func NewHostEndpointList() *HostEndpointList {
return &HostEndpointList{
TypeMetadata: unversioned.TypeMetadata{
Kind: "hostEndpointList",
APIVersion: unversioned.VersionCurrent,
},
}
}