kubesphere.io/api@v0.0.0-20231107125330-c9a03957060c/servicemesh/v1alpha2/servicepolicy_types.go (about)

     1  /*
     2  Copyright 2019 The KubeSphere authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v1alpha2
    18  
    19  import (
    20  	"istio.io/api/networking/v1alpha3"
    21  	"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
    22  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    23  )
    24  
    25  const (
    26  	ResourceKindServicePolicy     = "ServicePolicy"
    27  	ResourceSingularServicePolicy = "servicepolicy"
    28  	ResourcePluralServicePolicy   = "servicepolicies"
    29  )
    30  
    31  // EDIT THIS FILE!  THIS IS SCAFFOLDING FOR YOU TO OWN!
    32  // NOTE: json tags are required.  Any new fields you add must have json tags for the fields to be serialized.
    33  
    34  // ServicePolicySpec defines the desired state of ServicePolicy
    35  type ServicePolicySpec struct {
    36  
    37  	// Label selector for destination rules.
    38  	// +optional
    39  	Selector *metav1.LabelSelector `json:"selector,omitempty"`
    40  
    41  	// Template used to create a destination rule
    42  	// +optional
    43  	Template DestinationRuleSpecTemplate `json:"template,omitempty"`
    44  }
    45  
    46  type DestinationRuleSpecTemplate struct {
    47  
    48  	// Metadata of the virtual services created from this template
    49  	// +optional
    50  	metav1.ObjectMeta `json:"metadata,omitempty"`
    51  
    52  	// Spec indicates the behavior of a destination rule.
    53  	// +optional
    54  	Spec v1alpha3.DestinationRule `json:"spec,omitempty"`
    55  }
    56  
    57  type ServicePolicyConditionType string
    58  
    59  // These are valid conditions of a strategy.
    60  const (
    61  	// StrategyComplete means the strategy has been delivered to istio.
    62  	ServicePolicyComplete ServicePolicyConditionType = "Complete"
    63  
    64  	// StrategyFailed means the strategy has failed its delivery to istio.
    65  	ServicePolicyFailed ServicePolicyConditionType = "Failed"
    66  )
    67  
    68  // StrategyCondition describes current state of a strategy.
    69  type ServicePolicyCondition struct {
    70  	// Type of strategy condition, Complete or Failed.
    71  	Type ServicePolicyConditionType `json:"type,omitempty"`
    72  
    73  	// Status of the condition, one of True, False, Unknown
    74  	Status apiextensions.ConditionStatus `json:"status,omitempty"`
    75  
    76  	// Last time the condition was checked.
    77  	// +optional
    78  	LastProbeTime metav1.Time `json:"lastProbeTime,omitempty"`
    79  
    80  	// Last time the condition transit from one status to another
    81  	// +optional
    82  	LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
    83  
    84  	// reason for the condition's last transition
    85  	Reason string `json:"reason,omitempty"`
    86  
    87  	// Human readable message indicating details about last transition.
    88  	// +optinal
    89  	Message string `json:"message,omitempty"`
    90  }
    91  
    92  // ServicePolicyStatus defines the observed state of ServicePolicy
    93  type ServicePolicyStatus struct {
    94  	// The latest available observations of an object's current state.
    95  	// +optional
    96  	Conditions []ServicePolicyCondition `json:"conditions,omitempty"`
    97  
    98  	// Represents time when the strategy was acknowledged by the controller.
    99  	// It is represented in RFC3339 form and is in UTC.
   100  	// +optional
   101  	StartTime *metav1.Time `json:"startTime,omitempty"`
   102  
   103  	// Represents time when the strategy was completed.
   104  	// It is represented in RFC3339 form and is in UTC.
   105  	// +optional
   106  	CompletionTime *metav1.Time `json:"completionTime,omitempty"`
   107  }
   108  
   109  // +genclient
   110  // +kubebuilder:object:root=true
   111  
   112  // ServicePolicy is the Schema for the servicepolicies API
   113  // +k8s:openapi-gen=true
   114  type ServicePolicy struct {
   115  	metav1.TypeMeta   `json:",inline"`
   116  	metav1.ObjectMeta `json:"metadata,omitempty"`
   117  
   118  	Spec   ServicePolicySpec   `json:"spec,omitempty"`
   119  	Status ServicePolicyStatus `json:"status,omitempty"`
   120  }
   121  
   122  // +kubebuilder:object:root=true
   123  
   124  // ServicePolicyList contains a list of ServicePolicy
   125  type ServicePolicyList struct {
   126  	metav1.TypeMeta `json:",inline"`
   127  	metav1.ListMeta `json:"metadata,omitempty"`
   128  	Items           []ServicePolicy `json:"items"`
   129  }
   130  
   131  func init() {
   132  	SchemeBuilder.Register(&ServicePolicy{}, &ServicePolicyList{})
   133  }