...

Source file src/github.com/chaos-mesh/chaos-mesh/api/v1alpha1/zz_generated.chaosmesh.go

Documentation: github.com/chaos-mesh/chaos-mesh/api/v1alpha1

     1  // Copyright Chaos Mesh Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  // http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  //
    15  
    16  // Code generated by chaos-builder. DO NOT EDIT.
    17  
    18  package v1alpha1
    19  
    20  import (
    21  	"encoding/json"
    22  	"reflect"
    23  	"time"
    24  	"fmt"
    25  
    26  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    27  	"sigs.k8s.io/controller-runtime/pkg/webhook"
    28  	logf "sigs.k8s.io/controller-runtime/pkg/log"
    29  	"k8s.io/apimachinery/pkg/runtime"
    30  
    31  	gw "github.com/chaos-mesh/chaos-mesh/api/v1alpha1/genericwebhook"
    32  )
    33  
    34  // updating spec of a chaos will have no effect, we'd better reject it
    35  var ErrCanNotUpdateChaos = fmt.Errorf("Cannot update chaos spec")
    36  
    37  const KindAWSChaos = "AWSChaos"
    38  
    39  // IsDeleted returns whether this resource has been deleted
    40  func (in *AWSChaos) IsDeleted() bool {
    41  	return !in.DeletionTimestamp.IsZero()
    42  }
    43  
    44  // IsPaused returns whether this resource has been paused
    45  func (in *AWSChaos) IsPaused() bool {
    46  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
    47  		return false
    48  	}
    49  	return true
    50  }
    51  
    52  // GetObjectMeta would return the ObjectMeta for chaos
    53  func (in *AWSChaos) GetObjectMeta() *metav1.ObjectMeta {
    54  	return &in.ObjectMeta
    55  }
    56  
    57  // GetDuration would return the duration for chaos
    58  func (in *AWSChaosSpec) GetDuration() (*time.Duration, error) {
    59  	if in.Duration == nil {
    60  		return nil, nil
    61  	}
    62  	duration, err := time.ParseDuration(string(*in.Duration))
    63  	if err != nil {
    64  		return nil, err
    65  	}
    66  	return &duration, nil
    67  }
    68  
    69  // GetStatus returns the status
    70  func (in *AWSChaos) GetStatus() *ChaosStatus {
    71  	return &in.Status.ChaosStatus
    72  }
    73  
    74  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
    75  func (in *AWSChaos) GetSpecAndMetaString() (string, error) {
    76  	spec, err := json.Marshal(in.Spec)
    77  	if err != nil {
    78  		return "", err
    79  	}
    80  
    81  	meta := in.ObjectMeta.DeepCopy()
    82  	meta.SetResourceVersion("")
    83  	meta.SetGeneration(0)
    84  
    85  	return string(spec) + meta.String(), nil
    86  }
    87  
    88  // +kubebuilder:object:root=true
    89  
    90  // AWSChaosList contains a list of AWSChaos
    91  type AWSChaosList struct {
    92  	metav1.TypeMeta `json:",inline"`
    93  	metav1.ListMeta `json:"metadata,omitempty"`
    94  	Items           []AWSChaos `json:"items"`
    95  }
    96  
    97  func (in *AWSChaosList) DeepCopyList() GenericChaosList {
    98  	return in.DeepCopy()
    99  }
   100  
   101  // ListChaos returns a list of chaos
   102  func (in *AWSChaosList) ListChaos() []GenericChaos {
   103  	var result []GenericChaos
   104  	for _, item := range in.Items {
   105  		item := item
   106  		result = append(result, &item)
   107  	}
   108  	return result
   109  }
   110  
   111  func (in *AWSChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
   112  	duration, err := in.Spec.GetDuration()
   113  	if err != nil {
   114  		return false, 0, err
   115  	}
   116  
   117  	if duration != nil {
   118  		stopTime := in.GetCreationTimestamp().Add(*duration)
   119  		if stopTime.Before(now) {
   120  			return true, 0, nil
   121  		}
   122  
   123  		return false, stopTime.Sub(now), nil
   124  	}
   125  
   126  	return false, 0, nil
   127  }
   128  
   129  func (in *AWSChaos) IsOneShot() bool {
   130  	if in.Spec.Action==Ec2Restart {
   131  		return true
   132  	}
   133  
   134  	return false
   135  }
   136  
   137  var AWSChaosWebhookLog = logf.Log.WithName("AWSChaos-resource")
   138  
   139  func (in *AWSChaos) ValidateCreate() error {
   140  	AWSChaosWebhookLog.Info("validate create", "name", in.Name)
   141  	return in.Validate()
   142  }
   143  
   144  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
   145  func (in *AWSChaos) ValidateUpdate(old runtime.Object) error {
   146  	AWSChaosWebhookLog.Info("validate update", "name", in.Name)
   147  	if !reflect.DeepEqual(in.Spec, old.(*AWSChaos).Spec) {
   148  		return ErrCanNotUpdateChaos
   149  	}
   150  	return in.Validate()
   151  }
   152  
   153  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
   154  func (in *AWSChaos) ValidateDelete() error {
   155  	AWSChaosWebhookLog.Info("validate delete", "name", in.Name)
   156  
   157  	// Nothing to do?
   158  	return nil
   159  }
   160  
   161  var _ webhook.Validator = &AWSChaos{}
   162  
   163  func (in *AWSChaos) Validate() error {
   164  	errs := gw.Validate(in)
   165  	return gw.Aggregate(errs)
   166  }
   167  
   168  var _ webhook.Defaulter = &AWSChaos{}
   169  
   170  func (in *AWSChaos) Default() {
   171  	gw.Default(in)
   172  }
   173  
   174  const KindDNSChaos = "DNSChaos"
   175  
   176  // IsDeleted returns whether this resource has been deleted
   177  func (in *DNSChaos) IsDeleted() bool {
   178  	return !in.DeletionTimestamp.IsZero()
   179  }
   180  
   181  // IsPaused returns whether this resource has been paused
   182  func (in *DNSChaos) IsPaused() bool {
   183  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
   184  		return false
   185  	}
   186  	return true
   187  }
   188  
   189  // GetObjectMeta would return the ObjectMeta for chaos
   190  func (in *DNSChaos) GetObjectMeta() *metav1.ObjectMeta {
   191  	return &in.ObjectMeta
   192  }
   193  
   194  // GetDuration would return the duration for chaos
   195  func (in *DNSChaosSpec) GetDuration() (*time.Duration, error) {
   196  	if in.Duration == nil {
   197  		return nil, nil
   198  	}
   199  	duration, err := time.ParseDuration(string(*in.Duration))
   200  	if err != nil {
   201  		return nil, err
   202  	}
   203  	return &duration, nil
   204  }
   205  
   206  // GetStatus returns the status
   207  func (in *DNSChaos) GetStatus() *ChaosStatus {
   208  	return &in.Status.ChaosStatus
   209  }
   210  
   211  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
   212  func (in *DNSChaos) GetSpecAndMetaString() (string, error) {
   213  	spec, err := json.Marshal(in.Spec)
   214  	if err != nil {
   215  		return "", err
   216  	}
   217  
   218  	meta := in.ObjectMeta.DeepCopy()
   219  	meta.SetResourceVersion("")
   220  	meta.SetGeneration(0)
   221  
   222  	return string(spec) + meta.String(), nil
   223  }
   224  
   225  // +kubebuilder:object:root=true
   226  
   227  // DNSChaosList contains a list of DNSChaos
   228  type DNSChaosList struct {
   229  	metav1.TypeMeta `json:",inline"`
   230  	metav1.ListMeta `json:"metadata,omitempty"`
   231  	Items           []DNSChaos `json:"items"`
   232  }
   233  
   234  func (in *DNSChaosList) DeepCopyList() GenericChaosList {
   235  	return in.DeepCopy()
   236  }
   237  
   238  // ListChaos returns a list of chaos
   239  func (in *DNSChaosList) ListChaos() []GenericChaos {
   240  	var result []GenericChaos
   241  	for _, item := range in.Items {
   242  		item := item
   243  		result = append(result, &item)
   244  	}
   245  	return result
   246  }
   247  
   248  func (in *DNSChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
   249  	duration, err := in.Spec.GetDuration()
   250  	if err != nil {
   251  		return false, 0, err
   252  	}
   253  
   254  	if duration != nil {
   255  		stopTime := in.GetCreationTimestamp().Add(*duration)
   256  		if stopTime.Before(now) {
   257  			return true, 0, nil
   258  		}
   259  
   260  		return false, stopTime.Sub(now), nil
   261  	}
   262  
   263  	return false, 0, nil
   264  }
   265  
   266  func (in *DNSChaos) IsOneShot() bool {
   267  	return false
   268  }
   269  
   270  var DNSChaosWebhookLog = logf.Log.WithName("DNSChaos-resource")
   271  
   272  func (in *DNSChaos) ValidateCreate() error {
   273  	DNSChaosWebhookLog.Info("validate create", "name", in.Name)
   274  	return in.Validate()
   275  }
   276  
   277  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
   278  func (in *DNSChaos) ValidateUpdate(old runtime.Object) error {
   279  	DNSChaosWebhookLog.Info("validate update", "name", in.Name)
   280  	if !reflect.DeepEqual(in.Spec, old.(*DNSChaos).Spec) {
   281  		return ErrCanNotUpdateChaos
   282  	}
   283  	return in.Validate()
   284  }
   285  
   286  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
   287  func (in *DNSChaos) ValidateDelete() error {
   288  	DNSChaosWebhookLog.Info("validate delete", "name", in.Name)
   289  
   290  	// Nothing to do?
   291  	return nil
   292  }
   293  
   294  var _ webhook.Validator = &DNSChaos{}
   295  
   296  func (in *DNSChaos) Validate() error {
   297  	errs := gw.Validate(in)
   298  	return gw.Aggregate(errs)
   299  }
   300  
   301  var _ webhook.Defaulter = &DNSChaos{}
   302  
   303  func (in *DNSChaos) Default() {
   304  	gw.Default(in)
   305  }
   306  
   307  const KindGCPChaos = "GCPChaos"
   308  
   309  // IsDeleted returns whether this resource has been deleted
   310  func (in *GCPChaos) IsDeleted() bool {
   311  	return !in.DeletionTimestamp.IsZero()
   312  }
   313  
   314  // IsPaused returns whether this resource has been paused
   315  func (in *GCPChaos) IsPaused() bool {
   316  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
   317  		return false
   318  	}
   319  	return true
   320  }
   321  
   322  // GetObjectMeta would return the ObjectMeta for chaos
   323  func (in *GCPChaos) GetObjectMeta() *metav1.ObjectMeta {
   324  	return &in.ObjectMeta
   325  }
   326  
   327  // GetDuration would return the duration for chaos
   328  func (in *GCPChaosSpec) GetDuration() (*time.Duration, error) {
   329  	if in.Duration == nil {
   330  		return nil, nil
   331  	}
   332  	duration, err := time.ParseDuration(string(*in.Duration))
   333  	if err != nil {
   334  		return nil, err
   335  	}
   336  	return &duration, nil
   337  }
   338  
   339  // GetStatus returns the status
   340  func (in *GCPChaos) GetStatus() *ChaosStatus {
   341  	return &in.Status.ChaosStatus
   342  }
   343  
   344  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
   345  func (in *GCPChaos) GetSpecAndMetaString() (string, error) {
   346  	spec, err := json.Marshal(in.Spec)
   347  	if err != nil {
   348  		return "", err
   349  	}
   350  
   351  	meta := in.ObjectMeta.DeepCopy()
   352  	meta.SetResourceVersion("")
   353  	meta.SetGeneration(0)
   354  
   355  	return string(spec) + meta.String(), nil
   356  }
   357  
   358  // +kubebuilder:object:root=true
   359  
   360  // GCPChaosList contains a list of GCPChaos
   361  type GCPChaosList struct {
   362  	metav1.TypeMeta `json:",inline"`
   363  	metav1.ListMeta `json:"metadata,omitempty"`
   364  	Items           []GCPChaos `json:"items"`
   365  }
   366  
   367  func (in *GCPChaosList) DeepCopyList() GenericChaosList {
   368  	return in.DeepCopy()
   369  }
   370  
   371  // ListChaos returns a list of chaos
   372  func (in *GCPChaosList) ListChaos() []GenericChaos {
   373  	var result []GenericChaos
   374  	for _, item := range in.Items {
   375  		item := item
   376  		result = append(result, &item)
   377  	}
   378  	return result
   379  }
   380  
   381  func (in *GCPChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
   382  	duration, err := in.Spec.GetDuration()
   383  	if err != nil {
   384  		return false, 0, err
   385  	}
   386  
   387  	if duration != nil {
   388  		stopTime := in.GetCreationTimestamp().Add(*duration)
   389  		if stopTime.Before(now) {
   390  			return true, 0, nil
   391  		}
   392  
   393  		return false, stopTime.Sub(now), nil
   394  	}
   395  
   396  	return false, 0, nil
   397  }
   398  
   399  func (in *GCPChaos) IsOneShot() bool {
   400  	if in.Spec.Action==NodeReset {
   401  		return true
   402  	}
   403  
   404  	return false
   405  }
   406  
   407  var GCPChaosWebhookLog = logf.Log.WithName("GCPChaos-resource")
   408  
   409  func (in *GCPChaos) ValidateCreate() error {
   410  	GCPChaosWebhookLog.Info("validate create", "name", in.Name)
   411  	return in.Validate()
   412  }
   413  
   414  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
   415  func (in *GCPChaos) ValidateUpdate(old runtime.Object) error {
   416  	GCPChaosWebhookLog.Info("validate update", "name", in.Name)
   417  	if !reflect.DeepEqual(in.Spec, old.(*GCPChaos).Spec) {
   418  		return ErrCanNotUpdateChaos
   419  	}
   420  	return in.Validate()
   421  }
   422  
   423  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
   424  func (in *GCPChaos) ValidateDelete() error {
   425  	GCPChaosWebhookLog.Info("validate delete", "name", in.Name)
   426  
   427  	// Nothing to do?
   428  	return nil
   429  }
   430  
   431  var _ webhook.Validator = &GCPChaos{}
   432  
   433  func (in *GCPChaos) Validate() error {
   434  	errs := gw.Validate(in)
   435  	return gw.Aggregate(errs)
   436  }
   437  
   438  var _ webhook.Defaulter = &GCPChaos{}
   439  
   440  func (in *GCPChaos) Default() {
   441  	gw.Default(in)
   442  }
   443  
   444  const KindHTTPChaos = "HTTPChaos"
   445  
   446  // IsDeleted returns whether this resource has been deleted
   447  func (in *HTTPChaos) IsDeleted() bool {
   448  	return !in.DeletionTimestamp.IsZero()
   449  }
   450  
   451  // IsPaused returns whether this resource has been paused
   452  func (in *HTTPChaos) IsPaused() bool {
   453  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
   454  		return false
   455  	}
   456  	return true
   457  }
   458  
   459  // GetObjectMeta would return the ObjectMeta for chaos
   460  func (in *HTTPChaos) GetObjectMeta() *metav1.ObjectMeta {
   461  	return &in.ObjectMeta
   462  }
   463  
   464  // GetDuration would return the duration for chaos
   465  func (in *HTTPChaosSpec) GetDuration() (*time.Duration, error) {
   466  	if in.Duration == nil {
   467  		return nil, nil
   468  	}
   469  	duration, err := time.ParseDuration(string(*in.Duration))
   470  	if err != nil {
   471  		return nil, err
   472  	}
   473  	return &duration, nil
   474  }
   475  
   476  // GetStatus returns the status
   477  func (in *HTTPChaos) GetStatus() *ChaosStatus {
   478  	return &in.Status.ChaosStatus
   479  }
   480  
   481  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
   482  func (in *HTTPChaos) GetSpecAndMetaString() (string, error) {
   483  	spec, err := json.Marshal(in.Spec)
   484  	if err != nil {
   485  		return "", err
   486  	}
   487  
   488  	meta := in.ObjectMeta.DeepCopy()
   489  	meta.SetResourceVersion("")
   490  	meta.SetGeneration(0)
   491  
   492  	return string(spec) + meta.String(), nil
   493  }
   494  
   495  // +kubebuilder:object:root=true
   496  
   497  // HTTPChaosList contains a list of HTTPChaos
   498  type HTTPChaosList struct {
   499  	metav1.TypeMeta `json:",inline"`
   500  	metav1.ListMeta `json:"metadata,omitempty"`
   501  	Items           []HTTPChaos `json:"items"`
   502  }
   503  
   504  func (in *HTTPChaosList) DeepCopyList() GenericChaosList {
   505  	return in.DeepCopy()
   506  }
   507  
   508  // ListChaos returns a list of chaos
   509  func (in *HTTPChaosList) ListChaos() []GenericChaos {
   510  	var result []GenericChaos
   511  	for _, item := range in.Items {
   512  		item := item
   513  		result = append(result, &item)
   514  	}
   515  	return result
   516  }
   517  
   518  func (in *HTTPChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
   519  	duration, err := in.Spec.GetDuration()
   520  	if err != nil {
   521  		return false, 0, err
   522  	}
   523  
   524  	if duration != nil {
   525  		stopTime := in.GetCreationTimestamp().Add(*duration)
   526  		if stopTime.Before(now) {
   527  			return true, 0, nil
   528  		}
   529  
   530  		return false, stopTime.Sub(now), nil
   531  	}
   532  
   533  	return false, 0, nil
   534  }
   535  
   536  func (in *HTTPChaos) IsOneShot() bool {
   537  	return false
   538  }
   539  
   540  var HTTPChaosWebhookLog = logf.Log.WithName("HTTPChaos-resource")
   541  
   542  func (in *HTTPChaos) ValidateCreate() error {
   543  	HTTPChaosWebhookLog.Info("validate create", "name", in.Name)
   544  	return in.Validate()
   545  }
   546  
   547  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
   548  func (in *HTTPChaos) ValidateUpdate(old runtime.Object) error {
   549  	HTTPChaosWebhookLog.Info("validate update", "name", in.Name)
   550  	if !reflect.DeepEqual(in.Spec, old.(*HTTPChaos).Spec) {
   551  		return ErrCanNotUpdateChaos
   552  	}
   553  	return in.Validate()
   554  }
   555  
   556  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
   557  func (in *HTTPChaos) ValidateDelete() error {
   558  	HTTPChaosWebhookLog.Info("validate delete", "name", in.Name)
   559  
   560  	// Nothing to do?
   561  	return nil
   562  }
   563  
   564  var _ webhook.Validator = &HTTPChaos{}
   565  
   566  func (in *HTTPChaos) Validate() error {
   567  	errs := gw.Validate(in)
   568  	return gw.Aggregate(errs)
   569  }
   570  
   571  var _ webhook.Defaulter = &HTTPChaos{}
   572  
   573  func (in *HTTPChaos) Default() {
   574  	gw.Default(in)
   575  }
   576  
   577  const KindIOChaos = "IOChaos"
   578  
   579  // IsDeleted returns whether this resource has been deleted
   580  func (in *IOChaos) IsDeleted() bool {
   581  	return !in.DeletionTimestamp.IsZero()
   582  }
   583  
   584  // IsPaused returns whether this resource has been paused
   585  func (in *IOChaos) IsPaused() bool {
   586  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
   587  		return false
   588  	}
   589  	return true
   590  }
   591  
   592  // GetObjectMeta would return the ObjectMeta for chaos
   593  func (in *IOChaos) GetObjectMeta() *metav1.ObjectMeta {
   594  	return &in.ObjectMeta
   595  }
   596  
   597  // GetDuration would return the duration for chaos
   598  func (in *IOChaosSpec) GetDuration() (*time.Duration, error) {
   599  	if in.Duration == nil {
   600  		return nil, nil
   601  	}
   602  	duration, err := time.ParseDuration(string(*in.Duration))
   603  	if err != nil {
   604  		return nil, err
   605  	}
   606  	return &duration, nil
   607  }
   608  
   609  // GetStatus returns the status
   610  func (in *IOChaos) GetStatus() *ChaosStatus {
   611  	return &in.Status.ChaosStatus
   612  }
   613  
   614  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
   615  func (in *IOChaos) GetSpecAndMetaString() (string, error) {
   616  	spec, err := json.Marshal(in.Spec)
   617  	if err != nil {
   618  		return "", err
   619  	}
   620  
   621  	meta := in.ObjectMeta.DeepCopy()
   622  	meta.SetResourceVersion("")
   623  	meta.SetGeneration(0)
   624  
   625  	return string(spec) + meta.String(), nil
   626  }
   627  
   628  // +kubebuilder:object:root=true
   629  
   630  // IOChaosList contains a list of IOChaos
   631  type IOChaosList struct {
   632  	metav1.TypeMeta `json:",inline"`
   633  	metav1.ListMeta `json:"metadata,omitempty"`
   634  	Items           []IOChaos `json:"items"`
   635  }
   636  
   637  func (in *IOChaosList) DeepCopyList() GenericChaosList {
   638  	return in.DeepCopy()
   639  }
   640  
   641  // ListChaos returns a list of chaos
   642  func (in *IOChaosList) ListChaos() []GenericChaos {
   643  	var result []GenericChaos
   644  	for _, item := range in.Items {
   645  		item := item
   646  		result = append(result, &item)
   647  	}
   648  	return result
   649  }
   650  
   651  func (in *IOChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
   652  	duration, err := in.Spec.GetDuration()
   653  	if err != nil {
   654  		return false, 0, err
   655  	}
   656  
   657  	if duration != nil {
   658  		stopTime := in.GetCreationTimestamp().Add(*duration)
   659  		if stopTime.Before(now) {
   660  			return true, 0, nil
   661  		}
   662  
   663  		return false, stopTime.Sub(now), nil
   664  	}
   665  
   666  	return false, 0, nil
   667  }
   668  
   669  func (in *IOChaos) IsOneShot() bool {
   670  	return false
   671  }
   672  
   673  var IOChaosWebhookLog = logf.Log.WithName("IOChaos-resource")
   674  
   675  func (in *IOChaos) ValidateCreate() error {
   676  	IOChaosWebhookLog.Info("validate create", "name", in.Name)
   677  	return in.Validate()
   678  }
   679  
   680  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
   681  func (in *IOChaos) ValidateUpdate(old runtime.Object) error {
   682  	IOChaosWebhookLog.Info("validate update", "name", in.Name)
   683  	if !reflect.DeepEqual(in.Spec, old.(*IOChaos).Spec) {
   684  		return ErrCanNotUpdateChaos
   685  	}
   686  	return in.Validate()
   687  }
   688  
   689  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
   690  func (in *IOChaos) ValidateDelete() error {
   691  	IOChaosWebhookLog.Info("validate delete", "name", in.Name)
   692  
   693  	// Nothing to do?
   694  	return nil
   695  }
   696  
   697  var _ webhook.Validator = &IOChaos{}
   698  
   699  func (in *IOChaos) Validate() error {
   700  	errs := gw.Validate(in)
   701  	return gw.Aggregate(errs)
   702  }
   703  
   704  var _ webhook.Defaulter = &IOChaos{}
   705  
   706  func (in *IOChaos) Default() {
   707  	gw.Default(in)
   708  }
   709  
   710  const KindJVMChaos = "JVMChaos"
   711  
   712  // IsDeleted returns whether this resource has been deleted
   713  func (in *JVMChaos) IsDeleted() bool {
   714  	return !in.DeletionTimestamp.IsZero()
   715  }
   716  
   717  // IsPaused returns whether this resource has been paused
   718  func (in *JVMChaos) IsPaused() bool {
   719  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
   720  		return false
   721  	}
   722  	return true
   723  }
   724  
   725  // GetObjectMeta would return the ObjectMeta for chaos
   726  func (in *JVMChaos) GetObjectMeta() *metav1.ObjectMeta {
   727  	return &in.ObjectMeta
   728  }
   729  
   730  // GetDuration would return the duration for chaos
   731  func (in *JVMChaosSpec) GetDuration() (*time.Duration, error) {
   732  	if in.Duration == nil {
   733  		return nil, nil
   734  	}
   735  	duration, err := time.ParseDuration(string(*in.Duration))
   736  	if err != nil {
   737  		return nil, err
   738  	}
   739  	return &duration, nil
   740  }
   741  
   742  // GetStatus returns the status
   743  func (in *JVMChaos) GetStatus() *ChaosStatus {
   744  	return &in.Status.ChaosStatus
   745  }
   746  
   747  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
   748  func (in *JVMChaos) GetSpecAndMetaString() (string, error) {
   749  	spec, err := json.Marshal(in.Spec)
   750  	if err != nil {
   751  		return "", err
   752  	}
   753  
   754  	meta := in.ObjectMeta.DeepCopy()
   755  	meta.SetResourceVersion("")
   756  	meta.SetGeneration(0)
   757  
   758  	return string(spec) + meta.String(), nil
   759  }
   760  
   761  // +kubebuilder:object:root=true
   762  
   763  // JVMChaosList contains a list of JVMChaos
   764  type JVMChaosList struct {
   765  	metav1.TypeMeta `json:",inline"`
   766  	metav1.ListMeta `json:"metadata,omitempty"`
   767  	Items           []JVMChaos `json:"items"`
   768  }
   769  
   770  func (in *JVMChaosList) DeepCopyList() GenericChaosList {
   771  	return in.DeepCopy()
   772  }
   773  
   774  // ListChaos returns a list of chaos
   775  func (in *JVMChaosList) ListChaos() []GenericChaos {
   776  	var result []GenericChaos
   777  	for _, item := range in.Items {
   778  		item := item
   779  		result = append(result, &item)
   780  	}
   781  	return result
   782  }
   783  
   784  func (in *JVMChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
   785  	duration, err := in.Spec.GetDuration()
   786  	if err != nil {
   787  		return false, 0, err
   788  	}
   789  
   790  	if duration != nil {
   791  		stopTime := in.GetCreationTimestamp().Add(*duration)
   792  		if stopTime.Before(now) {
   793  			return true, 0, nil
   794  		}
   795  
   796  		return false, stopTime.Sub(now), nil
   797  	}
   798  
   799  	return false, 0, nil
   800  }
   801  
   802  func (in *JVMChaos) IsOneShot() bool {
   803  	return false
   804  }
   805  
   806  var JVMChaosWebhookLog = logf.Log.WithName("JVMChaos-resource")
   807  
   808  func (in *JVMChaos) ValidateCreate() error {
   809  	JVMChaosWebhookLog.Info("validate create", "name", in.Name)
   810  	return in.Validate()
   811  }
   812  
   813  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
   814  func (in *JVMChaos) ValidateUpdate(old runtime.Object) error {
   815  	JVMChaosWebhookLog.Info("validate update", "name", in.Name)
   816  	if !reflect.DeepEqual(in.Spec, old.(*JVMChaos).Spec) {
   817  		return ErrCanNotUpdateChaos
   818  	}
   819  	return in.Validate()
   820  }
   821  
   822  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
   823  func (in *JVMChaos) ValidateDelete() error {
   824  	JVMChaosWebhookLog.Info("validate delete", "name", in.Name)
   825  
   826  	// Nothing to do?
   827  	return nil
   828  }
   829  
   830  var _ webhook.Validator = &JVMChaos{}
   831  
   832  func (in *JVMChaos) Validate() error {
   833  	errs := gw.Validate(in)
   834  	return gw.Aggregate(errs)
   835  }
   836  
   837  var _ webhook.Defaulter = &JVMChaos{}
   838  
   839  func (in *JVMChaos) Default() {
   840  	gw.Default(in)
   841  }
   842  
   843  const KindKernelChaos = "KernelChaos"
   844  
   845  // IsDeleted returns whether this resource has been deleted
   846  func (in *KernelChaos) IsDeleted() bool {
   847  	return !in.DeletionTimestamp.IsZero()
   848  }
   849  
   850  // IsPaused returns whether this resource has been paused
   851  func (in *KernelChaos) IsPaused() bool {
   852  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
   853  		return false
   854  	}
   855  	return true
   856  }
   857  
   858  // GetObjectMeta would return the ObjectMeta for chaos
   859  func (in *KernelChaos) GetObjectMeta() *metav1.ObjectMeta {
   860  	return &in.ObjectMeta
   861  }
   862  
   863  // GetDuration would return the duration for chaos
   864  func (in *KernelChaosSpec) GetDuration() (*time.Duration, error) {
   865  	if in.Duration == nil {
   866  		return nil, nil
   867  	}
   868  	duration, err := time.ParseDuration(string(*in.Duration))
   869  	if err != nil {
   870  		return nil, err
   871  	}
   872  	return &duration, nil
   873  }
   874  
   875  // GetStatus returns the status
   876  func (in *KernelChaos) GetStatus() *ChaosStatus {
   877  	return &in.Status.ChaosStatus
   878  }
   879  
   880  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
   881  func (in *KernelChaos) GetSpecAndMetaString() (string, error) {
   882  	spec, err := json.Marshal(in.Spec)
   883  	if err != nil {
   884  		return "", err
   885  	}
   886  
   887  	meta := in.ObjectMeta.DeepCopy()
   888  	meta.SetResourceVersion("")
   889  	meta.SetGeneration(0)
   890  
   891  	return string(spec) + meta.String(), nil
   892  }
   893  
   894  // +kubebuilder:object:root=true
   895  
   896  // KernelChaosList contains a list of KernelChaos
   897  type KernelChaosList struct {
   898  	metav1.TypeMeta `json:",inline"`
   899  	metav1.ListMeta `json:"metadata,omitempty"`
   900  	Items           []KernelChaos `json:"items"`
   901  }
   902  
   903  func (in *KernelChaosList) DeepCopyList() GenericChaosList {
   904  	return in.DeepCopy()
   905  }
   906  
   907  // ListChaos returns a list of chaos
   908  func (in *KernelChaosList) ListChaos() []GenericChaos {
   909  	var result []GenericChaos
   910  	for _, item := range in.Items {
   911  		item := item
   912  		result = append(result, &item)
   913  	}
   914  	return result
   915  }
   916  
   917  func (in *KernelChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
   918  	duration, err := in.Spec.GetDuration()
   919  	if err != nil {
   920  		return false, 0, err
   921  	}
   922  
   923  	if duration != nil {
   924  		stopTime := in.GetCreationTimestamp().Add(*duration)
   925  		if stopTime.Before(now) {
   926  			return true, 0, nil
   927  		}
   928  
   929  		return false, stopTime.Sub(now), nil
   930  	}
   931  
   932  	return false, 0, nil
   933  }
   934  
   935  func (in *KernelChaos) IsOneShot() bool {
   936  	return false
   937  }
   938  
   939  var KernelChaosWebhookLog = logf.Log.WithName("KernelChaos-resource")
   940  
   941  func (in *KernelChaos) ValidateCreate() error {
   942  	KernelChaosWebhookLog.Info("validate create", "name", in.Name)
   943  	return in.Validate()
   944  }
   945  
   946  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
   947  func (in *KernelChaos) ValidateUpdate(old runtime.Object) error {
   948  	KernelChaosWebhookLog.Info("validate update", "name", in.Name)
   949  	if !reflect.DeepEqual(in.Spec, old.(*KernelChaos).Spec) {
   950  		return ErrCanNotUpdateChaos
   951  	}
   952  	return in.Validate()
   953  }
   954  
   955  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
   956  func (in *KernelChaos) ValidateDelete() error {
   957  	KernelChaosWebhookLog.Info("validate delete", "name", in.Name)
   958  
   959  	// Nothing to do?
   960  	return nil
   961  }
   962  
   963  var _ webhook.Validator = &KernelChaos{}
   964  
   965  func (in *KernelChaos) Validate() error {
   966  	errs := gw.Validate(in)
   967  	return gw.Aggregate(errs)
   968  }
   969  
   970  var _ webhook.Defaulter = &KernelChaos{}
   971  
   972  func (in *KernelChaos) Default() {
   973  	gw.Default(in)
   974  }
   975  
   976  const KindNetworkChaos = "NetworkChaos"
   977  
   978  // IsDeleted returns whether this resource has been deleted
   979  func (in *NetworkChaos) IsDeleted() bool {
   980  	return !in.DeletionTimestamp.IsZero()
   981  }
   982  
   983  // IsPaused returns whether this resource has been paused
   984  func (in *NetworkChaos) IsPaused() bool {
   985  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
   986  		return false
   987  	}
   988  	return true
   989  }
   990  
   991  // GetObjectMeta would return the ObjectMeta for chaos
   992  func (in *NetworkChaos) GetObjectMeta() *metav1.ObjectMeta {
   993  	return &in.ObjectMeta
   994  }
   995  
   996  // GetDuration would return the duration for chaos
   997  func (in *NetworkChaosSpec) GetDuration() (*time.Duration, error) {
   998  	if in.Duration == nil {
   999  		return nil, nil
  1000  	}
  1001  	duration, err := time.ParseDuration(string(*in.Duration))
  1002  	if err != nil {
  1003  		return nil, err
  1004  	}
  1005  	return &duration, nil
  1006  }
  1007  
  1008  // GetStatus returns the status
  1009  func (in *NetworkChaos) GetStatus() *ChaosStatus {
  1010  	return &in.Status.ChaosStatus
  1011  }
  1012  
  1013  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
  1014  func (in *NetworkChaos) GetSpecAndMetaString() (string, error) {
  1015  	spec, err := json.Marshal(in.Spec)
  1016  	if err != nil {
  1017  		return "", err
  1018  	}
  1019  
  1020  	meta := in.ObjectMeta.DeepCopy()
  1021  	meta.SetResourceVersion("")
  1022  	meta.SetGeneration(0)
  1023  
  1024  	return string(spec) + meta.String(), nil
  1025  }
  1026  
  1027  // +kubebuilder:object:root=true
  1028  
  1029  // NetworkChaosList contains a list of NetworkChaos
  1030  type NetworkChaosList struct {
  1031  	metav1.TypeMeta `json:",inline"`
  1032  	metav1.ListMeta `json:"metadata,omitempty"`
  1033  	Items           []NetworkChaos `json:"items"`
  1034  }
  1035  
  1036  func (in *NetworkChaosList) DeepCopyList() GenericChaosList {
  1037  	return in.DeepCopy()
  1038  }
  1039  
  1040  // ListChaos returns a list of chaos
  1041  func (in *NetworkChaosList) ListChaos() []GenericChaos {
  1042  	var result []GenericChaos
  1043  	for _, item := range in.Items {
  1044  		item := item
  1045  		result = append(result, &item)
  1046  	}
  1047  	return result
  1048  }
  1049  
  1050  func (in *NetworkChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
  1051  	duration, err := in.Spec.GetDuration()
  1052  	if err != nil {
  1053  		return false, 0, err
  1054  	}
  1055  
  1056  	if duration != nil {
  1057  		stopTime := in.GetCreationTimestamp().Add(*duration)
  1058  		if stopTime.Before(now) {
  1059  			return true, 0, nil
  1060  		}
  1061  
  1062  		return false, stopTime.Sub(now), nil
  1063  	}
  1064  
  1065  	return false, 0, nil
  1066  }
  1067  
  1068  func (in *NetworkChaos) IsOneShot() bool {
  1069  	return false
  1070  }
  1071  
  1072  var NetworkChaosWebhookLog = logf.Log.WithName("NetworkChaos-resource")
  1073  
  1074  func (in *NetworkChaos) ValidateCreate() error {
  1075  	NetworkChaosWebhookLog.Info("validate create", "name", in.Name)
  1076  	return in.Validate()
  1077  }
  1078  
  1079  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
  1080  func (in *NetworkChaos) ValidateUpdate(old runtime.Object) error {
  1081  	NetworkChaosWebhookLog.Info("validate update", "name", in.Name)
  1082  	if !reflect.DeepEqual(in.Spec, old.(*NetworkChaos).Spec) {
  1083  		return ErrCanNotUpdateChaos
  1084  	}
  1085  	return in.Validate()
  1086  }
  1087  
  1088  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
  1089  func (in *NetworkChaos) ValidateDelete() error {
  1090  	NetworkChaosWebhookLog.Info("validate delete", "name", in.Name)
  1091  
  1092  	// Nothing to do?
  1093  	return nil
  1094  }
  1095  
  1096  var _ webhook.Validator = &NetworkChaos{}
  1097  
  1098  func (in *NetworkChaos) Validate() error {
  1099  	errs := gw.Validate(in)
  1100  	return gw.Aggregate(errs)
  1101  }
  1102  
  1103  var _ webhook.Defaulter = &NetworkChaos{}
  1104  
  1105  func (in *NetworkChaos) Default() {
  1106  	gw.Default(in)
  1107  }
  1108  
  1109  const KindPhysicalMachineChaos = "PhysicalMachineChaos"
  1110  
  1111  // IsDeleted returns whether this resource has been deleted
  1112  func (in *PhysicalMachineChaos) IsDeleted() bool {
  1113  	return !in.DeletionTimestamp.IsZero()
  1114  }
  1115  
  1116  // IsPaused returns whether this resource has been paused
  1117  func (in *PhysicalMachineChaos) IsPaused() bool {
  1118  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
  1119  		return false
  1120  	}
  1121  	return true
  1122  }
  1123  
  1124  // GetObjectMeta would return the ObjectMeta for chaos
  1125  func (in *PhysicalMachineChaos) GetObjectMeta() *metav1.ObjectMeta {
  1126  	return &in.ObjectMeta
  1127  }
  1128  
  1129  // GetDuration would return the duration for chaos
  1130  func (in *PhysicalMachineChaosSpec) GetDuration() (*time.Duration, error) {
  1131  	if in.Duration == nil {
  1132  		return nil, nil
  1133  	}
  1134  	duration, err := time.ParseDuration(string(*in.Duration))
  1135  	if err != nil {
  1136  		return nil, err
  1137  	}
  1138  	return &duration, nil
  1139  }
  1140  
  1141  // GetStatus returns the status
  1142  func (in *PhysicalMachineChaos) GetStatus() *ChaosStatus {
  1143  	return &in.Status.ChaosStatus
  1144  }
  1145  
  1146  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
  1147  func (in *PhysicalMachineChaos) GetSpecAndMetaString() (string, error) {
  1148  	spec, err := json.Marshal(in.Spec)
  1149  	if err != nil {
  1150  		return "", err
  1151  	}
  1152  
  1153  	meta := in.ObjectMeta.DeepCopy()
  1154  	meta.SetResourceVersion("")
  1155  	meta.SetGeneration(0)
  1156  
  1157  	return string(spec) + meta.String(), nil
  1158  }
  1159  
  1160  // +kubebuilder:object:root=true
  1161  
  1162  // PhysicalMachineChaosList contains a list of PhysicalMachineChaos
  1163  type PhysicalMachineChaosList struct {
  1164  	metav1.TypeMeta `json:",inline"`
  1165  	metav1.ListMeta `json:"metadata,omitempty"`
  1166  	Items           []PhysicalMachineChaos `json:"items"`
  1167  }
  1168  
  1169  func (in *PhysicalMachineChaosList) DeepCopyList() GenericChaosList {
  1170  	return in.DeepCopy()
  1171  }
  1172  
  1173  // ListChaos returns a list of chaos
  1174  func (in *PhysicalMachineChaosList) ListChaos() []GenericChaos {
  1175  	var result []GenericChaos
  1176  	for _, item := range in.Items {
  1177  		item := item
  1178  		result = append(result, &item)
  1179  	}
  1180  	return result
  1181  }
  1182  
  1183  func (in *PhysicalMachineChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
  1184  	duration, err := in.Spec.GetDuration()
  1185  	if err != nil {
  1186  		return false, 0, err
  1187  	}
  1188  
  1189  	if duration != nil {
  1190  		stopTime := in.GetCreationTimestamp().Add(*duration)
  1191  		if stopTime.Before(now) {
  1192  			return true, 0, nil
  1193  		}
  1194  
  1195  		return false, stopTime.Sub(now), nil
  1196  	}
  1197  
  1198  	return false, 0, nil
  1199  }
  1200  
  1201  func (in *PhysicalMachineChaos) IsOneShot() bool {
  1202  	return false
  1203  }
  1204  
  1205  var PhysicalMachineChaosWebhookLog = logf.Log.WithName("PhysicalMachineChaos-resource")
  1206  
  1207  func (in *PhysicalMachineChaos) ValidateCreate() error {
  1208  	PhysicalMachineChaosWebhookLog.Info("validate create", "name", in.Name)
  1209  	return in.Validate()
  1210  }
  1211  
  1212  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
  1213  func (in *PhysicalMachineChaos) ValidateUpdate(old runtime.Object) error {
  1214  	PhysicalMachineChaosWebhookLog.Info("validate update", "name", in.Name)
  1215  	if !reflect.DeepEqual(in.Spec, old.(*PhysicalMachineChaos).Spec) {
  1216  		return ErrCanNotUpdateChaos
  1217  	}
  1218  	return in.Validate()
  1219  }
  1220  
  1221  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
  1222  func (in *PhysicalMachineChaos) ValidateDelete() error {
  1223  	PhysicalMachineChaosWebhookLog.Info("validate delete", "name", in.Name)
  1224  
  1225  	// Nothing to do?
  1226  	return nil
  1227  }
  1228  
  1229  var _ webhook.Validator = &PhysicalMachineChaos{}
  1230  
  1231  func (in *PhysicalMachineChaos) Validate() error {
  1232  	errs := gw.Validate(in)
  1233  	return gw.Aggregate(errs)
  1234  }
  1235  
  1236  var _ webhook.Defaulter = &PhysicalMachineChaos{}
  1237  
  1238  func (in *PhysicalMachineChaos) Default() {
  1239  	gw.Default(in)
  1240  }
  1241  
  1242  const KindPodChaos = "PodChaos"
  1243  
  1244  // IsDeleted returns whether this resource has been deleted
  1245  func (in *PodChaos) IsDeleted() bool {
  1246  	return !in.DeletionTimestamp.IsZero()
  1247  }
  1248  
  1249  // IsPaused returns whether this resource has been paused
  1250  func (in *PodChaos) IsPaused() bool {
  1251  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
  1252  		return false
  1253  	}
  1254  	return true
  1255  }
  1256  
  1257  // GetObjectMeta would return the ObjectMeta for chaos
  1258  func (in *PodChaos) GetObjectMeta() *metav1.ObjectMeta {
  1259  	return &in.ObjectMeta
  1260  }
  1261  
  1262  // GetDuration would return the duration for chaos
  1263  func (in *PodChaosSpec) GetDuration() (*time.Duration, error) {
  1264  	if in.Duration == nil {
  1265  		return nil, nil
  1266  	}
  1267  	duration, err := time.ParseDuration(string(*in.Duration))
  1268  	if err != nil {
  1269  		return nil, err
  1270  	}
  1271  	return &duration, nil
  1272  }
  1273  
  1274  // GetStatus returns the status
  1275  func (in *PodChaos) GetStatus() *ChaosStatus {
  1276  	return &in.Status.ChaosStatus
  1277  }
  1278  
  1279  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
  1280  func (in *PodChaos) GetSpecAndMetaString() (string, error) {
  1281  	spec, err := json.Marshal(in.Spec)
  1282  	if err != nil {
  1283  		return "", err
  1284  	}
  1285  
  1286  	meta := in.ObjectMeta.DeepCopy()
  1287  	meta.SetResourceVersion("")
  1288  	meta.SetGeneration(0)
  1289  
  1290  	return string(spec) + meta.String(), nil
  1291  }
  1292  
  1293  // +kubebuilder:object:root=true
  1294  
  1295  // PodChaosList contains a list of PodChaos
  1296  type PodChaosList struct {
  1297  	metav1.TypeMeta `json:",inline"`
  1298  	metav1.ListMeta `json:"metadata,omitempty"`
  1299  	Items           []PodChaos `json:"items"`
  1300  }
  1301  
  1302  func (in *PodChaosList) DeepCopyList() GenericChaosList {
  1303  	return in.DeepCopy()
  1304  }
  1305  
  1306  // ListChaos returns a list of chaos
  1307  func (in *PodChaosList) ListChaos() []GenericChaos {
  1308  	var result []GenericChaos
  1309  	for _, item := range in.Items {
  1310  		item := item
  1311  		result = append(result, &item)
  1312  	}
  1313  	return result
  1314  }
  1315  
  1316  func (in *PodChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
  1317  	duration, err := in.Spec.GetDuration()
  1318  	if err != nil {
  1319  		return false, 0, err
  1320  	}
  1321  
  1322  	if duration != nil {
  1323  		stopTime := in.GetCreationTimestamp().Add(*duration)
  1324  		if stopTime.Before(now) {
  1325  			return true, 0, nil
  1326  		}
  1327  
  1328  		return false, stopTime.Sub(now), nil
  1329  	}
  1330  
  1331  	return false, 0, nil
  1332  }
  1333  
  1334  func (in *PodChaos) IsOneShot() bool {
  1335  	if in.Spec.Action==PodKillAction || in.Spec.Action==ContainerKillAction {
  1336  		return true
  1337  	}
  1338  
  1339  	return false
  1340  }
  1341  
  1342  var PodChaosWebhookLog = logf.Log.WithName("PodChaos-resource")
  1343  
  1344  func (in *PodChaos) ValidateCreate() error {
  1345  	PodChaosWebhookLog.Info("validate create", "name", in.Name)
  1346  	return in.Validate()
  1347  }
  1348  
  1349  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
  1350  func (in *PodChaos) ValidateUpdate(old runtime.Object) error {
  1351  	PodChaosWebhookLog.Info("validate update", "name", in.Name)
  1352  	if !reflect.DeepEqual(in.Spec, old.(*PodChaos).Spec) {
  1353  		return ErrCanNotUpdateChaos
  1354  	}
  1355  	return in.Validate()
  1356  }
  1357  
  1358  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
  1359  func (in *PodChaos) ValidateDelete() error {
  1360  	PodChaosWebhookLog.Info("validate delete", "name", in.Name)
  1361  
  1362  	// Nothing to do?
  1363  	return nil
  1364  }
  1365  
  1366  var _ webhook.Validator = &PodChaos{}
  1367  
  1368  func (in *PodChaos) Validate() error {
  1369  	errs := gw.Validate(in)
  1370  	return gw.Aggregate(errs)
  1371  }
  1372  
  1373  var _ webhook.Defaulter = &PodChaos{}
  1374  
  1375  func (in *PodChaos) Default() {
  1376  	gw.Default(in)
  1377  }
  1378  
  1379  const KindPodHttpChaos = "PodHttpChaos"
  1380  
  1381  var PodHttpChaosWebhookLog = logf.Log.WithName("PodHttpChaos-resource")
  1382  
  1383  func (in *PodHttpChaos) ValidateCreate() error {
  1384  	PodHttpChaosWebhookLog.Info("validate create", "name", in.Name)
  1385  	return in.Validate()
  1386  }
  1387  
  1388  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
  1389  func (in *PodHttpChaos) ValidateUpdate(old runtime.Object) error {
  1390  	PodHttpChaosWebhookLog.Info("validate update", "name", in.Name)
  1391  	return in.Validate()
  1392  }
  1393  
  1394  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
  1395  func (in *PodHttpChaos) ValidateDelete() error {
  1396  	PodHttpChaosWebhookLog.Info("validate delete", "name", in.Name)
  1397  
  1398  	// Nothing to do?
  1399  	return nil
  1400  }
  1401  
  1402  var _ webhook.Validator = &PodHttpChaos{}
  1403  
  1404  func (in *PodHttpChaos) Validate() error {
  1405  	errs := gw.Validate(in)
  1406  	return gw.Aggregate(errs)
  1407  }
  1408  
  1409  var _ webhook.Defaulter = &PodHttpChaos{}
  1410  
  1411  func (in *PodHttpChaos) Default() {
  1412  	gw.Default(in)
  1413  }
  1414  
  1415  const KindPodIOChaos = "PodIOChaos"
  1416  
  1417  var PodIOChaosWebhookLog = logf.Log.WithName("PodIOChaos-resource")
  1418  
  1419  func (in *PodIOChaos) ValidateCreate() error {
  1420  	PodIOChaosWebhookLog.Info("validate create", "name", in.Name)
  1421  	return in.Validate()
  1422  }
  1423  
  1424  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
  1425  func (in *PodIOChaos) ValidateUpdate(old runtime.Object) error {
  1426  	PodIOChaosWebhookLog.Info("validate update", "name", in.Name)
  1427  	return in.Validate()
  1428  }
  1429  
  1430  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
  1431  func (in *PodIOChaos) ValidateDelete() error {
  1432  	PodIOChaosWebhookLog.Info("validate delete", "name", in.Name)
  1433  
  1434  	// Nothing to do?
  1435  	return nil
  1436  }
  1437  
  1438  var _ webhook.Validator = &PodIOChaos{}
  1439  
  1440  func (in *PodIOChaos) Validate() error {
  1441  	errs := gw.Validate(in)
  1442  	return gw.Aggregate(errs)
  1443  }
  1444  
  1445  var _ webhook.Defaulter = &PodIOChaos{}
  1446  
  1447  func (in *PodIOChaos) Default() {
  1448  	gw.Default(in)
  1449  }
  1450  
  1451  const KindPodNetworkChaos = "PodNetworkChaos"
  1452  
  1453  var PodNetworkChaosWebhookLog = logf.Log.WithName("PodNetworkChaos-resource")
  1454  
  1455  func (in *PodNetworkChaos) ValidateCreate() error {
  1456  	PodNetworkChaosWebhookLog.Info("validate create", "name", in.Name)
  1457  	return in.Validate()
  1458  }
  1459  
  1460  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
  1461  func (in *PodNetworkChaos) ValidateUpdate(old runtime.Object) error {
  1462  	PodNetworkChaosWebhookLog.Info("validate update", "name", in.Name)
  1463  	return in.Validate()
  1464  }
  1465  
  1466  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
  1467  func (in *PodNetworkChaos) ValidateDelete() error {
  1468  	PodNetworkChaosWebhookLog.Info("validate delete", "name", in.Name)
  1469  
  1470  	// Nothing to do?
  1471  	return nil
  1472  }
  1473  
  1474  var _ webhook.Validator = &PodNetworkChaos{}
  1475  
  1476  func (in *PodNetworkChaos) Validate() error {
  1477  	errs := gw.Validate(in)
  1478  	return gw.Aggregate(errs)
  1479  }
  1480  
  1481  var _ webhook.Defaulter = &PodNetworkChaos{}
  1482  
  1483  func (in *PodNetworkChaos) Default() {
  1484  	gw.Default(in)
  1485  }
  1486  
  1487  const KindStressChaos = "StressChaos"
  1488  
  1489  // IsDeleted returns whether this resource has been deleted
  1490  func (in *StressChaos) IsDeleted() bool {
  1491  	return !in.DeletionTimestamp.IsZero()
  1492  }
  1493  
  1494  // IsPaused returns whether this resource has been paused
  1495  func (in *StressChaos) IsPaused() bool {
  1496  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
  1497  		return false
  1498  	}
  1499  	return true
  1500  }
  1501  
  1502  // GetObjectMeta would return the ObjectMeta for chaos
  1503  func (in *StressChaos) GetObjectMeta() *metav1.ObjectMeta {
  1504  	return &in.ObjectMeta
  1505  }
  1506  
  1507  // GetDuration would return the duration for chaos
  1508  func (in *StressChaosSpec) GetDuration() (*time.Duration, error) {
  1509  	if in.Duration == nil {
  1510  		return nil, nil
  1511  	}
  1512  	duration, err := time.ParseDuration(string(*in.Duration))
  1513  	if err != nil {
  1514  		return nil, err
  1515  	}
  1516  	return &duration, nil
  1517  }
  1518  
  1519  // GetStatus returns the status
  1520  func (in *StressChaos) GetStatus() *ChaosStatus {
  1521  	return &in.Status.ChaosStatus
  1522  }
  1523  
  1524  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
  1525  func (in *StressChaos) GetSpecAndMetaString() (string, error) {
  1526  	spec, err := json.Marshal(in.Spec)
  1527  	if err != nil {
  1528  		return "", err
  1529  	}
  1530  
  1531  	meta := in.ObjectMeta.DeepCopy()
  1532  	meta.SetResourceVersion("")
  1533  	meta.SetGeneration(0)
  1534  
  1535  	return string(spec) + meta.String(), nil
  1536  }
  1537  
  1538  // +kubebuilder:object:root=true
  1539  
  1540  // StressChaosList contains a list of StressChaos
  1541  type StressChaosList struct {
  1542  	metav1.TypeMeta `json:",inline"`
  1543  	metav1.ListMeta `json:"metadata,omitempty"`
  1544  	Items           []StressChaos `json:"items"`
  1545  }
  1546  
  1547  func (in *StressChaosList) DeepCopyList() GenericChaosList {
  1548  	return in.DeepCopy()
  1549  }
  1550  
  1551  // ListChaos returns a list of chaos
  1552  func (in *StressChaosList) ListChaos() []GenericChaos {
  1553  	var result []GenericChaos
  1554  	for _, item := range in.Items {
  1555  		item := item
  1556  		result = append(result, &item)
  1557  	}
  1558  	return result
  1559  }
  1560  
  1561  func (in *StressChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
  1562  	duration, err := in.Spec.GetDuration()
  1563  	if err != nil {
  1564  		return false, 0, err
  1565  	}
  1566  
  1567  	if duration != nil {
  1568  		stopTime := in.GetCreationTimestamp().Add(*duration)
  1569  		if stopTime.Before(now) {
  1570  			return true, 0, nil
  1571  		}
  1572  
  1573  		return false, stopTime.Sub(now), nil
  1574  	}
  1575  
  1576  	return false, 0, nil
  1577  }
  1578  
  1579  func (in *StressChaos) IsOneShot() bool {
  1580  	return false
  1581  }
  1582  
  1583  var StressChaosWebhookLog = logf.Log.WithName("StressChaos-resource")
  1584  
  1585  func (in *StressChaos) ValidateCreate() error {
  1586  	StressChaosWebhookLog.Info("validate create", "name", in.Name)
  1587  	return in.Validate()
  1588  }
  1589  
  1590  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
  1591  func (in *StressChaos) ValidateUpdate(old runtime.Object) error {
  1592  	StressChaosWebhookLog.Info("validate update", "name", in.Name)
  1593  	if !reflect.DeepEqual(in.Spec, old.(*StressChaos).Spec) {
  1594  		return ErrCanNotUpdateChaos
  1595  	}
  1596  	return in.Validate()
  1597  }
  1598  
  1599  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
  1600  func (in *StressChaos) ValidateDelete() error {
  1601  	StressChaosWebhookLog.Info("validate delete", "name", in.Name)
  1602  
  1603  	// Nothing to do?
  1604  	return nil
  1605  }
  1606  
  1607  var _ webhook.Validator = &StressChaos{}
  1608  
  1609  func (in *StressChaos) Validate() error {
  1610  	errs := gw.Validate(in)
  1611  	return gw.Aggregate(errs)
  1612  }
  1613  
  1614  var _ webhook.Defaulter = &StressChaos{}
  1615  
  1616  func (in *StressChaos) Default() {
  1617  	gw.Default(in)
  1618  }
  1619  
  1620  const KindTimeChaos = "TimeChaos"
  1621  
  1622  // IsDeleted returns whether this resource has been deleted
  1623  func (in *TimeChaos) IsDeleted() bool {
  1624  	return !in.DeletionTimestamp.IsZero()
  1625  }
  1626  
  1627  // IsPaused returns whether this resource has been paused
  1628  func (in *TimeChaos) IsPaused() bool {
  1629  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
  1630  		return false
  1631  	}
  1632  	return true
  1633  }
  1634  
  1635  // GetObjectMeta would return the ObjectMeta for chaos
  1636  func (in *TimeChaos) GetObjectMeta() *metav1.ObjectMeta {
  1637  	return &in.ObjectMeta
  1638  }
  1639  
  1640  // GetDuration would return the duration for chaos
  1641  func (in *TimeChaosSpec) GetDuration() (*time.Duration, error) {
  1642  	if in.Duration == nil {
  1643  		return nil, nil
  1644  	}
  1645  	duration, err := time.ParseDuration(string(*in.Duration))
  1646  	if err != nil {
  1647  		return nil, err
  1648  	}
  1649  	return &duration, nil
  1650  }
  1651  
  1652  // GetStatus returns the status
  1653  func (in *TimeChaos) GetStatus() *ChaosStatus {
  1654  	return &in.Status.ChaosStatus
  1655  }
  1656  
  1657  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
  1658  func (in *TimeChaos) GetSpecAndMetaString() (string, error) {
  1659  	spec, err := json.Marshal(in.Spec)
  1660  	if err != nil {
  1661  		return "", err
  1662  	}
  1663  
  1664  	meta := in.ObjectMeta.DeepCopy()
  1665  	meta.SetResourceVersion("")
  1666  	meta.SetGeneration(0)
  1667  
  1668  	return string(spec) + meta.String(), nil
  1669  }
  1670  
  1671  // +kubebuilder:object:root=true
  1672  
  1673  // TimeChaosList contains a list of TimeChaos
  1674  type TimeChaosList struct {
  1675  	metav1.TypeMeta `json:",inline"`
  1676  	metav1.ListMeta `json:"metadata,omitempty"`
  1677  	Items           []TimeChaos `json:"items"`
  1678  }
  1679  
  1680  func (in *TimeChaosList) DeepCopyList() GenericChaosList {
  1681  	return in.DeepCopy()
  1682  }
  1683  
  1684  // ListChaos returns a list of chaos
  1685  func (in *TimeChaosList) ListChaos() []GenericChaos {
  1686  	var result []GenericChaos
  1687  	for _, item := range in.Items {
  1688  		item := item
  1689  		result = append(result, &item)
  1690  	}
  1691  	return result
  1692  }
  1693  
  1694  func (in *TimeChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
  1695  	duration, err := in.Spec.GetDuration()
  1696  	if err != nil {
  1697  		return false, 0, err
  1698  	}
  1699  
  1700  	if duration != nil {
  1701  		stopTime := in.GetCreationTimestamp().Add(*duration)
  1702  		if stopTime.Before(now) {
  1703  			return true, 0, nil
  1704  		}
  1705  
  1706  		return false, stopTime.Sub(now), nil
  1707  	}
  1708  
  1709  	return false, 0, nil
  1710  }
  1711  
  1712  func (in *TimeChaos) IsOneShot() bool {
  1713  	return false
  1714  }
  1715  
  1716  var TimeChaosWebhookLog = logf.Log.WithName("TimeChaos-resource")
  1717  
  1718  func (in *TimeChaos) ValidateCreate() error {
  1719  	TimeChaosWebhookLog.Info("validate create", "name", in.Name)
  1720  	return in.Validate()
  1721  }
  1722  
  1723  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
  1724  func (in *TimeChaos) ValidateUpdate(old runtime.Object) error {
  1725  	TimeChaosWebhookLog.Info("validate update", "name", in.Name)
  1726  	if !reflect.DeepEqual(in.Spec, old.(*TimeChaos).Spec) {
  1727  		return ErrCanNotUpdateChaos
  1728  	}
  1729  	return in.Validate()
  1730  }
  1731  
  1732  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
  1733  func (in *TimeChaos) ValidateDelete() error {
  1734  	TimeChaosWebhookLog.Info("validate delete", "name", in.Name)
  1735  
  1736  	// Nothing to do?
  1737  	return nil
  1738  }
  1739  
  1740  var _ webhook.Validator = &TimeChaos{}
  1741  
  1742  func (in *TimeChaos) Validate() error {
  1743  	errs := gw.Validate(in)
  1744  	return gw.Aggregate(errs)
  1745  }
  1746  
  1747  var _ webhook.Defaulter = &TimeChaos{}
  1748  
  1749  func (in *TimeChaos) Default() {
  1750  	gw.Default(in)
  1751  }
  1752  
  1753  func init() {
  1754  
  1755  	SchemeBuilder.Register(&AWSChaos{}, &AWSChaosList{})
  1756  	all.register(KindAWSChaos, &ChaosKind{
  1757  		chaos: &AWSChaos{},
  1758  		list:  &AWSChaosList{},
  1759  	})
  1760  
  1761  	SchemeBuilder.Register(&DNSChaos{}, &DNSChaosList{})
  1762  	all.register(KindDNSChaos, &ChaosKind{
  1763  		chaos: &DNSChaos{},
  1764  		list:  &DNSChaosList{},
  1765  	})
  1766  
  1767  	SchemeBuilder.Register(&GCPChaos{}, &GCPChaosList{})
  1768  	all.register(KindGCPChaos, &ChaosKind{
  1769  		chaos: &GCPChaos{},
  1770  		list:  &GCPChaosList{},
  1771  	})
  1772  
  1773  	SchemeBuilder.Register(&HTTPChaos{}, &HTTPChaosList{})
  1774  	all.register(KindHTTPChaos, &ChaosKind{
  1775  		chaos: &HTTPChaos{},
  1776  		list:  &HTTPChaosList{},
  1777  	})
  1778  
  1779  	SchemeBuilder.Register(&IOChaos{}, &IOChaosList{})
  1780  	all.register(KindIOChaos, &ChaosKind{
  1781  		chaos: &IOChaos{},
  1782  		list:  &IOChaosList{},
  1783  	})
  1784  
  1785  	SchemeBuilder.Register(&JVMChaos{}, &JVMChaosList{})
  1786  	all.register(KindJVMChaos, &ChaosKind{
  1787  		chaos: &JVMChaos{},
  1788  		list:  &JVMChaosList{},
  1789  	})
  1790  
  1791  	SchemeBuilder.Register(&KernelChaos{}, &KernelChaosList{})
  1792  	all.register(KindKernelChaos, &ChaosKind{
  1793  		chaos: &KernelChaos{},
  1794  		list:  &KernelChaosList{},
  1795  	})
  1796  
  1797  	SchemeBuilder.Register(&NetworkChaos{}, &NetworkChaosList{})
  1798  	all.register(KindNetworkChaos, &ChaosKind{
  1799  		chaos: &NetworkChaos{},
  1800  		list:  &NetworkChaosList{},
  1801  	})
  1802  
  1803  	SchemeBuilder.Register(&PhysicalMachineChaos{}, &PhysicalMachineChaosList{})
  1804  	all.register(KindPhysicalMachineChaos, &ChaosKind{
  1805  		chaos: &PhysicalMachineChaos{},
  1806  		list:  &PhysicalMachineChaosList{},
  1807  	})
  1808  
  1809  	SchemeBuilder.Register(&PodChaos{}, &PodChaosList{})
  1810  	all.register(KindPodChaos, &ChaosKind{
  1811  		chaos: &PodChaos{},
  1812  		list:  &PodChaosList{},
  1813  	})
  1814  
  1815  	SchemeBuilder.Register(&PodHttpChaos{}, &PodHttpChaosList{})
  1816  
  1817  	SchemeBuilder.Register(&PodIOChaos{}, &PodIOChaosList{})
  1818  
  1819  	SchemeBuilder.Register(&PodNetworkChaos{}, &PodNetworkChaosList{})
  1820  
  1821  	SchemeBuilder.Register(&StressChaos{}, &StressChaosList{})
  1822  	all.register(KindStressChaos, &ChaosKind{
  1823  		chaos: &StressChaos{},
  1824  		list:  &StressChaosList{},
  1825  	})
  1826  
  1827  	SchemeBuilder.Register(&TimeChaos{}, &TimeChaosList{})
  1828  	all.register(KindTimeChaos, &ChaosKind{
  1829  		chaos: &TimeChaos{},
  1830  		list:  &TimeChaosList{},
  1831  	})
  1832  
  1833  
  1834  	allScheduleItem.register(KindAWSChaos, &ChaosKind{
  1835  		chaos: &AWSChaos{},
  1836  		list:  &AWSChaosList{},
  1837  	})
  1838  
  1839  	allScheduleItem.register(KindDNSChaos, &ChaosKind{
  1840  		chaos: &DNSChaos{},
  1841  		list:  &DNSChaosList{},
  1842  	})
  1843  
  1844  	allScheduleItem.register(KindGCPChaos, &ChaosKind{
  1845  		chaos: &GCPChaos{},
  1846  		list:  &GCPChaosList{},
  1847  	})
  1848  
  1849  	allScheduleItem.register(KindHTTPChaos, &ChaosKind{
  1850  		chaos: &HTTPChaos{},
  1851  		list:  &HTTPChaosList{},
  1852  	})
  1853  
  1854  	allScheduleItem.register(KindIOChaos, &ChaosKind{
  1855  		chaos: &IOChaos{},
  1856  		list:  &IOChaosList{},
  1857  	})
  1858  
  1859  	allScheduleItem.register(KindJVMChaos, &ChaosKind{
  1860  		chaos: &JVMChaos{},
  1861  		list:  &JVMChaosList{},
  1862  	})
  1863  
  1864  	allScheduleItem.register(KindKernelChaos, &ChaosKind{
  1865  		chaos: &KernelChaos{},
  1866  		list:  &KernelChaosList{},
  1867  	})
  1868  
  1869  	allScheduleItem.register(KindNetworkChaos, &ChaosKind{
  1870  		chaos: &NetworkChaos{},
  1871  		list:  &NetworkChaosList{},
  1872  	})
  1873  
  1874  	allScheduleItem.register(KindPhysicalMachineChaos, &ChaosKind{
  1875  		chaos: &PhysicalMachineChaos{},
  1876  		list:  &PhysicalMachineChaosList{},
  1877  	})
  1878  
  1879  	allScheduleItem.register(KindPodChaos, &ChaosKind{
  1880  		chaos: &PodChaos{},
  1881  		list:  &PodChaosList{},
  1882  	})
  1883  
  1884  	allScheduleItem.register(KindStressChaos, &ChaosKind{
  1885  		chaos: &StressChaos{},
  1886  		list:  &StressChaosList{},
  1887  	})
  1888  
  1889  	allScheduleItem.register(KindTimeChaos, &ChaosKind{
  1890  		chaos: &TimeChaos{},
  1891  		list:  &TimeChaosList{},
  1892  	})
  1893  
  1894  	allScheduleItem.register(KindWorkflow, &ChaosKind{
  1895  		chaos: &Workflow{},
  1896  		list:  &WorkflowList{},
  1897  	})
  1898  
  1899  }
  1900