/*
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"
)

// ClusterNetworkPolicyIngressRuleApplyConfiguration represents a declarative configuration of the ClusterNetworkPolicyIngressRule type for use
// with apply.
//
// ClusterNetworkPolicyIngressRule describes an action to take on a particular
// set of traffic destined for pods selected by a ClusterNetworkPolicy's
// Subject field.
type ClusterNetworkPolicyIngressRuleApplyConfiguration struct {
	// Name is an identifier for this rule, that may be no more than
	// 100 characters in length. This field should be used by the implementation
	// to help improve observability, readability and error-reporting
	// for any applied policies.
	Name *string `json:"name,omitempty"`
	// Action specifies the effect this rule will have on matching
	// traffic. Currently the following actions are supported:
	//
	// - Accept: Accepts the selected traffic, allowing it into
	// the destination. No further ClusterNetworkPolicy or
	// NetworkPolicy rules will be processed.
	//
	// Note: while Accept ensures traffic is accepted by
	// Kubernetes network policy, it is still possible that the
	// packet is blocked in other ways: custom nftable rules,
	// high-layers e.g. service mesh.
	//
	// - Deny: Drops the selected traffic. No further
	// ClusterNetworkPolicy or NetworkPolicy rules will be
	// processed.
	//
	// - Pass: Skips all further ClusterNetworkPolicy rules in the
	// current tier for the selected traffic, and passes
	// evaluation to the next tier.
	Action *apisv1alpha2.ClusterNetworkPolicyRuleAction `json:"action,omitempty"`
	// From is the list of sources whose traffic this rule applies to.
	// If any element matches the source of incoming
	// traffic then the specified action is applied.
	// This field must be defined and contain at least one item.
	From []ClusterNetworkPolicyIngressPeerApplyConfiguration `json:"from,omitempty"`
	// Protocols allows for more fine-grain matching of traffic on
	// protocol-specific attributes such as the port. If
	// unspecified, protocol-specific attributes will not be used
	// to match traffic.
	Protocols []ClusterNetworkPolicyProtocolApplyConfiguration `json:"protocols,omitempty"`
}

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

// WithName sets the Name 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 Name field is set to the value of the last call.
func (b *ClusterNetworkPolicyIngressRuleApplyConfiguration) WithName(value string) *ClusterNetworkPolicyIngressRuleApplyConfiguration {
	b.Name = &value
	return b
}

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

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

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