utils

package
v3.8.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2019 License: Apache-2.0 Imports: 28 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) 2015-2019 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) (*current.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 CleanUpNamespace

func CleanUpNamespace(args *skel.CmdArgs, logger *logrus.Entry) error

CleanUpNamespace deletes the devices in the network namespace.

func ConfigureLogging

func ConfigureLogging(logLevel string)

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) (*current.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 DoNetworking

func DoNetworking(
	args *skel.CmdArgs,
	conf types.NetConf,
	result *current.Result,
	logger *logrus.Entry,
	desiredVethName string,
	routes []*net.IPNet,
) (hostVethName, contVethMAC string, err error)

DoNetworking performs the networking for the given config and IPAM result

func GetHandleID

func GetHandleID(netName, containerID, workload string) string

func Min

func Min(a, b int) int

func PopulateEndpointNets

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

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

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{}, getPodCIDR func() (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 SetupRoutes

func SetupRoutes(hostVeth netlink.Link, result *current.Result) error

SetupRoutes sets up the routes for the host side of the veth pair.

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.

Jump to

Keyboard shortcuts

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