utils

package
v0.0.0-...-21cfbab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2023 License: Apache-2.0, Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Copyright 2018 Tigera Inc

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.

Copyright (c) 2018-2021 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.

Copyright (c) 2015-2020 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.

Index

Constants

This section is empty.

Variables

View Source
var (
	// IPv4AllNet represents the IPv4 all-addresses CIDR 0.0.0.0/0.
	IPv4AllNet *net.IPNet
	// IPv6AllNet represents the IPv6 all-addresses CIDR ::/0.
	IPv6AllNet    *net.IPNet
	DefaultRoutes []*net.IPNet
)

Functions

func AddIPAM

func AddIPAM(conf types.NetConf, args *skel.CmdArgs, logger *logrus.Entry) (*cniv1.Result, error)

AddIPAM calls through to the configured IPAM plugin. It also contains IPAM plugin specific logic based on the configured plugin.

func AddIgnoreUnknownArgs

func AddIgnoreUnknownArgs() error

AddIgnoreUnknownArgs appends the 'IgnoreUnknown=1' option to CNI_ARGS before calling the IPAM plugin. Otherwise, it will complain about the Kubernetes arguments. See https://github.com/kubernetes/kubernetes/pull/24983

func CheckForSpuriousDockerAdd

func CheckForSpuriousDockerAdd(args *skel.CmdArgs,
	conf types.NetConf,
	epIDs WEPIdentifiers,
	endpoint *api.WorkloadEndpoint,
	logger *logrus.Entry) (*cniv1.Result, error)

func ConfigureLogging

func ConfigureLogging(conf types.NetConf)

Set up logging for both Calico and libcalico using the provided log level,

func CreateClient

func CreateClient(conf types.NetConf) (client.Interface, error)

func CreateOrUpdate

func CreateOrUpdate(ctx context.Context, client client.Interface, wep *api.WorkloadEndpoint) (*api.WorkloadEndpoint, error)

CreateOrUpdate creates the WorkloadEndpoint if ResourceVersion is not specified, or Update if it's specified.

func CreateResultFromEndpoint

func CreateResultFromEndpoint(wep *api.WorkloadEndpoint) (*cniv1.Result, error)

CreateResultFromEndpoint takes a WorkloadEndpoint, extracts IP information and populates that into a CNI Result.

func DeleteIPAM

func DeleteIPAM(conf types.NetConf, args *skel.CmdArgs, logger *logrus.Entry) error

DeleteIPAM calls IPAM plugin to release the IP address. It also contains IPAM plugin specific logic based on the configured plugin, and is the logical counterpart to AddIPAM.

func DetermineNodename

func DetermineNodename(conf types.NetConf) (nodename string)

DetermineNodename gets the node name, in order of priority: 1. Nodename field in NetConf 2. Nodename from the file /var/lib/calico/nodename 3. Hostname field in NetConf (DEPRECATED). 4. OS Hostname.

func EnsureVXLANTunnelAddr

func EnsureVXLANTunnelAddr(ctx context.Context, calicoClient calicoclient.Interface, nodeName string, ipNet *net.IPNet, networkName string) error

func GetHandleID

func GetHandleID(netName, containerID, workload string) string

func MTUFromFile

func MTUFromFile(filename string) (int, error)

MTUFromFile reads the /var/lib/calico/mtu file if it exists and returns the MTU within.

func Min

func Min(a, b int) int

func PopulateEndpointNets

func PopulateEndpointNets(wep *api.WorkloadEndpoint, result *cniv1.Result) error

PopulateEndpointNets takes a WorkloadEndpoint and a CNI Result, extracts IP address and mask and populates that information into the WorkloadEndpoint.

func RegisterDeletedWep

func RegisterDeletedWep(containerID string) error

func ReleaseIPAllocation

func ReleaseIPAllocation(logger *logrus.Entry, conf types.NetConf, args *skel.CmdArgs)

ReleaseIPAllocation is called to cleanup IPAM allocations if something goes wrong during CNI ADD execution. It forces the CNI_COMMAND to be DEL.

func ReplaceHostLocalIPAMPodCIDRs

func ReplaceHostLocalIPAMPodCIDRs(logger *logrus.Entry, stdinData map[string]interface{}, getPodCIDRs func() (string, string, error)) error

ReplaceHostLocalIPAMPodCIDRs extracts the host-local IPAM config section and replaces our special-case "usePodCidr" subnet value with pod CIDR retrieved by the passed-in getPodCIDR function. Typically, the passed-in function would access the datastore to retrieve the podCIDR. However, for tear-down we use a dummy value that returns 0.0.0.0/0.

To make sure that unknown fields are round-tripped, we manipulate the JSON as maps and slices rather than by unmarshaling it into a struct. The structure of the JSON is as follows; we support replacing usePodCidr in either the "ipam" dict or its nested ranges section:

{
  "cniVersion": "%s",
  ...
  "ipam": {
    "type": "host-local",
    "subnet": "usePodCidr",
    "ranges": [
      [
         {
           "subnet": "usePodCidr"
         }
      ]
    ]
  }
  ...
}

func ResolvePools

func ResolvePools(ctx context.Context, c client.Interface, pools []string, isv4 bool) ([]cnet.IPNet, error)

ResolvePools takes an array of CIDRs or IP Pool names and resolves it to a slice of pool CIDRs.

func SanitizeMesosLabel

func SanitizeMesosLabel(s string) string

SanitizeMesosLabel converts a string from a valid mesos label to a valid Calico label. Mesos labels have no restriction outside of being unicode.

func UpdateHostLocalIPAMDataForWindows

func UpdateHostLocalIPAMDataForWindows(subnet string, ipamData map[string]interface{}) error

This function will update host-local IPAM data based on input from cni.conf

func ValidateNetworkName

func ValidateNetworkName(name string) error

ValidateNetworkName checks that the network name meets felix's expectations

Types

type WEPIdentifiers

type WEPIdentifiers struct {
	Namespace string
	WEPName   string
	names.WorkloadEndpointIdentifiers
}

func GetIdentifiers

func GetIdentifiers(args *skel.CmdArgs, nodename string) (*WEPIdentifiers, error)

GetIdentifiers takes CNI command arguments, and extracts identifiers i.e. pod name, pod namespace, container ID, endpoint(container interface name) and orchestratorID based on the orchestrator.

Directories

Path Synopsis
Dummy version of the HCN API for compilation on Linux.
Dummy version of the HCN API for compilation on Linux.
This package contains algorithmic support code for Windows.
This package contains algorithmic support code for Windows.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL