github.com/cilium/cilium@v1.16.2/api/v1/models/l_r_p_spec.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  // Copyright Authors of Cilium
     4  // SPDX-License-Identifier: Apache-2.0
     5  
     6  package models
     7  
     8  // This file was generated by the swagger tool.
     9  // Editing this file might prove futile when you re-run the swagger generate command
    10  
    11  import (
    12  	"context"
    13  	"strconv"
    14  
    15  	"github.com/go-openapi/errors"
    16  	"github.com/go-openapi/strfmt"
    17  	"github.com/go-openapi/swag"
    18  )
    19  
    20  // LRPSpec Configuration of an LRP
    21  //
    22  // swagger:model LRPSpec
    23  type LRPSpec struct {
    24  
    25  	// mapping of frontends to pod backends
    26  	FrontendMappings []*FrontendMapping `json:"frontend-mappings"`
    27  
    28  	// LRP frontend type
    29  	FrontendType string `json:"frontend-type,omitempty"`
    30  
    31  	// LRP config type
    32  	LrpType string `json:"lrp-type,omitempty"`
    33  
    34  	// LRP service name
    35  	Name string `json:"name,omitempty"`
    36  
    37  	// LRP service namespace
    38  	Namespace string `json:"namespace,omitempty"`
    39  
    40  	// matching k8s service namespace and name
    41  	ServiceID string `json:"service-id,omitempty"`
    42  
    43  	// Unique identification
    44  	UID string `json:"uid,omitempty"`
    45  }
    46  
    47  // Validate validates this l r p spec
    48  func (m *LRPSpec) Validate(formats strfmt.Registry) error {
    49  	var res []error
    50  
    51  	if err := m.validateFrontendMappings(formats); err != nil {
    52  		res = append(res, err)
    53  	}
    54  
    55  	if len(res) > 0 {
    56  		return errors.CompositeValidationError(res...)
    57  	}
    58  	return nil
    59  }
    60  
    61  func (m *LRPSpec) validateFrontendMappings(formats strfmt.Registry) error {
    62  	if swag.IsZero(m.FrontendMappings) { // not required
    63  		return nil
    64  	}
    65  
    66  	for i := 0; i < len(m.FrontendMappings); i++ {
    67  		if swag.IsZero(m.FrontendMappings[i]) { // not required
    68  			continue
    69  		}
    70  
    71  		if m.FrontendMappings[i] != nil {
    72  			if err := m.FrontendMappings[i].Validate(formats); err != nil {
    73  				if ve, ok := err.(*errors.Validation); ok {
    74  					return ve.ValidateName("frontend-mappings" + "." + strconv.Itoa(i))
    75  				} else if ce, ok := err.(*errors.CompositeError); ok {
    76  					return ce.ValidateName("frontend-mappings" + "." + strconv.Itoa(i))
    77  				}
    78  				return err
    79  			}
    80  		}
    81  
    82  	}
    83  
    84  	return nil
    85  }
    86  
    87  // ContextValidate validate this l r p spec based on the context it is used
    88  func (m *LRPSpec) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    89  	var res []error
    90  
    91  	if err := m.contextValidateFrontendMappings(ctx, formats); err != nil {
    92  		res = append(res, err)
    93  	}
    94  
    95  	if len(res) > 0 {
    96  		return errors.CompositeValidationError(res...)
    97  	}
    98  	return nil
    99  }
   100  
   101  func (m *LRPSpec) contextValidateFrontendMappings(ctx context.Context, formats strfmt.Registry) error {
   102  
   103  	for i := 0; i < len(m.FrontendMappings); i++ {
   104  
   105  		if m.FrontendMappings[i] != nil {
   106  
   107  			if swag.IsZero(m.FrontendMappings[i]) { // not required
   108  				return nil
   109  			}
   110  
   111  			if err := m.FrontendMappings[i].ContextValidate(ctx, formats); err != nil {
   112  				if ve, ok := err.(*errors.Validation); ok {
   113  					return ve.ValidateName("frontend-mappings" + "." + strconv.Itoa(i))
   114  				} else if ce, ok := err.(*errors.CompositeError); ok {
   115  					return ce.ValidateName("frontend-mappings" + "." + strconv.Itoa(i))
   116  				}
   117  				return err
   118  			}
   119  		}
   120  
   121  	}
   122  
   123  	return nil
   124  }
   125  
   126  // MarshalBinary interface implementation
   127  func (m *LRPSpec) MarshalBinary() ([]byte, error) {
   128  	if m == nil {
   129  		return nil, nil
   130  	}
   131  	return swag.WriteJSON(m)
   132  }
   133  
   134  // UnmarshalBinary interface implementation
   135  func (m *LRPSpec) UnmarshalBinary(b []byte) error {
   136  	var res LRPSpec
   137  	if err := swag.ReadJSON(b, &res); err != nil {
   138  		return err
   139  	}
   140  	*m = res
   141  	return nil
   142  }