func()

in network.go [46:97]


func (networkInterfaces NetworkInterfaces) validate(kernelArgs kernelArgs) error {
	for _, iface := range networkInterfaces {
		hasCNI := iface.CNIConfiguration != nil
		hasStaticInterface := iface.StaticConfiguration != nil
		hasStaticIP := hasStaticInterface && iface.StaticConfiguration.IPConfiguration != nil

		if !hasCNI && !hasStaticInterface {
			return errors.Errorf(
				"must specify at least one of CNIConfiguration or StaticConfiguration for network interfaces: %+v", networkInterfaces)
		}

		if hasCNI && hasStaticInterface {
			// TODO(sipsma) in theory, the current code actually supports the user providing both CNI and StaticConfiguration
			// for a single interface. The behavior would be that CNI is invoked but the final device used would be
			// specified statically rather than parsed from the CNI result via vmconf.
			// This may be useful in some scenarios, but the full implications of enabling it have not yet been considered or
			// tested, so for now providing both is blocked to prevent any regrettable one-way doors.
			return errors.Errorf(
				"cannot provide both CNIConfiguration and StaticConfiguration for a network interface: %+v", iface)
		}

		if hasCNI || hasStaticIP {
			// due to limitations of using "ip=" kernel boot param, currently only one network interface can be provided
			// when a static IP is going to be configured.
			if len(networkInterfaces) > 1 {
				return errors.Errorf(
					"cannot specify CNIConfiguration or IPConfiguration when multiple network interfaces are provided: %+v", networkInterfaces)
			}

			if argVal, ok := kernelArgs["ip"]; ok {
				return errors.Errorf(
					`CNIConfiguration or IPConfiguration cannot be specified when "ip=" provided in kernel boot args, value found: "%v"`, argVal)
			}
		}

		if hasCNI {
			err := iface.CNIConfiguration.validate()
			if err != nil {
				return err
			}
		}

		if hasStaticInterface {
			err := iface.StaticConfiguration.validate()
			if err != nil {
				return err
			}
		}
	}

	return nil
}