/*
Copyright The Kubernetes Authors.

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.
*/

// Code generated by applyconfiguration-gen. DO NOT EDIT.

package v1alpha1

import (
	v1 "k8s.io/client-go/applyconfigurations/meta/v1"
	apisv1alpha1 "sigs.k8s.io/network-policy-api/apis/v1alpha1"
)

// AdminNetworkPolicyEgressPeerApplyConfiguration represents a declarative configuration of the AdminNetworkPolicyEgressPeer type for use
// with apply.
//
// AdminNetworkPolicyEgressPeer defines a peer to allow traffic to.
//
// Exactly one of the fields must be set for a given peer and this is enforced
// by the validation rules on the CRD. If an implementation sees no fields are
// set then it can infer that the deployed CRD is of an incompatible version
// with an unknown field.  In that case it should fail closed.
//
// For "Allow" rules, "fail closed" means: "treat the rule as matching no
// traffic". For "Deny" and "Pass" rules, "fail closed" means: "treat the rule
// as a 'Deny all' rule".
type AdminNetworkPolicyEgressPeerApplyConfiguration struct {
	// Namespaces defines a way to select all pods within a set of Namespaces.
	// Note that host-networked pods are not included in this type of peer.
	Namespaces *v1.LabelSelectorApplyConfiguration `json:"namespaces,omitempty"`
	// Pods defines a way to select a set of pods in
	// a set of namespaces. Note that host-networked pods
	// are not included in this type of peer.
	Pods *NamespacedPodApplyConfiguration `json:"pods,omitempty"`
	// Nodes defines a way to select a set of nodes in
	// the cluster (based on the node's labels). It selects
	// the nodeIPs as the peer type by matching on the IPs
	// present in the node.Status.Addresses field of the node.
	// This field follows standard label selector
	// semantics; if present but empty, it selects all Nodes.
	//
	// <network-policy-api:experimental>
	Nodes *v1.LabelSelectorApplyConfiguration `json:"nodes,omitempty"`
	// Networks defines a way to select peers via CIDR blocks.
	// This is intended for representing entities that live outside the cluster,
	// which can't be selected by pods, namespaces and nodes peers, but note
	// that cluster-internal traffic will be checked against the rule as
	// well. So if you Allow or Deny traffic to `"0.0.0.0/0"`, that will allow
	// or deny all IPv4 pod-to-pod traffic as well. If you don't want that,
	// add a rule that Passes all pod traffic before the Networks rule.
	//
	// Each item in Networks should be provided in the CIDR format and should be
	// IPv4 or IPv6, for example "10.0.0.0/8" or "fd00::/8".
	//
	// Networks can have upto 25 CIDRs specified.
	Networks []apisv1alpha1.CIDR `json:"networks,omitempty"`
	// DomainNames provides a way to specify domain names as peers.
	//
	// DomainNames is only supported for ALLOW rules. In order to control
	// access, DomainNames Allow rules should be used with a lower priority
	// egress deny -- this allows the admin to maintain an explicit "allowlist"
	// of reachable domains.
	//
	// DomainNames can have up to 25 domain names specified in one rule.
	//
	// <network-policy-api:experimental>
	DomainNames []apisv1alpha1.DomainName `json:"domainNames,omitempty"`
}

// AdminNetworkPolicyEgressPeerApplyConfiguration constructs a declarative configuration of the AdminNetworkPolicyEgressPeer type for use with
// apply.
func AdminNetworkPolicyEgressPeer() *AdminNetworkPolicyEgressPeerApplyConfiguration {
	return &AdminNetworkPolicyEgressPeerApplyConfiguration{}
}

// WithNamespaces sets the Namespaces field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the Namespaces field is set to the value of the last call.
func (b *AdminNetworkPolicyEgressPeerApplyConfiguration) WithNamespaces(value *v1.LabelSelectorApplyConfiguration) *AdminNetworkPolicyEgressPeerApplyConfiguration {
	b.Namespaces = value
	return b
}

// WithPods sets the Pods field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the Pods field is set to the value of the last call.
func (b *AdminNetworkPolicyEgressPeerApplyConfiguration) WithPods(value *NamespacedPodApplyConfiguration) *AdminNetworkPolicyEgressPeerApplyConfiguration {
	b.Pods = value
	return b
}

// WithNodes sets the Nodes field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the Nodes field is set to the value of the last call.
func (b *AdminNetworkPolicyEgressPeerApplyConfiguration) WithNodes(value *v1.LabelSelectorApplyConfiguration) *AdminNetworkPolicyEgressPeerApplyConfiguration {
	b.Nodes = value
	return b
}

// WithNetworks adds the given value to the Networks field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, values provided by each call will be appended to the Networks field.
func (b *AdminNetworkPolicyEgressPeerApplyConfiguration) WithNetworks(values ...apisv1alpha1.CIDR) *AdminNetworkPolicyEgressPeerApplyConfiguration {
	for i := range values {
		b.Networks = append(b.Networks, values[i])
	}
	return b
}

// WithDomainNames adds the given value to the DomainNames field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, values provided by each call will be appended to the DomainNames field.
func (b *AdminNetworkPolicyEgressPeerApplyConfiguration) WithDomainNames(values ...apisv1alpha1.DomainName) *AdminNetworkPolicyEgressPeerApplyConfiguration {
	for i := range values {
		b.DomainNames = append(b.DomainNames, values[i])
	}
	return b
}
