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

import (
	apisv1alpha2 "sigs.k8s.io/network-policy-api/apis/v1alpha2"
)

// ClusterNetworkPolicySpecApplyConfiguration represents a declarative configuration of the ClusterNetworkPolicySpec type for use
// with apply.
//
// ClusterNetworkPolicySpec defines the desired state of ClusterNetworkPolicy.
type ClusterNetworkPolicySpecApplyConfiguration struct {
	// Tier is used as the top-level grouping for network policy prioritization.
	//
	// Policy tiers are evaluated in the following order:
	// * Admin tier
	// * NetworkPolicy tier
	// * Baseline tier
	//
	// ClusterNetworkPolicy can use 2 of these tiers: Admin and Baseline.
	//
	// The Admin tier takes precedence over all other policies. Policies
	// defined in this tier are used to set cluster-wide security rules
	// that cannot be overridden in the other tiers. If Admin tier has
	// made a final decision (Accept or Deny) on a connection, then no
	// further evaluation is done.
	//
	// NetworkPolicy tier is the tier for the namespaced v1.NetworkPolicy.
	// These policies are intended for the application developer to describe
	// the security policy associated with their deployments inside their
	// namespace. v1.NetworkPolicy always makes a final decision for selected
	// pods. Further evaluation only happens for Pods not selected by a
	// v1.NetworkPolicy.
	//
	// Baseline tier is a cluster-wide policy that can be overridden by the
	// v1.NetworkPolicy. If Baseline tier has made a final decision (Accept or
	// Deny) on a connection, then no further evaluation is done.
	//
	// If a given connection wasn't allowed or denied by any of the tiers,
	// the default kubernetes policy is applied, which says that
	// all pods can communicate with each other.
	Tier *apisv1alpha2.Tier `json:"tier,omitempty"`
	// Priority is a value from 0 to 1000 indicating the precedence of
	// the policy within its tier. Policies with lower priority values have
	// higher precedence, and are checked before policies with higher priority
	// values in the same tier. All Admin tier rules have higher precedence than
	// NetworkPolicy or Baseline tier rules.
	// If two (or more) policies in the same tier with the same priority
	// could match a connection, then the implementation can apply any of the
	// matching policies to the connection, and there is no way for the user to
	// reliably determine which one it will choose. Administrators must be
	// careful about assigning the priorities for policies with rules that will
	// match many connections, and ensure that policies have unique priority
	// values in cases where ambiguity would be unacceptable.
	Priority *int32 `json:"priority,omitempty"`
	// Subject defines the pods to which this ClusterNetworkPolicy applies.
	Subject *ClusterNetworkPolicySubjectApplyConfiguration `json:"subject,omitempty"`
	// Ingress is the list of Ingress rules to be applied to the selected pods.
	//
	// A maximum of 25 rules is allowed in this block.
	//
	// The relative precedence of ingress rules within a single CNP object
	// (all of which share the priority) will be determined by the order
	// in which the rule is written.
	// Thus, a rule that appears at the top of the ingress rules
	// would take the highest precedence.
	// CNPs with no ingress rules do not affect ingress traffic.
	Ingress []ClusterNetworkPolicyIngressRuleApplyConfiguration `json:"ingress,omitempty"`
	// Egress is the list of Egress rules to be applied to the selected pods.
	//
	// A maximum of 25 rules is allowed in this block.
	//
	// The relative precedence of egress rules within a single CNP object
	// (all of which share the priority) will be determined by the order
	// in which the rule is written.
	// Thus, a rule that appears at the top of the egress rules
	// would take the highest precedence.
	// CNPs with no egress rules do not affect egress traffic.
	Egress []ClusterNetworkPolicyEgressRuleApplyConfiguration `json:"egress,omitempty"`
}

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

// WithTier sets the Tier 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 Tier field is set to the value of the last call.
func (b *ClusterNetworkPolicySpecApplyConfiguration) WithTier(value apisv1alpha2.Tier) *ClusterNetworkPolicySpecApplyConfiguration {
	b.Tier = &value
	return b
}

// WithPriority sets the Priority 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 Priority field is set to the value of the last call.
func (b *ClusterNetworkPolicySpecApplyConfiguration) WithPriority(value int32) *ClusterNetworkPolicySpecApplyConfiguration {
	b.Priority = &value
	return b
}

// WithSubject sets the Subject 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 Subject field is set to the value of the last call.
func (b *ClusterNetworkPolicySpecApplyConfiguration) WithSubject(value *ClusterNetworkPolicySubjectApplyConfiguration) *ClusterNetworkPolicySpecApplyConfiguration {
	b.Subject = value
	return b
}

// WithIngress adds the given value to the Ingress 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 Ingress field.
func (b *ClusterNetworkPolicySpecApplyConfiguration) WithIngress(values ...*ClusterNetworkPolicyIngressRuleApplyConfiguration) *ClusterNetworkPolicySpecApplyConfiguration {
	for i := range values {
		if values[i] == nil {
			panic("nil value passed to WithIngress")
		}
		b.Ingress = append(b.Ingress, *values[i])
	}
	return b
}

// WithEgress adds the given value to the Egress 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 Egress field.
func (b *ClusterNetworkPolicySpecApplyConfiguration) WithEgress(values ...*ClusterNetworkPolicyEgressRuleApplyConfiguration) *ClusterNetworkPolicySpecApplyConfiguration {
	for i := range values {
		if values[i] == nil {
			panic("nil value passed to WithEgress")
		}
		b.Egress = append(b.Egress, *values[i])
	}
	return b
}
