...

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  
    25  	"github.com/pkg/errors"
    26  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    27  	"k8s.io/apimachinery/pkg/runtime"
    28  	logf "sigs.k8s.io/controller-runtime/pkg/log"
    29  	"sigs.k8s.io/controller-runtime/pkg/webhook"
    30  	"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
    31  
    32  	gw "github.com/chaos-mesh/chaos-mesh/api/genericwebhook"
    33  )
    34  
    35  // updating spec of a chaos will have no effect, we'd better reject it
    36  var ErrCanNotUpdateChaos = errors.New("Cannot update chaos spec")
    37  
    38  const KindAWSChaos = "AWSChaos"
    39  
    40  // IsDeleted returns whether this resource has been deleted
    41  func (in *AWSChaos) IsDeleted() bool {
    42  	return !in.DeletionTimestamp.IsZero()
    43  }
    44  
    45  // IsPaused returns whether this resource has been paused
    46  func (in *AWSChaos) IsPaused() bool {
    47  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
    48  		return false
    49  	}
    50  	return true
    51  }
    52  
    53  // GetObjectMeta would return the ObjectMeta for chaos
    54  func (in *AWSChaos) GetObjectMeta() *metav1.ObjectMeta {
    55  	return &in.ObjectMeta
    56  }
    57  
    58  // GetDuration would return the duration for chaos
    59  func (in *AWSChaosSpec) GetDuration() (*time.Duration, error) {
    60  	if in.Duration == nil {
    61  		return nil, nil
    62  	}
    63  	duration, err := time.ParseDuration(string(*in.Duration))
    64  	if err != nil {
    65  		return nil, err
    66  	}
    67  	return &duration, nil
    68  }
    69  
    70  // GetStatus returns the status
    71  func (in *AWSChaos) GetStatus() *ChaosStatus {
    72  	return &in.Status.ChaosStatus
    73  }
    74  
    75  // GetRemoteCluster returns the remoteCluster
    76  func (in *AWSChaos) GetRemoteCluster() string {
    77  	return in.Spec.RemoteCluster
    78  }
    79  
    80  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
    81  func (in *AWSChaos) GetSpecAndMetaString() (string, error) {
    82  	spec, err := json.Marshal(in.Spec)
    83  	if err != nil {
    84  		return "", err
    85  	}
    86  
    87  	meta := in.ObjectMeta.DeepCopy()
    88  	meta.SetResourceVersion("")
    89  	meta.SetGeneration(0)
    90  
    91  	return string(spec) + meta.String(), nil
    92  }
    93  
    94  // +kubebuilder:object:root=true
    95  
    96  // AWSChaosList contains a list of AWSChaos
    97  type AWSChaosList struct {
    98  	metav1.TypeMeta `json:",inline"`
    99  	metav1.ListMeta `json:"metadata,omitempty"`
   100  	Items           []AWSChaos `json:"items"`
   101  }
   102  
   103  func (in *AWSChaosList) DeepCopyList() GenericChaosList {
   104  	return in.DeepCopy()
   105  }
   106  
   107  // ListChaos returns a list of chaos
   108  func (in *AWSChaosList) ListChaos() []GenericChaos {
   109  	var result []GenericChaos
   110  	for _, item := range in.Items {
   111  		item := item
   112  		result = append(result, &item)
   113  	}
   114  	return result
   115  }
   116  
   117  func (in *AWSChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
   118  	duration, err := in.Spec.GetDuration()
   119  	if err != nil {
   120  		return false, 0, err
   121  	}
   122  
   123  	if duration != nil {
   124  		stopTime := in.GetCreationTimestamp().Add(*duration)
   125  		if stopTime.Before(now) {
   126  			return true, 0, nil
   127  		}
   128  
   129  		return false, stopTime.Sub(now), nil
   130  	}
   131  
   132  	return false, 0, nil
   133  }
   134  
   135  func (in *AWSChaos) IsOneShot() bool {
   136  	if in.Spec.Action==Ec2Restart {
   137  		return true
   138  	}
   139  
   140  	return false
   141  }
   142  
   143  var AWSChaosWebhookLog = logf.Log.WithName("AWSChaos-resource")
   144  
   145  func (in *AWSChaos) ValidateCreate() (admission.Warnings, error) {
   146  	AWSChaosWebhookLog.Info("validate create", "name", in.Name)
   147  	return in.Validate()
   148  }
   149  
   150  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
   151  func (in *AWSChaos) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
   152  	AWSChaosWebhookLog.Info("validate update", "name", in.Name)
   153  	if !reflect.DeepEqual(in.Spec, old.(*AWSChaos).Spec) {
   154  		return nil, ErrCanNotUpdateChaos
   155  	}
   156  	return in.Validate()
   157  }
   158  
   159  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
   160  func (in *AWSChaos) ValidateDelete() (admission.Warnings, error) {
   161  	AWSChaosWebhookLog.Info("validate delete", "name", in.Name)
   162  
   163  	// Nothing to do?
   164  	return nil, nil
   165  }
   166  
   167  var _ webhook.Validator = &AWSChaos{}
   168  
   169  func (in *AWSChaos) Validate() ([]string, error) {
   170  	errs := gw.Validate(in)
   171  	return nil, gw.Aggregate(errs)
   172  }
   173  
   174  var _ webhook.Defaulter = &AWSChaos{}
   175  
   176  func (in *AWSChaos) Default() {
   177  	gw.Default(in)
   178  }
   179  
   180  const KindAzureChaos = "AzureChaos"
   181  
   182  // IsDeleted returns whether this resource has been deleted
   183  func (in *AzureChaos) IsDeleted() bool {
   184  	return !in.DeletionTimestamp.IsZero()
   185  }
   186  
   187  // IsPaused returns whether this resource has been paused
   188  func (in *AzureChaos) IsPaused() bool {
   189  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
   190  		return false
   191  	}
   192  	return true
   193  }
   194  
   195  // GetObjectMeta would return the ObjectMeta for chaos
   196  func (in *AzureChaos) GetObjectMeta() *metav1.ObjectMeta {
   197  	return &in.ObjectMeta
   198  }
   199  
   200  // GetDuration would return the duration for chaos
   201  func (in *AzureChaosSpec) GetDuration() (*time.Duration, error) {
   202  	if in.Duration == nil {
   203  		return nil, nil
   204  	}
   205  	duration, err := time.ParseDuration(string(*in.Duration))
   206  	if err != nil {
   207  		return nil, err
   208  	}
   209  	return &duration, nil
   210  }
   211  
   212  // GetStatus returns the status
   213  func (in *AzureChaos) GetStatus() *ChaosStatus {
   214  	return &in.Status.ChaosStatus
   215  }
   216  
   217  // GetRemoteCluster returns the remoteCluster
   218  func (in *AzureChaos) GetRemoteCluster() string {
   219  	return in.Spec.RemoteCluster
   220  }
   221  
   222  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
   223  func (in *AzureChaos) GetSpecAndMetaString() (string, error) {
   224  	spec, err := json.Marshal(in.Spec)
   225  	if err != nil {
   226  		return "", err
   227  	}
   228  
   229  	meta := in.ObjectMeta.DeepCopy()
   230  	meta.SetResourceVersion("")
   231  	meta.SetGeneration(0)
   232  
   233  	return string(spec) + meta.String(), nil
   234  }
   235  
   236  // +kubebuilder:object:root=true
   237  
   238  // AzureChaosList contains a list of AzureChaos
   239  type AzureChaosList struct {
   240  	metav1.TypeMeta `json:",inline"`
   241  	metav1.ListMeta `json:"metadata,omitempty"`
   242  	Items           []AzureChaos `json:"items"`
   243  }
   244  
   245  func (in *AzureChaosList) DeepCopyList() GenericChaosList {
   246  	return in.DeepCopy()
   247  }
   248  
   249  // ListChaos returns a list of chaos
   250  func (in *AzureChaosList) ListChaos() []GenericChaos {
   251  	var result []GenericChaos
   252  	for _, item := range in.Items {
   253  		item := item
   254  		result = append(result, &item)
   255  	}
   256  	return result
   257  }
   258  
   259  func (in *AzureChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
   260  	duration, err := in.Spec.GetDuration()
   261  	if err != nil {
   262  		return false, 0, err
   263  	}
   264  
   265  	if duration != nil {
   266  		stopTime := in.GetCreationTimestamp().Add(*duration)
   267  		if stopTime.Before(now) {
   268  			return true, 0, nil
   269  		}
   270  
   271  		return false, stopTime.Sub(now), nil
   272  	}
   273  
   274  	return false, 0, nil
   275  }
   276  
   277  func (in *AzureChaos) IsOneShot() bool {
   278  	if in.Spec.Action==AzureVmRestart {
   279  		return true
   280  	}
   281  
   282  	return false
   283  }
   284  
   285  var AzureChaosWebhookLog = logf.Log.WithName("AzureChaos-resource")
   286  
   287  func (in *AzureChaos) ValidateCreate() (admission.Warnings, error) {
   288  	AzureChaosWebhookLog.Info("validate create", "name", in.Name)
   289  	return in.Validate()
   290  }
   291  
   292  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
   293  func (in *AzureChaos) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
   294  	AzureChaosWebhookLog.Info("validate update", "name", in.Name)
   295  	if !reflect.DeepEqual(in.Spec, old.(*AzureChaos).Spec) {
   296  		return nil, ErrCanNotUpdateChaos
   297  	}
   298  	return in.Validate()
   299  }
   300  
   301  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
   302  func (in *AzureChaos) ValidateDelete() (admission.Warnings, error) {
   303  	AzureChaosWebhookLog.Info("validate delete", "name", in.Name)
   304  
   305  	// Nothing to do?
   306  	return nil, nil
   307  }
   308  
   309  var _ webhook.Validator = &AzureChaos{}
   310  
   311  func (in *AzureChaos) Validate() ([]string, error) {
   312  	errs := gw.Validate(in)
   313  	return nil, gw.Aggregate(errs)
   314  }
   315  
   316  var _ webhook.Defaulter = &AzureChaos{}
   317  
   318  func (in *AzureChaos) Default() {
   319  	gw.Default(in)
   320  }
   321  
   322  const KindBlockChaos = "BlockChaos"
   323  
   324  // IsDeleted returns whether this resource has been deleted
   325  func (in *BlockChaos) IsDeleted() bool {
   326  	return !in.DeletionTimestamp.IsZero()
   327  }
   328  
   329  // IsPaused returns whether this resource has been paused
   330  func (in *BlockChaos) IsPaused() bool {
   331  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
   332  		return false
   333  	}
   334  	return true
   335  }
   336  
   337  // GetObjectMeta would return the ObjectMeta for chaos
   338  func (in *BlockChaos) GetObjectMeta() *metav1.ObjectMeta {
   339  	return &in.ObjectMeta
   340  }
   341  
   342  // GetDuration would return the duration for chaos
   343  func (in *BlockChaosSpec) GetDuration() (*time.Duration, error) {
   344  	if in.Duration == nil {
   345  		return nil, nil
   346  	}
   347  	duration, err := time.ParseDuration(string(*in.Duration))
   348  	if err != nil {
   349  		return nil, err
   350  	}
   351  	return &duration, nil
   352  }
   353  
   354  // GetStatus returns the status
   355  func (in *BlockChaos) GetStatus() *ChaosStatus {
   356  	return &in.Status.ChaosStatus
   357  }
   358  
   359  // GetRemoteCluster returns the remoteCluster
   360  func (in *BlockChaos) GetRemoteCluster() string {
   361  	return in.Spec.RemoteCluster
   362  }
   363  
   364  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
   365  func (in *BlockChaos) GetSpecAndMetaString() (string, error) {
   366  	spec, err := json.Marshal(in.Spec)
   367  	if err != nil {
   368  		return "", err
   369  	}
   370  
   371  	meta := in.ObjectMeta.DeepCopy()
   372  	meta.SetResourceVersion("")
   373  	meta.SetGeneration(0)
   374  
   375  	return string(spec) + meta.String(), nil
   376  }
   377  
   378  // +kubebuilder:object:root=true
   379  
   380  // BlockChaosList contains a list of BlockChaos
   381  type BlockChaosList struct {
   382  	metav1.TypeMeta `json:",inline"`
   383  	metav1.ListMeta `json:"metadata,omitempty"`
   384  	Items           []BlockChaos `json:"items"`
   385  }
   386  
   387  func (in *BlockChaosList) DeepCopyList() GenericChaosList {
   388  	return in.DeepCopy()
   389  }
   390  
   391  // ListChaos returns a list of chaos
   392  func (in *BlockChaosList) ListChaos() []GenericChaos {
   393  	var result []GenericChaos
   394  	for _, item := range in.Items {
   395  		item := item
   396  		result = append(result, &item)
   397  	}
   398  	return result
   399  }
   400  
   401  func (in *BlockChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
   402  	duration, err := in.Spec.GetDuration()
   403  	if err != nil {
   404  		return false, 0, err
   405  	}
   406  
   407  	if duration != nil {
   408  		stopTime := in.GetCreationTimestamp().Add(*duration)
   409  		if stopTime.Before(now) {
   410  			return true, 0, nil
   411  		}
   412  
   413  		return false, stopTime.Sub(now), nil
   414  	}
   415  
   416  	return false, 0, nil
   417  }
   418  
   419  func (in *BlockChaos) IsOneShot() bool {
   420  	return false
   421  }
   422  
   423  var BlockChaosWebhookLog = logf.Log.WithName("BlockChaos-resource")
   424  
   425  func (in *BlockChaos) ValidateCreate() (admission.Warnings, error) {
   426  	BlockChaosWebhookLog.Info("validate create", "name", in.Name)
   427  	return in.Validate()
   428  }
   429  
   430  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
   431  func (in *BlockChaos) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
   432  	BlockChaosWebhookLog.Info("validate update", "name", in.Name)
   433  	if !reflect.DeepEqual(in.Spec, old.(*BlockChaos).Spec) {
   434  		return nil, ErrCanNotUpdateChaos
   435  	}
   436  	return in.Validate()
   437  }
   438  
   439  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
   440  func (in *BlockChaos) ValidateDelete() (admission.Warnings, error) {
   441  	BlockChaosWebhookLog.Info("validate delete", "name", in.Name)
   442  
   443  	// Nothing to do?
   444  	return nil, nil
   445  }
   446  
   447  var _ webhook.Validator = &BlockChaos{}
   448  
   449  func (in *BlockChaos) Validate() ([]string, error) {
   450  	errs := gw.Validate(in)
   451  	return nil, gw.Aggregate(errs)
   452  }
   453  
   454  var _ webhook.Defaulter = &BlockChaos{}
   455  
   456  func (in *BlockChaos) Default() {
   457  	gw.Default(in)
   458  }
   459  
   460  const KindDNSChaos = "DNSChaos"
   461  
   462  // IsDeleted returns whether this resource has been deleted
   463  func (in *DNSChaos) IsDeleted() bool {
   464  	return !in.DeletionTimestamp.IsZero()
   465  }
   466  
   467  // IsPaused returns whether this resource has been paused
   468  func (in *DNSChaos) IsPaused() bool {
   469  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
   470  		return false
   471  	}
   472  	return true
   473  }
   474  
   475  // GetObjectMeta would return the ObjectMeta for chaos
   476  func (in *DNSChaos) GetObjectMeta() *metav1.ObjectMeta {
   477  	return &in.ObjectMeta
   478  }
   479  
   480  // GetDuration would return the duration for chaos
   481  func (in *DNSChaosSpec) GetDuration() (*time.Duration, error) {
   482  	if in.Duration == nil {
   483  		return nil, nil
   484  	}
   485  	duration, err := time.ParseDuration(string(*in.Duration))
   486  	if err != nil {
   487  		return nil, err
   488  	}
   489  	return &duration, nil
   490  }
   491  
   492  // GetStatus returns the status
   493  func (in *DNSChaos) GetStatus() *ChaosStatus {
   494  	return &in.Status.ChaosStatus
   495  }
   496  
   497  // GetRemoteCluster returns the remoteCluster
   498  func (in *DNSChaos) GetRemoteCluster() string {
   499  	return in.Spec.RemoteCluster
   500  }
   501  
   502  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
   503  func (in *DNSChaos) GetSpecAndMetaString() (string, error) {
   504  	spec, err := json.Marshal(in.Spec)
   505  	if err != nil {
   506  		return "", err
   507  	}
   508  
   509  	meta := in.ObjectMeta.DeepCopy()
   510  	meta.SetResourceVersion("")
   511  	meta.SetGeneration(0)
   512  
   513  	return string(spec) + meta.String(), nil
   514  }
   515  
   516  // +kubebuilder:object:root=true
   517  
   518  // DNSChaosList contains a list of DNSChaos
   519  type DNSChaosList struct {
   520  	metav1.TypeMeta `json:",inline"`
   521  	metav1.ListMeta `json:"metadata,omitempty"`
   522  	Items           []DNSChaos `json:"items"`
   523  }
   524  
   525  func (in *DNSChaosList) DeepCopyList() GenericChaosList {
   526  	return in.DeepCopy()
   527  }
   528  
   529  // ListChaos returns a list of chaos
   530  func (in *DNSChaosList) ListChaos() []GenericChaos {
   531  	var result []GenericChaos
   532  	for _, item := range in.Items {
   533  		item := item
   534  		result = append(result, &item)
   535  	}
   536  	return result
   537  }
   538  
   539  func (in *DNSChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
   540  	duration, err := in.Spec.GetDuration()
   541  	if err != nil {
   542  		return false, 0, err
   543  	}
   544  
   545  	if duration != nil {
   546  		stopTime := in.GetCreationTimestamp().Add(*duration)
   547  		if stopTime.Before(now) {
   548  			return true, 0, nil
   549  		}
   550  
   551  		return false, stopTime.Sub(now), nil
   552  	}
   553  
   554  	return false, 0, nil
   555  }
   556  
   557  func (in *DNSChaos) IsOneShot() bool {
   558  	return false
   559  }
   560  
   561  var DNSChaosWebhookLog = logf.Log.WithName("DNSChaos-resource")
   562  
   563  func (in *DNSChaos) ValidateCreate() (admission.Warnings, error) {
   564  	DNSChaosWebhookLog.Info("validate create", "name", in.Name)
   565  	return in.Validate()
   566  }
   567  
   568  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
   569  func (in *DNSChaos) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
   570  	DNSChaosWebhookLog.Info("validate update", "name", in.Name)
   571  	if !reflect.DeepEqual(in.Spec, old.(*DNSChaos).Spec) {
   572  		return nil, ErrCanNotUpdateChaos
   573  	}
   574  	return in.Validate()
   575  }
   576  
   577  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
   578  func (in *DNSChaos) ValidateDelete() (admission.Warnings, error) {
   579  	DNSChaosWebhookLog.Info("validate delete", "name", in.Name)
   580  
   581  	// Nothing to do?
   582  	return nil, nil
   583  }
   584  
   585  var _ webhook.Validator = &DNSChaos{}
   586  
   587  func (in *DNSChaos) Validate() ([]string, error) {
   588  	errs := gw.Validate(in)
   589  	return nil, gw.Aggregate(errs)
   590  }
   591  
   592  var _ webhook.Defaulter = &DNSChaos{}
   593  
   594  func (in *DNSChaos) Default() {
   595  	gw.Default(in)
   596  }
   597  
   598  const KindGCPChaos = "GCPChaos"
   599  
   600  // IsDeleted returns whether this resource has been deleted
   601  func (in *GCPChaos) IsDeleted() bool {
   602  	return !in.DeletionTimestamp.IsZero()
   603  }
   604  
   605  // IsPaused returns whether this resource has been paused
   606  func (in *GCPChaos) IsPaused() bool {
   607  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
   608  		return false
   609  	}
   610  	return true
   611  }
   612  
   613  // GetObjectMeta would return the ObjectMeta for chaos
   614  func (in *GCPChaos) GetObjectMeta() *metav1.ObjectMeta {
   615  	return &in.ObjectMeta
   616  }
   617  
   618  // GetDuration would return the duration for chaos
   619  func (in *GCPChaosSpec) GetDuration() (*time.Duration, error) {
   620  	if in.Duration == nil {
   621  		return nil, nil
   622  	}
   623  	duration, err := time.ParseDuration(string(*in.Duration))
   624  	if err != nil {
   625  		return nil, err
   626  	}
   627  	return &duration, nil
   628  }
   629  
   630  // GetStatus returns the status
   631  func (in *GCPChaos) GetStatus() *ChaosStatus {
   632  	return &in.Status.ChaosStatus
   633  }
   634  
   635  // GetRemoteCluster returns the remoteCluster
   636  func (in *GCPChaos) GetRemoteCluster() string {
   637  	return in.Spec.RemoteCluster
   638  }
   639  
   640  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
   641  func (in *GCPChaos) GetSpecAndMetaString() (string, error) {
   642  	spec, err := json.Marshal(in.Spec)
   643  	if err != nil {
   644  		return "", err
   645  	}
   646  
   647  	meta := in.ObjectMeta.DeepCopy()
   648  	meta.SetResourceVersion("")
   649  	meta.SetGeneration(0)
   650  
   651  	return string(spec) + meta.String(), nil
   652  }
   653  
   654  // +kubebuilder:object:root=true
   655  
   656  // GCPChaosList contains a list of GCPChaos
   657  type GCPChaosList struct {
   658  	metav1.TypeMeta `json:",inline"`
   659  	metav1.ListMeta `json:"metadata,omitempty"`
   660  	Items           []GCPChaos `json:"items"`
   661  }
   662  
   663  func (in *GCPChaosList) DeepCopyList() GenericChaosList {
   664  	return in.DeepCopy()
   665  }
   666  
   667  // ListChaos returns a list of chaos
   668  func (in *GCPChaosList) ListChaos() []GenericChaos {
   669  	var result []GenericChaos
   670  	for _, item := range in.Items {
   671  		item := item
   672  		result = append(result, &item)
   673  	}
   674  	return result
   675  }
   676  
   677  func (in *GCPChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
   678  	duration, err := in.Spec.GetDuration()
   679  	if err != nil {
   680  		return false, 0, err
   681  	}
   682  
   683  	if duration != nil {
   684  		stopTime := in.GetCreationTimestamp().Add(*duration)
   685  		if stopTime.Before(now) {
   686  			return true, 0, nil
   687  		}
   688  
   689  		return false, stopTime.Sub(now), nil
   690  	}
   691  
   692  	return false, 0, nil
   693  }
   694  
   695  func (in *GCPChaos) IsOneShot() bool {
   696  	if in.Spec.Action==NodeReset {
   697  		return true
   698  	}
   699  
   700  	return false
   701  }
   702  
   703  var GCPChaosWebhookLog = logf.Log.WithName("GCPChaos-resource")
   704  
   705  func (in *GCPChaos) ValidateCreate() (admission.Warnings, error) {
   706  	GCPChaosWebhookLog.Info("validate create", "name", in.Name)
   707  	return in.Validate()
   708  }
   709  
   710  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
   711  func (in *GCPChaos) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
   712  	GCPChaosWebhookLog.Info("validate update", "name", in.Name)
   713  	if !reflect.DeepEqual(in.Spec, old.(*GCPChaos).Spec) {
   714  		return nil, ErrCanNotUpdateChaos
   715  	}
   716  	return in.Validate()
   717  }
   718  
   719  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
   720  func (in *GCPChaos) ValidateDelete() (admission.Warnings, error) {
   721  	GCPChaosWebhookLog.Info("validate delete", "name", in.Name)
   722  
   723  	// Nothing to do?
   724  	return nil, nil
   725  }
   726  
   727  var _ webhook.Validator = &GCPChaos{}
   728  
   729  func (in *GCPChaos) Validate() ([]string, error) {
   730  	errs := gw.Validate(in)
   731  	return nil, gw.Aggregate(errs)
   732  }
   733  
   734  var _ webhook.Defaulter = &GCPChaos{}
   735  
   736  func (in *GCPChaos) Default() {
   737  	gw.Default(in)
   738  }
   739  
   740  const KindHTTPChaos = "HTTPChaos"
   741  
   742  // IsDeleted returns whether this resource has been deleted
   743  func (in *HTTPChaos) IsDeleted() bool {
   744  	return !in.DeletionTimestamp.IsZero()
   745  }
   746  
   747  // IsPaused returns whether this resource has been paused
   748  func (in *HTTPChaos) IsPaused() bool {
   749  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
   750  		return false
   751  	}
   752  	return true
   753  }
   754  
   755  // GetObjectMeta would return the ObjectMeta for chaos
   756  func (in *HTTPChaos) GetObjectMeta() *metav1.ObjectMeta {
   757  	return &in.ObjectMeta
   758  }
   759  
   760  // GetDuration would return the duration for chaos
   761  func (in *HTTPChaosSpec) GetDuration() (*time.Duration, error) {
   762  	if in.Duration == nil {
   763  		return nil, nil
   764  	}
   765  	duration, err := time.ParseDuration(string(*in.Duration))
   766  	if err != nil {
   767  		return nil, err
   768  	}
   769  	return &duration, nil
   770  }
   771  
   772  // GetStatus returns the status
   773  func (in *HTTPChaos) GetStatus() *ChaosStatus {
   774  	return &in.Status.ChaosStatus
   775  }
   776  
   777  // GetRemoteCluster returns the remoteCluster
   778  func (in *HTTPChaos) GetRemoteCluster() string {
   779  	return in.Spec.RemoteCluster
   780  }
   781  
   782  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
   783  func (in *HTTPChaos) GetSpecAndMetaString() (string, error) {
   784  	spec, err := json.Marshal(in.Spec)
   785  	if err != nil {
   786  		return "", err
   787  	}
   788  
   789  	meta := in.ObjectMeta.DeepCopy()
   790  	meta.SetResourceVersion("")
   791  	meta.SetGeneration(0)
   792  
   793  	return string(spec) + meta.String(), nil
   794  }
   795  
   796  // +kubebuilder:object:root=true
   797  
   798  // HTTPChaosList contains a list of HTTPChaos
   799  type HTTPChaosList struct {
   800  	metav1.TypeMeta `json:",inline"`
   801  	metav1.ListMeta `json:"metadata,omitempty"`
   802  	Items           []HTTPChaos `json:"items"`
   803  }
   804  
   805  func (in *HTTPChaosList) DeepCopyList() GenericChaosList {
   806  	return in.DeepCopy()
   807  }
   808  
   809  // ListChaos returns a list of chaos
   810  func (in *HTTPChaosList) ListChaos() []GenericChaos {
   811  	var result []GenericChaos
   812  	for _, item := range in.Items {
   813  		item := item
   814  		result = append(result, &item)
   815  	}
   816  	return result
   817  }
   818  
   819  func (in *HTTPChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
   820  	duration, err := in.Spec.GetDuration()
   821  	if err != nil {
   822  		return false, 0, err
   823  	}
   824  
   825  	if duration != nil {
   826  		stopTime := in.GetCreationTimestamp().Add(*duration)
   827  		if stopTime.Before(now) {
   828  			return true, 0, nil
   829  		}
   830  
   831  		return false, stopTime.Sub(now), nil
   832  	}
   833  
   834  	return false, 0, nil
   835  }
   836  
   837  func (in *HTTPChaos) IsOneShot() bool {
   838  	return false
   839  }
   840  
   841  var HTTPChaosWebhookLog = logf.Log.WithName("HTTPChaos-resource")
   842  
   843  func (in *HTTPChaos) ValidateCreate() (admission.Warnings, error) {
   844  	HTTPChaosWebhookLog.Info("validate create", "name", in.Name)
   845  	return in.Validate()
   846  }
   847  
   848  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
   849  func (in *HTTPChaos) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
   850  	HTTPChaosWebhookLog.Info("validate update", "name", in.Name)
   851  	if !reflect.DeepEqual(in.Spec, old.(*HTTPChaos).Spec) {
   852  		return nil, ErrCanNotUpdateChaos
   853  	}
   854  	return in.Validate()
   855  }
   856  
   857  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
   858  func (in *HTTPChaos) ValidateDelete() (admission.Warnings, error) {
   859  	HTTPChaosWebhookLog.Info("validate delete", "name", in.Name)
   860  
   861  	// Nothing to do?
   862  	return nil, nil
   863  }
   864  
   865  var _ webhook.Validator = &HTTPChaos{}
   866  
   867  func (in *HTTPChaos) Validate() ([]string, error) {
   868  	errs := gw.Validate(in)
   869  	return nil, gw.Aggregate(errs)
   870  }
   871  
   872  var _ webhook.Defaulter = &HTTPChaos{}
   873  
   874  func (in *HTTPChaos) Default() {
   875  	gw.Default(in)
   876  }
   877  
   878  const KindIOChaos = "IOChaos"
   879  
   880  // IsDeleted returns whether this resource has been deleted
   881  func (in *IOChaos) IsDeleted() bool {
   882  	return !in.DeletionTimestamp.IsZero()
   883  }
   884  
   885  // IsPaused returns whether this resource has been paused
   886  func (in *IOChaos) IsPaused() bool {
   887  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
   888  		return false
   889  	}
   890  	return true
   891  }
   892  
   893  // GetObjectMeta would return the ObjectMeta for chaos
   894  func (in *IOChaos) GetObjectMeta() *metav1.ObjectMeta {
   895  	return &in.ObjectMeta
   896  }
   897  
   898  // GetDuration would return the duration for chaos
   899  func (in *IOChaosSpec) GetDuration() (*time.Duration, error) {
   900  	if in.Duration == nil {
   901  		return nil, nil
   902  	}
   903  	duration, err := time.ParseDuration(string(*in.Duration))
   904  	if err != nil {
   905  		return nil, err
   906  	}
   907  	return &duration, nil
   908  }
   909  
   910  // GetStatus returns the status
   911  func (in *IOChaos) GetStatus() *ChaosStatus {
   912  	return &in.Status.ChaosStatus
   913  }
   914  
   915  // GetRemoteCluster returns the remoteCluster
   916  func (in *IOChaos) GetRemoteCluster() string {
   917  	return in.Spec.RemoteCluster
   918  }
   919  
   920  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
   921  func (in *IOChaos) GetSpecAndMetaString() (string, error) {
   922  	spec, err := json.Marshal(in.Spec)
   923  	if err != nil {
   924  		return "", err
   925  	}
   926  
   927  	meta := in.ObjectMeta.DeepCopy()
   928  	meta.SetResourceVersion("")
   929  	meta.SetGeneration(0)
   930  
   931  	return string(spec) + meta.String(), nil
   932  }
   933  
   934  // +kubebuilder:object:root=true
   935  
   936  // IOChaosList contains a list of IOChaos
   937  type IOChaosList struct {
   938  	metav1.TypeMeta `json:",inline"`
   939  	metav1.ListMeta `json:"metadata,omitempty"`
   940  	Items           []IOChaos `json:"items"`
   941  }
   942  
   943  func (in *IOChaosList) DeepCopyList() GenericChaosList {
   944  	return in.DeepCopy()
   945  }
   946  
   947  // ListChaos returns a list of chaos
   948  func (in *IOChaosList) ListChaos() []GenericChaos {
   949  	var result []GenericChaos
   950  	for _, item := range in.Items {
   951  		item := item
   952  		result = append(result, &item)
   953  	}
   954  	return result
   955  }
   956  
   957  func (in *IOChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
   958  	duration, err := in.Spec.GetDuration()
   959  	if err != nil {
   960  		return false, 0, err
   961  	}
   962  
   963  	if duration != nil {
   964  		stopTime := in.GetCreationTimestamp().Add(*duration)
   965  		if stopTime.Before(now) {
   966  			return true, 0, nil
   967  		}
   968  
   969  		return false, stopTime.Sub(now), nil
   970  	}
   971  
   972  	return false, 0, nil
   973  }
   974  
   975  func (in *IOChaos) IsOneShot() bool {
   976  	return false
   977  }
   978  
   979  var IOChaosWebhookLog = logf.Log.WithName("IOChaos-resource")
   980  
   981  func (in *IOChaos) ValidateCreate() (admission.Warnings, error) {
   982  	IOChaosWebhookLog.Info("validate create", "name", in.Name)
   983  	return in.Validate()
   984  }
   985  
   986  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
   987  func (in *IOChaos) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
   988  	IOChaosWebhookLog.Info("validate update", "name", in.Name)
   989  	if !reflect.DeepEqual(in.Spec, old.(*IOChaos).Spec) {
   990  		return nil, ErrCanNotUpdateChaos
   991  	}
   992  	return in.Validate()
   993  }
   994  
   995  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
   996  func (in *IOChaos) ValidateDelete() (admission.Warnings, error) {
   997  	IOChaosWebhookLog.Info("validate delete", "name", in.Name)
   998  
   999  	// Nothing to do?
  1000  	return nil, nil
  1001  }
  1002  
  1003  var _ webhook.Validator = &IOChaos{}
  1004  
  1005  func (in *IOChaos) Validate() ([]string, error) {
  1006  	errs := gw.Validate(in)
  1007  	return nil, gw.Aggregate(errs)
  1008  }
  1009  
  1010  var _ webhook.Defaulter = &IOChaos{}
  1011  
  1012  func (in *IOChaos) Default() {
  1013  	gw.Default(in)
  1014  }
  1015  
  1016  const KindJVMChaos = "JVMChaos"
  1017  
  1018  // IsDeleted returns whether this resource has been deleted
  1019  func (in *JVMChaos) IsDeleted() bool {
  1020  	return !in.DeletionTimestamp.IsZero()
  1021  }
  1022  
  1023  // IsPaused returns whether this resource has been paused
  1024  func (in *JVMChaos) IsPaused() bool {
  1025  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
  1026  		return false
  1027  	}
  1028  	return true
  1029  }
  1030  
  1031  // GetObjectMeta would return the ObjectMeta for chaos
  1032  func (in *JVMChaos) GetObjectMeta() *metav1.ObjectMeta {
  1033  	return &in.ObjectMeta
  1034  }
  1035  
  1036  // GetDuration would return the duration for chaos
  1037  func (in *JVMChaosSpec) GetDuration() (*time.Duration, error) {
  1038  	if in.Duration == nil {
  1039  		return nil, nil
  1040  	}
  1041  	duration, err := time.ParseDuration(string(*in.Duration))
  1042  	if err != nil {
  1043  		return nil, err
  1044  	}
  1045  	return &duration, nil
  1046  }
  1047  
  1048  // GetStatus returns the status
  1049  func (in *JVMChaos) GetStatus() *ChaosStatus {
  1050  	return &in.Status.ChaosStatus
  1051  }
  1052  
  1053  // GetRemoteCluster returns the remoteCluster
  1054  func (in *JVMChaos) GetRemoteCluster() string {
  1055  	return in.Spec.RemoteCluster
  1056  }
  1057  
  1058  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
  1059  func (in *JVMChaos) GetSpecAndMetaString() (string, error) {
  1060  	spec, err := json.Marshal(in.Spec)
  1061  	if err != nil {
  1062  		return "", err
  1063  	}
  1064  
  1065  	meta := in.ObjectMeta.DeepCopy()
  1066  	meta.SetResourceVersion("")
  1067  	meta.SetGeneration(0)
  1068  
  1069  	return string(spec) + meta.String(), nil
  1070  }
  1071  
  1072  // +kubebuilder:object:root=true
  1073  
  1074  // JVMChaosList contains a list of JVMChaos
  1075  type JVMChaosList struct {
  1076  	metav1.TypeMeta `json:",inline"`
  1077  	metav1.ListMeta `json:"metadata,omitempty"`
  1078  	Items           []JVMChaos `json:"items"`
  1079  }
  1080  
  1081  func (in *JVMChaosList) DeepCopyList() GenericChaosList {
  1082  	return in.DeepCopy()
  1083  }
  1084  
  1085  // ListChaos returns a list of chaos
  1086  func (in *JVMChaosList) ListChaos() []GenericChaos {
  1087  	var result []GenericChaos
  1088  	for _, item := range in.Items {
  1089  		item := item
  1090  		result = append(result, &item)
  1091  	}
  1092  	return result
  1093  }
  1094  
  1095  func (in *JVMChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
  1096  	duration, err := in.Spec.GetDuration()
  1097  	if err != nil {
  1098  		return false, 0, err
  1099  	}
  1100  
  1101  	if duration != nil {
  1102  		stopTime := in.GetCreationTimestamp().Add(*duration)
  1103  		if stopTime.Before(now) {
  1104  			return true, 0, nil
  1105  		}
  1106  
  1107  		return false, stopTime.Sub(now), nil
  1108  	}
  1109  
  1110  	return false, 0, nil
  1111  }
  1112  
  1113  func (in *JVMChaos) IsOneShot() bool {
  1114  	return false
  1115  }
  1116  
  1117  var JVMChaosWebhookLog = logf.Log.WithName("JVMChaos-resource")
  1118  
  1119  func (in *JVMChaos) ValidateCreate() (admission.Warnings, error) {
  1120  	JVMChaosWebhookLog.Info("validate create", "name", in.Name)
  1121  	return in.Validate()
  1122  }
  1123  
  1124  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
  1125  func (in *JVMChaos) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
  1126  	JVMChaosWebhookLog.Info("validate update", "name", in.Name)
  1127  	if !reflect.DeepEqual(in.Spec, old.(*JVMChaos).Spec) {
  1128  		return nil, ErrCanNotUpdateChaos
  1129  	}
  1130  	return in.Validate()
  1131  }
  1132  
  1133  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
  1134  func (in *JVMChaos) ValidateDelete() (admission.Warnings, error) {
  1135  	JVMChaosWebhookLog.Info("validate delete", "name", in.Name)
  1136  
  1137  	// Nothing to do?
  1138  	return nil, nil
  1139  }
  1140  
  1141  var _ webhook.Validator = &JVMChaos{}
  1142  
  1143  func (in *JVMChaos) Validate() ([]string, error) {
  1144  	errs := gw.Validate(in)
  1145  	return nil, gw.Aggregate(errs)
  1146  }
  1147  
  1148  var _ webhook.Defaulter = &JVMChaos{}
  1149  
  1150  func (in *JVMChaos) Default() {
  1151  	gw.Default(in)
  1152  }
  1153  
  1154  const KindKernelChaos = "KernelChaos"
  1155  
  1156  // IsDeleted returns whether this resource has been deleted
  1157  func (in *KernelChaos) IsDeleted() bool {
  1158  	return !in.DeletionTimestamp.IsZero()
  1159  }
  1160  
  1161  // IsPaused returns whether this resource has been paused
  1162  func (in *KernelChaos) IsPaused() bool {
  1163  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
  1164  		return false
  1165  	}
  1166  	return true
  1167  }
  1168  
  1169  // GetObjectMeta would return the ObjectMeta for chaos
  1170  func (in *KernelChaos) GetObjectMeta() *metav1.ObjectMeta {
  1171  	return &in.ObjectMeta
  1172  }
  1173  
  1174  // GetDuration would return the duration for chaos
  1175  func (in *KernelChaosSpec) GetDuration() (*time.Duration, error) {
  1176  	if in.Duration == nil {
  1177  		return nil, nil
  1178  	}
  1179  	duration, err := time.ParseDuration(string(*in.Duration))
  1180  	if err != nil {
  1181  		return nil, err
  1182  	}
  1183  	return &duration, nil
  1184  }
  1185  
  1186  // GetStatus returns the status
  1187  func (in *KernelChaos) GetStatus() *ChaosStatus {
  1188  	return &in.Status.ChaosStatus
  1189  }
  1190  
  1191  // GetRemoteCluster returns the remoteCluster
  1192  func (in *KernelChaos) GetRemoteCluster() string {
  1193  	return in.Spec.RemoteCluster
  1194  }
  1195  
  1196  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
  1197  func (in *KernelChaos) GetSpecAndMetaString() (string, error) {
  1198  	spec, err := json.Marshal(in.Spec)
  1199  	if err != nil {
  1200  		return "", err
  1201  	}
  1202  
  1203  	meta := in.ObjectMeta.DeepCopy()
  1204  	meta.SetResourceVersion("")
  1205  	meta.SetGeneration(0)
  1206  
  1207  	return string(spec) + meta.String(), nil
  1208  }
  1209  
  1210  // +kubebuilder:object:root=true
  1211  
  1212  // KernelChaosList contains a list of KernelChaos
  1213  type KernelChaosList struct {
  1214  	metav1.TypeMeta `json:",inline"`
  1215  	metav1.ListMeta `json:"metadata,omitempty"`
  1216  	Items           []KernelChaos `json:"items"`
  1217  }
  1218  
  1219  func (in *KernelChaosList) DeepCopyList() GenericChaosList {
  1220  	return in.DeepCopy()
  1221  }
  1222  
  1223  // ListChaos returns a list of chaos
  1224  func (in *KernelChaosList) ListChaos() []GenericChaos {
  1225  	var result []GenericChaos
  1226  	for _, item := range in.Items {
  1227  		item := item
  1228  		result = append(result, &item)
  1229  	}
  1230  	return result
  1231  }
  1232  
  1233  func (in *KernelChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
  1234  	duration, err := in.Spec.GetDuration()
  1235  	if err != nil {
  1236  		return false, 0, err
  1237  	}
  1238  
  1239  	if duration != nil {
  1240  		stopTime := in.GetCreationTimestamp().Add(*duration)
  1241  		if stopTime.Before(now) {
  1242  			return true, 0, nil
  1243  		}
  1244  
  1245  		return false, stopTime.Sub(now), nil
  1246  	}
  1247  
  1248  	return false, 0, nil
  1249  }
  1250  
  1251  func (in *KernelChaos) IsOneShot() bool {
  1252  	return false
  1253  }
  1254  
  1255  var KernelChaosWebhookLog = logf.Log.WithName("KernelChaos-resource")
  1256  
  1257  func (in *KernelChaos) ValidateCreate() (admission.Warnings, error) {
  1258  	KernelChaosWebhookLog.Info("validate create", "name", in.Name)
  1259  	return in.Validate()
  1260  }
  1261  
  1262  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
  1263  func (in *KernelChaos) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
  1264  	KernelChaosWebhookLog.Info("validate update", "name", in.Name)
  1265  	if !reflect.DeepEqual(in.Spec, old.(*KernelChaos).Spec) {
  1266  		return nil, ErrCanNotUpdateChaos
  1267  	}
  1268  	return in.Validate()
  1269  }
  1270  
  1271  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
  1272  func (in *KernelChaos) ValidateDelete() (admission.Warnings, error) {
  1273  	KernelChaosWebhookLog.Info("validate delete", "name", in.Name)
  1274  
  1275  	// Nothing to do?
  1276  	return nil, nil
  1277  }
  1278  
  1279  var _ webhook.Validator = &KernelChaos{}
  1280  
  1281  func (in *KernelChaos) Validate() ([]string, error) {
  1282  	errs := gw.Validate(in)
  1283  	return nil, gw.Aggregate(errs)
  1284  }
  1285  
  1286  var _ webhook.Defaulter = &KernelChaos{}
  1287  
  1288  func (in *KernelChaos) Default() {
  1289  	gw.Default(in)
  1290  }
  1291  
  1292  const KindNetworkChaos = "NetworkChaos"
  1293  
  1294  // IsDeleted returns whether this resource has been deleted
  1295  func (in *NetworkChaos) IsDeleted() bool {
  1296  	return !in.DeletionTimestamp.IsZero()
  1297  }
  1298  
  1299  // IsPaused returns whether this resource has been paused
  1300  func (in *NetworkChaos) IsPaused() bool {
  1301  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
  1302  		return false
  1303  	}
  1304  	return true
  1305  }
  1306  
  1307  // GetObjectMeta would return the ObjectMeta for chaos
  1308  func (in *NetworkChaos) GetObjectMeta() *metav1.ObjectMeta {
  1309  	return &in.ObjectMeta
  1310  }
  1311  
  1312  // GetDuration would return the duration for chaos
  1313  func (in *NetworkChaosSpec) GetDuration() (*time.Duration, error) {
  1314  	if in.Duration == nil {
  1315  		return nil, nil
  1316  	}
  1317  	duration, err := time.ParseDuration(string(*in.Duration))
  1318  	if err != nil {
  1319  		return nil, err
  1320  	}
  1321  	return &duration, nil
  1322  }
  1323  
  1324  // GetStatus returns the status
  1325  func (in *NetworkChaos) GetStatus() *ChaosStatus {
  1326  	return &in.Status.ChaosStatus
  1327  }
  1328  
  1329  // GetRemoteCluster returns the remoteCluster
  1330  func (in *NetworkChaos) GetRemoteCluster() string {
  1331  	return in.Spec.RemoteCluster
  1332  }
  1333  
  1334  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
  1335  func (in *NetworkChaos) GetSpecAndMetaString() (string, error) {
  1336  	spec, err := json.Marshal(in.Spec)
  1337  	if err != nil {
  1338  		return "", err
  1339  	}
  1340  
  1341  	meta := in.ObjectMeta.DeepCopy()
  1342  	meta.SetResourceVersion("")
  1343  	meta.SetGeneration(0)
  1344  
  1345  	return string(spec) + meta.String(), nil
  1346  }
  1347  
  1348  // +kubebuilder:object:root=true
  1349  
  1350  // NetworkChaosList contains a list of NetworkChaos
  1351  type NetworkChaosList struct {
  1352  	metav1.TypeMeta `json:",inline"`
  1353  	metav1.ListMeta `json:"metadata,omitempty"`
  1354  	Items           []NetworkChaos `json:"items"`
  1355  }
  1356  
  1357  func (in *NetworkChaosList) DeepCopyList() GenericChaosList {
  1358  	return in.DeepCopy()
  1359  }
  1360  
  1361  // ListChaos returns a list of chaos
  1362  func (in *NetworkChaosList) ListChaos() []GenericChaos {
  1363  	var result []GenericChaos
  1364  	for _, item := range in.Items {
  1365  		item := item
  1366  		result = append(result, &item)
  1367  	}
  1368  	return result
  1369  }
  1370  
  1371  func (in *NetworkChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
  1372  	duration, err := in.Spec.GetDuration()
  1373  	if err != nil {
  1374  		return false, 0, err
  1375  	}
  1376  
  1377  	if duration != nil {
  1378  		stopTime := in.GetCreationTimestamp().Add(*duration)
  1379  		if stopTime.Before(now) {
  1380  			return true, 0, nil
  1381  		}
  1382  
  1383  		return false, stopTime.Sub(now), nil
  1384  	}
  1385  
  1386  	return false, 0, nil
  1387  }
  1388  
  1389  func (in *NetworkChaos) IsOneShot() bool {
  1390  	return false
  1391  }
  1392  
  1393  var NetworkChaosWebhookLog = logf.Log.WithName("NetworkChaos-resource")
  1394  
  1395  func (in *NetworkChaos) ValidateCreate() (admission.Warnings, error) {
  1396  	NetworkChaosWebhookLog.Info("validate create", "name", in.Name)
  1397  	return in.Validate()
  1398  }
  1399  
  1400  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
  1401  func (in *NetworkChaos) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
  1402  	NetworkChaosWebhookLog.Info("validate update", "name", in.Name)
  1403  	if !reflect.DeepEqual(in.Spec, old.(*NetworkChaos).Spec) {
  1404  		return nil, ErrCanNotUpdateChaos
  1405  	}
  1406  	return in.Validate()
  1407  }
  1408  
  1409  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
  1410  func (in *NetworkChaos) ValidateDelete() (admission.Warnings, error) {
  1411  	NetworkChaosWebhookLog.Info("validate delete", "name", in.Name)
  1412  
  1413  	// Nothing to do?
  1414  	return nil, nil
  1415  }
  1416  
  1417  var _ webhook.Validator = &NetworkChaos{}
  1418  
  1419  func (in *NetworkChaos) Validate() ([]string, error) {
  1420  	errs := gw.Validate(in)
  1421  	return nil, gw.Aggregate(errs)
  1422  }
  1423  
  1424  var _ webhook.Defaulter = &NetworkChaos{}
  1425  
  1426  func (in *NetworkChaos) Default() {
  1427  	gw.Default(in)
  1428  }
  1429  
  1430  const KindPhysicalMachineChaos = "PhysicalMachineChaos"
  1431  
  1432  // IsDeleted returns whether this resource has been deleted
  1433  func (in *PhysicalMachineChaos) IsDeleted() bool {
  1434  	return !in.DeletionTimestamp.IsZero()
  1435  }
  1436  
  1437  // IsPaused returns whether this resource has been paused
  1438  func (in *PhysicalMachineChaos) IsPaused() bool {
  1439  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
  1440  		return false
  1441  	}
  1442  	return true
  1443  }
  1444  
  1445  // GetObjectMeta would return the ObjectMeta for chaos
  1446  func (in *PhysicalMachineChaos) GetObjectMeta() *metav1.ObjectMeta {
  1447  	return &in.ObjectMeta
  1448  }
  1449  
  1450  // GetDuration would return the duration for chaos
  1451  func (in *PhysicalMachineChaosSpec) GetDuration() (*time.Duration, error) {
  1452  	if in.Duration == nil {
  1453  		return nil, nil
  1454  	}
  1455  	duration, err := time.ParseDuration(string(*in.Duration))
  1456  	if err != nil {
  1457  		return nil, err
  1458  	}
  1459  	return &duration, nil
  1460  }
  1461  
  1462  // GetStatus returns the status
  1463  func (in *PhysicalMachineChaos) GetStatus() *ChaosStatus {
  1464  	return &in.Status.ChaosStatus
  1465  }
  1466  
  1467  // GetRemoteCluster returns the remoteCluster
  1468  func (in *PhysicalMachineChaos) GetRemoteCluster() string {
  1469  	return in.Spec.RemoteCluster
  1470  }
  1471  
  1472  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
  1473  func (in *PhysicalMachineChaos) GetSpecAndMetaString() (string, error) {
  1474  	spec, err := json.Marshal(in.Spec)
  1475  	if err != nil {
  1476  		return "", err
  1477  	}
  1478  
  1479  	meta := in.ObjectMeta.DeepCopy()
  1480  	meta.SetResourceVersion("")
  1481  	meta.SetGeneration(0)
  1482  
  1483  	return string(spec) + meta.String(), nil
  1484  }
  1485  
  1486  // +kubebuilder:object:root=true
  1487  
  1488  // PhysicalMachineChaosList contains a list of PhysicalMachineChaos
  1489  type PhysicalMachineChaosList struct {
  1490  	metav1.TypeMeta `json:",inline"`
  1491  	metav1.ListMeta `json:"metadata,omitempty"`
  1492  	Items           []PhysicalMachineChaos `json:"items"`
  1493  }
  1494  
  1495  func (in *PhysicalMachineChaosList) DeepCopyList() GenericChaosList {
  1496  	return in.DeepCopy()
  1497  }
  1498  
  1499  // ListChaos returns a list of chaos
  1500  func (in *PhysicalMachineChaosList) ListChaos() []GenericChaos {
  1501  	var result []GenericChaos
  1502  	for _, item := range in.Items {
  1503  		item := item
  1504  		result = append(result, &item)
  1505  	}
  1506  	return result
  1507  }
  1508  
  1509  func (in *PhysicalMachineChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
  1510  	duration, err := in.Spec.GetDuration()
  1511  	if err != nil {
  1512  		return false, 0, err
  1513  	}
  1514  
  1515  	if duration != nil {
  1516  		stopTime := in.GetCreationTimestamp().Add(*duration)
  1517  		if stopTime.Before(now) {
  1518  			return true, 0, nil
  1519  		}
  1520  
  1521  		return false, stopTime.Sub(now), nil
  1522  	}
  1523  
  1524  	return false, 0, nil
  1525  }
  1526  
  1527  func (in *PhysicalMachineChaos) IsOneShot() bool {
  1528  	return false
  1529  }
  1530  
  1531  var PhysicalMachineChaosWebhookLog = logf.Log.WithName("PhysicalMachineChaos-resource")
  1532  
  1533  func (in *PhysicalMachineChaos) ValidateCreate() (admission.Warnings, error) {
  1534  	PhysicalMachineChaosWebhookLog.Info("validate create", "name", in.Name)
  1535  	return in.Validate()
  1536  }
  1537  
  1538  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
  1539  func (in *PhysicalMachineChaos) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
  1540  	PhysicalMachineChaosWebhookLog.Info("validate update", "name", in.Name)
  1541  	if !reflect.DeepEqual(in.Spec, old.(*PhysicalMachineChaos).Spec) {
  1542  		return nil, ErrCanNotUpdateChaos
  1543  	}
  1544  	return in.Validate()
  1545  }
  1546  
  1547  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
  1548  func (in *PhysicalMachineChaos) ValidateDelete() (admission.Warnings, error) {
  1549  	PhysicalMachineChaosWebhookLog.Info("validate delete", "name", in.Name)
  1550  
  1551  	// Nothing to do?
  1552  	return nil, nil
  1553  }
  1554  
  1555  var _ webhook.Validator = &PhysicalMachineChaos{}
  1556  
  1557  func (in *PhysicalMachineChaos) Validate() ([]string, error) {
  1558  	errs := gw.Validate(in)
  1559  	return nil, gw.Aggregate(errs)
  1560  }
  1561  
  1562  var _ webhook.Defaulter = &PhysicalMachineChaos{}
  1563  
  1564  func (in *PhysicalMachineChaos) Default() {
  1565  	gw.Default(in)
  1566  }
  1567  
  1568  const KindPhysicalMachine = "PhysicalMachine"
  1569  
  1570  var PhysicalMachineWebhookLog = logf.Log.WithName("PhysicalMachine-resource")
  1571  
  1572  func (in *PhysicalMachine) ValidateCreate() (admission.Warnings, error) {
  1573  	PhysicalMachineWebhookLog.Info("validate create", "name", in.Name)
  1574  	return in.Validate()
  1575  }
  1576  
  1577  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
  1578  func (in *PhysicalMachine) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
  1579  	PhysicalMachineWebhookLog.Info("validate update", "name", in.Name)
  1580  	if !reflect.DeepEqual(in.Spec, old.(*PhysicalMachine).Spec) {
  1581  		return nil, ErrCanNotUpdateChaos
  1582  	}
  1583  	return in.Validate()
  1584  }
  1585  
  1586  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
  1587  func (in *PhysicalMachine) ValidateDelete() (admission.Warnings, error) {
  1588  	PhysicalMachineWebhookLog.Info("validate delete", "name", in.Name)
  1589  
  1590  	// Nothing to do?
  1591  	return nil, nil
  1592  }
  1593  
  1594  var _ webhook.Validator = &PhysicalMachine{}
  1595  
  1596  func (in *PhysicalMachine) Validate() ([]string, error) {
  1597  	errs := gw.Validate(in)
  1598  	return nil, gw.Aggregate(errs)
  1599  }
  1600  
  1601  var _ webhook.Defaulter = &PhysicalMachine{}
  1602  
  1603  func (in *PhysicalMachine) Default() {
  1604  	gw.Default(in)
  1605  }
  1606  
  1607  const KindPodChaos = "PodChaos"
  1608  
  1609  // IsDeleted returns whether this resource has been deleted
  1610  func (in *PodChaos) IsDeleted() bool {
  1611  	return !in.DeletionTimestamp.IsZero()
  1612  }
  1613  
  1614  // IsPaused returns whether this resource has been paused
  1615  func (in *PodChaos) IsPaused() bool {
  1616  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
  1617  		return false
  1618  	}
  1619  	return true
  1620  }
  1621  
  1622  // GetObjectMeta would return the ObjectMeta for chaos
  1623  func (in *PodChaos) GetObjectMeta() *metav1.ObjectMeta {
  1624  	return &in.ObjectMeta
  1625  }
  1626  
  1627  // GetDuration would return the duration for chaos
  1628  func (in *PodChaosSpec) GetDuration() (*time.Duration, error) {
  1629  	if in.Duration == nil {
  1630  		return nil, nil
  1631  	}
  1632  	duration, err := time.ParseDuration(string(*in.Duration))
  1633  	if err != nil {
  1634  		return nil, err
  1635  	}
  1636  	return &duration, nil
  1637  }
  1638  
  1639  // GetStatus returns the status
  1640  func (in *PodChaos) GetStatus() *ChaosStatus {
  1641  	return &in.Status.ChaosStatus
  1642  }
  1643  
  1644  // GetRemoteCluster returns the remoteCluster
  1645  func (in *PodChaos) GetRemoteCluster() string {
  1646  	return in.Spec.RemoteCluster
  1647  }
  1648  
  1649  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
  1650  func (in *PodChaos) GetSpecAndMetaString() (string, error) {
  1651  	spec, err := json.Marshal(in.Spec)
  1652  	if err != nil {
  1653  		return "", err
  1654  	}
  1655  
  1656  	meta := in.ObjectMeta.DeepCopy()
  1657  	meta.SetResourceVersion("")
  1658  	meta.SetGeneration(0)
  1659  
  1660  	return string(spec) + meta.String(), nil
  1661  }
  1662  
  1663  // +kubebuilder:object:root=true
  1664  
  1665  // PodChaosList contains a list of PodChaos
  1666  type PodChaosList struct {
  1667  	metav1.TypeMeta `json:",inline"`
  1668  	metav1.ListMeta `json:"metadata,omitempty"`
  1669  	Items           []PodChaos `json:"items"`
  1670  }
  1671  
  1672  func (in *PodChaosList) DeepCopyList() GenericChaosList {
  1673  	return in.DeepCopy()
  1674  }
  1675  
  1676  // ListChaos returns a list of chaos
  1677  func (in *PodChaosList) ListChaos() []GenericChaos {
  1678  	var result []GenericChaos
  1679  	for _, item := range in.Items {
  1680  		item := item
  1681  		result = append(result, &item)
  1682  	}
  1683  	return result
  1684  }
  1685  
  1686  func (in *PodChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
  1687  	duration, err := in.Spec.GetDuration()
  1688  	if err != nil {
  1689  		return false, 0, err
  1690  	}
  1691  
  1692  	if duration != nil {
  1693  		stopTime := in.GetCreationTimestamp().Add(*duration)
  1694  		if stopTime.Before(now) {
  1695  			return true, 0, nil
  1696  		}
  1697  
  1698  		return false, stopTime.Sub(now), nil
  1699  	}
  1700  
  1701  	return false, 0, nil
  1702  }
  1703  
  1704  func (in *PodChaos) IsOneShot() bool {
  1705  	if in.Spec.Action==PodKillAction || in.Spec.Action==ContainerKillAction {
  1706  		return true
  1707  	}
  1708  
  1709  	return false
  1710  }
  1711  
  1712  var PodChaosWebhookLog = logf.Log.WithName("PodChaos-resource")
  1713  
  1714  func (in *PodChaos) ValidateCreate() (admission.Warnings, error) {
  1715  	PodChaosWebhookLog.Info("validate create", "name", in.Name)
  1716  	return in.Validate()
  1717  }
  1718  
  1719  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
  1720  func (in *PodChaos) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
  1721  	PodChaosWebhookLog.Info("validate update", "name", in.Name)
  1722  	if !reflect.DeepEqual(in.Spec, old.(*PodChaos).Spec) {
  1723  		return nil, ErrCanNotUpdateChaos
  1724  	}
  1725  	return in.Validate()
  1726  }
  1727  
  1728  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
  1729  func (in *PodChaos) ValidateDelete() (admission.Warnings, error) {
  1730  	PodChaosWebhookLog.Info("validate delete", "name", in.Name)
  1731  
  1732  	// Nothing to do?
  1733  	return nil, nil
  1734  }
  1735  
  1736  var _ webhook.Validator = &PodChaos{}
  1737  
  1738  func (in *PodChaos) Validate() ([]string, error) {
  1739  	errs := gw.Validate(in)
  1740  	return nil, gw.Aggregate(errs)
  1741  }
  1742  
  1743  var _ webhook.Defaulter = &PodChaos{}
  1744  
  1745  func (in *PodChaos) Default() {
  1746  	gw.Default(in)
  1747  }
  1748  
  1749  const KindPodHttpChaos = "PodHttpChaos"
  1750  
  1751  var PodHttpChaosWebhookLog = logf.Log.WithName("PodHttpChaos-resource")
  1752  
  1753  func (in *PodHttpChaos) ValidateCreate() (admission.Warnings, error) {
  1754  	PodHttpChaosWebhookLog.Info("validate create", "name", in.Name)
  1755  	return in.Validate()
  1756  }
  1757  
  1758  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
  1759  func (in *PodHttpChaos) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
  1760  	PodHttpChaosWebhookLog.Info("validate update", "name", in.Name)
  1761  	return in.Validate()
  1762  }
  1763  
  1764  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
  1765  func (in *PodHttpChaos) ValidateDelete() (admission.Warnings, error) {
  1766  	PodHttpChaosWebhookLog.Info("validate delete", "name", in.Name)
  1767  
  1768  	// Nothing to do?
  1769  	return nil, nil
  1770  }
  1771  
  1772  var _ webhook.Validator = &PodHttpChaos{}
  1773  
  1774  func (in *PodHttpChaos) Validate() ([]string, error) {
  1775  	errs := gw.Validate(in)
  1776  	return nil, gw.Aggregate(errs)
  1777  }
  1778  
  1779  var _ webhook.Defaulter = &PodHttpChaos{}
  1780  
  1781  func (in *PodHttpChaos) Default() {
  1782  	gw.Default(in)
  1783  }
  1784  
  1785  const KindPodIOChaos = "PodIOChaos"
  1786  
  1787  var PodIOChaosWebhookLog = logf.Log.WithName("PodIOChaos-resource")
  1788  
  1789  func (in *PodIOChaos) ValidateCreate() (admission.Warnings, error) {
  1790  	PodIOChaosWebhookLog.Info("validate create", "name", in.Name)
  1791  	return in.Validate()
  1792  }
  1793  
  1794  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
  1795  func (in *PodIOChaos) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
  1796  	PodIOChaosWebhookLog.Info("validate update", "name", in.Name)
  1797  	return in.Validate()
  1798  }
  1799  
  1800  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
  1801  func (in *PodIOChaos) ValidateDelete() (admission.Warnings, error) {
  1802  	PodIOChaosWebhookLog.Info("validate delete", "name", in.Name)
  1803  
  1804  	// Nothing to do?
  1805  	return nil, nil
  1806  }
  1807  
  1808  var _ webhook.Validator = &PodIOChaos{}
  1809  
  1810  func (in *PodIOChaos) Validate() ([]string, error) {
  1811  	errs := gw.Validate(in)
  1812  	return nil, gw.Aggregate(errs)
  1813  }
  1814  
  1815  var _ webhook.Defaulter = &PodIOChaos{}
  1816  
  1817  func (in *PodIOChaos) Default() {
  1818  	gw.Default(in)
  1819  }
  1820  
  1821  const KindPodNetworkChaos = "PodNetworkChaos"
  1822  
  1823  var PodNetworkChaosWebhookLog = logf.Log.WithName("PodNetworkChaos-resource")
  1824  
  1825  func (in *PodNetworkChaos) ValidateCreate() (admission.Warnings, error) {
  1826  	PodNetworkChaosWebhookLog.Info("validate create", "name", in.Name)
  1827  	return in.Validate()
  1828  }
  1829  
  1830  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
  1831  func (in *PodNetworkChaos) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
  1832  	PodNetworkChaosWebhookLog.Info("validate update", "name", in.Name)
  1833  	return in.Validate()
  1834  }
  1835  
  1836  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
  1837  func (in *PodNetworkChaos) ValidateDelete() (admission.Warnings, error) {
  1838  	PodNetworkChaosWebhookLog.Info("validate delete", "name", in.Name)
  1839  
  1840  	// Nothing to do?
  1841  	return nil, nil
  1842  }
  1843  
  1844  var _ webhook.Validator = &PodNetworkChaos{}
  1845  
  1846  func (in *PodNetworkChaos) Validate() ([]string, error) {
  1847  	errs := gw.Validate(in)
  1848  	return nil, gw.Aggregate(errs)
  1849  }
  1850  
  1851  var _ webhook.Defaulter = &PodNetworkChaos{}
  1852  
  1853  func (in *PodNetworkChaos) Default() {
  1854  	gw.Default(in)
  1855  }
  1856  
  1857  const KindRemoteCluster = "RemoteCluster"
  1858  
  1859  var RemoteClusterWebhookLog = logf.Log.WithName("RemoteCluster-resource")
  1860  
  1861  func (in *RemoteCluster) ValidateCreate() (admission.Warnings, error) {
  1862  	RemoteClusterWebhookLog.Info("validate create", "name", in.Name)
  1863  	return in.Validate()
  1864  }
  1865  
  1866  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
  1867  func (in *RemoteCluster) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
  1868  	RemoteClusterWebhookLog.Info("validate update", "name", in.Name)
  1869  	if !reflect.DeepEqual(in.Spec, old.(*RemoteCluster).Spec) {
  1870  		return nil, ErrCanNotUpdateChaos
  1871  	}
  1872  	return in.Validate()
  1873  }
  1874  
  1875  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
  1876  func (in *RemoteCluster) ValidateDelete() (admission.Warnings, error) {
  1877  	RemoteClusterWebhookLog.Info("validate delete", "name", in.Name)
  1878  
  1879  	// Nothing to do?
  1880  	return nil, nil
  1881  }
  1882  
  1883  var _ webhook.Validator = &RemoteCluster{}
  1884  
  1885  func (in *RemoteCluster) Validate() ([]string, error) {
  1886  	errs := gw.Validate(in)
  1887  	return nil, gw.Aggregate(errs)
  1888  }
  1889  
  1890  var _ webhook.Defaulter = &RemoteCluster{}
  1891  
  1892  func (in *RemoteCluster) Default() {
  1893  	gw.Default(in)
  1894  }
  1895  
  1896  const KindStatusCheck = "StatusCheck"
  1897  
  1898  var StatusCheckWebhookLog = logf.Log.WithName("StatusCheck-resource")
  1899  
  1900  func (in *StatusCheck) ValidateCreate() (admission.Warnings, error) {
  1901  	StatusCheckWebhookLog.Info("validate create", "name", in.Name)
  1902  	return in.Validate()
  1903  }
  1904  
  1905  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
  1906  func (in *StatusCheck) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
  1907  	StatusCheckWebhookLog.Info("validate update", "name", in.Name)
  1908  	if !reflect.DeepEqual(in.Spec, old.(*StatusCheck).Spec) {
  1909  		return nil, ErrCanNotUpdateChaos
  1910  	}
  1911  	return in.Validate()
  1912  }
  1913  
  1914  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
  1915  func (in *StatusCheck) ValidateDelete() (admission.Warnings, error) {
  1916  	StatusCheckWebhookLog.Info("validate delete", "name", in.Name)
  1917  
  1918  	// Nothing to do?
  1919  	return nil, nil
  1920  }
  1921  
  1922  var _ webhook.Validator = &StatusCheck{}
  1923  
  1924  func (in *StatusCheck) Validate() ([]string, error) {
  1925  	errs := gw.Validate(in)
  1926  	return nil, gw.Aggregate(errs)
  1927  }
  1928  
  1929  var _ webhook.Defaulter = &StatusCheck{}
  1930  
  1931  func (in *StatusCheck) Default() {
  1932  	gw.Default(in)
  1933  }
  1934  
  1935  const KindStressChaos = "StressChaos"
  1936  
  1937  // IsDeleted returns whether this resource has been deleted
  1938  func (in *StressChaos) IsDeleted() bool {
  1939  	return !in.DeletionTimestamp.IsZero()
  1940  }
  1941  
  1942  // IsPaused returns whether this resource has been paused
  1943  func (in *StressChaos) IsPaused() bool {
  1944  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
  1945  		return false
  1946  	}
  1947  	return true
  1948  }
  1949  
  1950  // GetObjectMeta would return the ObjectMeta for chaos
  1951  func (in *StressChaos) GetObjectMeta() *metav1.ObjectMeta {
  1952  	return &in.ObjectMeta
  1953  }
  1954  
  1955  // GetDuration would return the duration for chaos
  1956  func (in *StressChaosSpec) GetDuration() (*time.Duration, error) {
  1957  	if in.Duration == nil {
  1958  		return nil, nil
  1959  	}
  1960  	duration, err := time.ParseDuration(string(*in.Duration))
  1961  	if err != nil {
  1962  		return nil, err
  1963  	}
  1964  	return &duration, nil
  1965  }
  1966  
  1967  // GetStatus returns the status
  1968  func (in *StressChaos) GetStatus() *ChaosStatus {
  1969  	return &in.Status.ChaosStatus
  1970  }
  1971  
  1972  // GetRemoteCluster returns the remoteCluster
  1973  func (in *StressChaos) GetRemoteCluster() string {
  1974  	return in.Spec.RemoteCluster
  1975  }
  1976  
  1977  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
  1978  func (in *StressChaos) GetSpecAndMetaString() (string, error) {
  1979  	spec, err := json.Marshal(in.Spec)
  1980  	if err != nil {
  1981  		return "", err
  1982  	}
  1983  
  1984  	meta := in.ObjectMeta.DeepCopy()
  1985  	meta.SetResourceVersion("")
  1986  	meta.SetGeneration(0)
  1987  
  1988  	return string(spec) + meta.String(), nil
  1989  }
  1990  
  1991  // +kubebuilder:object:root=true
  1992  
  1993  // StressChaosList contains a list of StressChaos
  1994  type StressChaosList struct {
  1995  	metav1.TypeMeta `json:",inline"`
  1996  	metav1.ListMeta `json:"metadata,omitempty"`
  1997  	Items           []StressChaos `json:"items"`
  1998  }
  1999  
  2000  func (in *StressChaosList) DeepCopyList() GenericChaosList {
  2001  	return in.DeepCopy()
  2002  }
  2003  
  2004  // ListChaos returns a list of chaos
  2005  func (in *StressChaosList) ListChaos() []GenericChaos {
  2006  	var result []GenericChaos
  2007  	for _, item := range in.Items {
  2008  		item := item
  2009  		result = append(result, &item)
  2010  	}
  2011  	return result
  2012  }
  2013  
  2014  func (in *StressChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
  2015  	duration, err := in.Spec.GetDuration()
  2016  	if err != nil {
  2017  		return false, 0, err
  2018  	}
  2019  
  2020  	if duration != nil {
  2021  		stopTime := in.GetCreationTimestamp().Add(*duration)
  2022  		if stopTime.Before(now) {
  2023  			return true, 0, nil
  2024  		}
  2025  
  2026  		return false, stopTime.Sub(now), nil
  2027  	}
  2028  
  2029  	return false, 0, nil
  2030  }
  2031  
  2032  func (in *StressChaos) IsOneShot() bool {
  2033  	return false
  2034  }
  2035  
  2036  var StressChaosWebhookLog = logf.Log.WithName("StressChaos-resource")
  2037  
  2038  func (in *StressChaos) ValidateCreate() (admission.Warnings, error) {
  2039  	StressChaosWebhookLog.Info("validate create", "name", in.Name)
  2040  	return in.Validate()
  2041  }
  2042  
  2043  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
  2044  func (in *StressChaos) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
  2045  	StressChaosWebhookLog.Info("validate update", "name", in.Name)
  2046  	if !reflect.DeepEqual(in.Spec, old.(*StressChaos).Spec) {
  2047  		return nil, ErrCanNotUpdateChaos
  2048  	}
  2049  	return in.Validate()
  2050  }
  2051  
  2052  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
  2053  func (in *StressChaos) ValidateDelete() (admission.Warnings, error) {
  2054  	StressChaosWebhookLog.Info("validate delete", "name", in.Name)
  2055  
  2056  	// Nothing to do?
  2057  	return nil, nil
  2058  }
  2059  
  2060  var _ webhook.Validator = &StressChaos{}
  2061  
  2062  func (in *StressChaos) Validate() ([]string, error) {
  2063  	errs := gw.Validate(in)
  2064  	return nil, gw.Aggregate(errs)
  2065  }
  2066  
  2067  var _ webhook.Defaulter = &StressChaos{}
  2068  
  2069  func (in *StressChaos) Default() {
  2070  	gw.Default(in)
  2071  }
  2072  
  2073  const KindTimeChaos = "TimeChaos"
  2074  
  2075  // IsDeleted returns whether this resource has been deleted
  2076  func (in *TimeChaos) IsDeleted() bool {
  2077  	return !in.DeletionTimestamp.IsZero()
  2078  }
  2079  
  2080  // IsPaused returns whether this resource has been paused
  2081  func (in *TimeChaos) IsPaused() bool {
  2082  	if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
  2083  		return false
  2084  	}
  2085  	return true
  2086  }
  2087  
  2088  // GetObjectMeta would return the ObjectMeta for chaos
  2089  func (in *TimeChaos) GetObjectMeta() *metav1.ObjectMeta {
  2090  	return &in.ObjectMeta
  2091  }
  2092  
  2093  // GetDuration would return the duration for chaos
  2094  func (in *TimeChaosSpec) GetDuration() (*time.Duration, error) {
  2095  	if in.Duration == nil {
  2096  		return nil, nil
  2097  	}
  2098  	duration, err := time.ParseDuration(string(*in.Duration))
  2099  	if err != nil {
  2100  		return nil, err
  2101  	}
  2102  	return &duration, nil
  2103  }
  2104  
  2105  // GetStatus returns the status
  2106  func (in *TimeChaos) GetStatus() *ChaosStatus {
  2107  	return &in.Status.ChaosStatus
  2108  }
  2109  
  2110  // GetRemoteCluster returns the remoteCluster
  2111  func (in *TimeChaos) GetRemoteCluster() string {
  2112  	return in.Spec.RemoteCluster
  2113  }
  2114  
  2115  // GetSpecAndMetaString returns a string including the meta and spec field of this chaos object.
  2116  func (in *TimeChaos) GetSpecAndMetaString() (string, error) {
  2117  	spec, err := json.Marshal(in.Spec)
  2118  	if err != nil {
  2119  		return "", err
  2120  	}
  2121  
  2122  	meta := in.ObjectMeta.DeepCopy()
  2123  	meta.SetResourceVersion("")
  2124  	meta.SetGeneration(0)
  2125  
  2126  	return string(spec) + meta.String(), nil
  2127  }
  2128  
  2129  // +kubebuilder:object:root=true
  2130  
  2131  // TimeChaosList contains a list of TimeChaos
  2132  type TimeChaosList struct {
  2133  	metav1.TypeMeta `json:",inline"`
  2134  	metav1.ListMeta `json:"metadata,omitempty"`
  2135  	Items           []TimeChaos `json:"items"`
  2136  }
  2137  
  2138  func (in *TimeChaosList) DeepCopyList() GenericChaosList {
  2139  	return in.DeepCopy()
  2140  }
  2141  
  2142  // ListChaos returns a list of chaos
  2143  func (in *TimeChaosList) ListChaos() []GenericChaos {
  2144  	var result []GenericChaos
  2145  	for _, item := range in.Items {
  2146  		item := item
  2147  		result = append(result, &item)
  2148  	}
  2149  	return result
  2150  }
  2151  
  2152  func (in *TimeChaos) DurationExceeded(now time.Time) (bool, time.Duration, error) {
  2153  	duration, err := in.Spec.GetDuration()
  2154  	if err != nil {
  2155  		return false, 0, err
  2156  	}
  2157  
  2158  	if duration != nil {
  2159  		stopTime := in.GetCreationTimestamp().Add(*duration)
  2160  		if stopTime.Before(now) {
  2161  			return true, 0, nil
  2162  		}
  2163  
  2164  		return false, stopTime.Sub(now), nil
  2165  	}
  2166  
  2167  	return false, 0, nil
  2168  }
  2169  
  2170  func (in *TimeChaos) IsOneShot() bool {
  2171  	return false
  2172  }
  2173  
  2174  var TimeChaosWebhookLog = logf.Log.WithName("TimeChaos-resource")
  2175  
  2176  func (in *TimeChaos) ValidateCreate() (admission.Warnings, error) {
  2177  	TimeChaosWebhookLog.Info("validate create", "name", in.Name)
  2178  	return in.Validate()
  2179  }
  2180  
  2181  // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
  2182  func (in *TimeChaos) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
  2183  	TimeChaosWebhookLog.Info("validate update", "name", in.Name)
  2184  	if !reflect.DeepEqual(in.Spec, old.(*TimeChaos).Spec) {
  2185  		return nil, ErrCanNotUpdateChaos
  2186  	}
  2187  	return in.Validate()
  2188  }
  2189  
  2190  // ValidateDelete implements webhook.Validator so a webhook will be registered for the type
  2191  func (in *TimeChaos) ValidateDelete() (admission.Warnings, error) {
  2192  	TimeChaosWebhookLog.Info("validate delete", "name", in.Name)
  2193  
  2194  	// Nothing to do?
  2195  	return nil, nil
  2196  }
  2197  
  2198  var _ webhook.Validator = &TimeChaos{}
  2199  
  2200  func (in *TimeChaos) Validate() ([]string, error) {
  2201  	errs := gw.Validate(in)
  2202  	return nil, gw.Aggregate(errs)
  2203  }
  2204  
  2205  var _ webhook.Defaulter = &TimeChaos{}
  2206  
  2207  func (in *TimeChaos) Default() {
  2208  	gw.Default(in)
  2209  }
  2210  
  2211  func init() {
  2212  
  2213  	SchemeBuilder.Register(&AWSChaos{}, &AWSChaosList{})
  2214  	all.register(KindAWSChaos, &ChaosKind{
  2215  		chaos: &AWSChaos{},
  2216  		list:  &AWSChaosList{},
  2217  	})
  2218  
  2219  	SchemeBuilder.Register(&AzureChaos{}, &AzureChaosList{})
  2220  	all.register(KindAzureChaos, &ChaosKind{
  2221  		chaos: &AzureChaos{},
  2222  		list:  &AzureChaosList{},
  2223  	})
  2224  
  2225  	SchemeBuilder.Register(&BlockChaos{}, &BlockChaosList{})
  2226  	all.register(KindBlockChaos, &ChaosKind{
  2227  		chaos: &BlockChaos{},
  2228  		list:  &BlockChaosList{},
  2229  	})
  2230  
  2231  	SchemeBuilder.Register(&DNSChaos{}, &DNSChaosList{})
  2232  	all.register(KindDNSChaos, &ChaosKind{
  2233  		chaos: &DNSChaos{},
  2234  		list:  &DNSChaosList{},
  2235  	})
  2236  
  2237  	SchemeBuilder.Register(&GCPChaos{}, &GCPChaosList{})
  2238  	all.register(KindGCPChaos, &ChaosKind{
  2239  		chaos: &GCPChaos{},
  2240  		list:  &GCPChaosList{},
  2241  	})
  2242  
  2243  	SchemeBuilder.Register(&HTTPChaos{}, &HTTPChaosList{})
  2244  	all.register(KindHTTPChaos, &ChaosKind{
  2245  		chaos: &HTTPChaos{},
  2246  		list:  &HTTPChaosList{},
  2247  	})
  2248  
  2249  	SchemeBuilder.Register(&IOChaos{}, &IOChaosList{})
  2250  	all.register(KindIOChaos, &ChaosKind{
  2251  		chaos: &IOChaos{},
  2252  		list:  &IOChaosList{},
  2253  	})
  2254  
  2255  	SchemeBuilder.Register(&JVMChaos{}, &JVMChaosList{})
  2256  	all.register(KindJVMChaos, &ChaosKind{
  2257  		chaos: &JVMChaos{},
  2258  		list:  &JVMChaosList{},
  2259  	})
  2260  
  2261  	SchemeBuilder.Register(&KernelChaos{}, &KernelChaosList{})
  2262  	all.register(KindKernelChaos, &ChaosKind{
  2263  		chaos: &KernelChaos{},
  2264  		list:  &KernelChaosList{},
  2265  	})
  2266  
  2267  	SchemeBuilder.Register(&NetworkChaos{}, &NetworkChaosList{})
  2268  	all.register(KindNetworkChaos, &ChaosKind{
  2269  		chaos: &NetworkChaos{},
  2270  		list:  &NetworkChaosList{},
  2271  	})
  2272  
  2273  	SchemeBuilder.Register(&PhysicalMachineChaos{}, &PhysicalMachineChaosList{})
  2274  	all.register(KindPhysicalMachineChaos, &ChaosKind{
  2275  		chaos: &PhysicalMachineChaos{},
  2276  		list:  &PhysicalMachineChaosList{},
  2277  	})
  2278  
  2279  	SchemeBuilder.Register(&PhysicalMachine{}, &PhysicalMachineList{})
  2280  
  2281  	SchemeBuilder.Register(&PodChaos{}, &PodChaosList{})
  2282  	all.register(KindPodChaos, &ChaosKind{
  2283  		chaos: &PodChaos{},
  2284  		list:  &PodChaosList{},
  2285  	})
  2286  
  2287  	SchemeBuilder.Register(&PodHttpChaos{}, &PodHttpChaosList{})
  2288  
  2289  	SchemeBuilder.Register(&PodIOChaos{}, &PodIOChaosList{})
  2290  
  2291  	SchemeBuilder.Register(&PodNetworkChaos{}, &PodNetworkChaosList{})
  2292  
  2293  	SchemeBuilder.Register(&RemoteCluster{}, &RemoteClusterList{})
  2294  
  2295  	SchemeBuilder.Register(&StatusCheck{}, &StatusCheckList{})
  2296  
  2297  	SchemeBuilder.Register(&StressChaos{}, &StressChaosList{})
  2298  	all.register(KindStressChaos, &ChaosKind{
  2299  		chaos: &StressChaos{},
  2300  		list:  &StressChaosList{},
  2301  	})
  2302  
  2303  	SchemeBuilder.Register(&TimeChaos{}, &TimeChaosList{})
  2304  	all.register(KindTimeChaos, &ChaosKind{
  2305  		chaos: &TimeChaos{},
  2306  		list:  &TimeChaosList{},
  2307  	})
  2308  
  2309  
  2310  	allScheduleItem.register(KindAWSChaos, &ChaosKind{
  2311  		chaos: &AWSChaos{},
  2312  		list:  &AWSChaosList{},
  2313  	})
  2314  
  2315  	allScheduleItem.register(KindAzureChaos, &ChaosKind{
  2316  		chaos: &AzureChaos{},
  2317  		list:  &AzureChaosList{},
  2318  	})
  2319  
  2320  	allScheduleItem.register(KindBlockChaos, &ChaosKind{
  2321  		chaos: &BlockChaos{},
  2322  		list:  &BlockChaosList{},
  2323  	})
  2324  
  2325  	allScheduleItem.register(KindDNSChaos, &ChaosKind{
  2326  		chaos: &DNSChaos{},
  2327  		list:  &DNSChaosList{},
  2328  	})
  2329  
  2330  	allScheduleItem.register(KindGCPChaos, &ChaosKind{
  2331  		chaos: &GCPChaos{},
  2332  		list:  &GCPChaosList{},
  2333  	})
  2334  
  2335  	allScheduleItem.register(KindHTTPChaos, &ChaosKind{
  2336  		chaos: &HTTPChaos{},
  2337  		list:  &HTTPChaosList{},
  2338  	})
  2339  
  2340  	allScheduleItem.register(KindIOChaos, &ChaosKind{
  2341  		chaos: &IOChaos{},
  2342  		list:  &IOChaosList{},
  2343  	})
  2344  
  2345  	allScheduleItem.register(KindJVMChaos, &ChaosKind{
  2346  		chaos: &JVMChaos{},
  2347  		list:  &JVMChaosList{},
  2348  	})
  2349  
  2350  	allScheduleItem.register(KindKernelChaos, &ChaosKind{
  2351  		chaos: &KernelChaos{},
  2352  		list:  &KernelChaosList{},
  2353  	})
  2354  
  2355  	allScheduleItem.register(KindNetworkChaos, &ChaosKind{
  2356  		chaos: &NetworkChaos{},
  2357  		list:  &NetworkChaosList{},
  2358  	})
  2359  
  2360  	allScheduleItem.register(KindPhysicalMachineChaos, &ChaosKind{
  2361  		chaos: &PhysicalMachineChaos{},
  2362  		list:  &PhysicalMachineChaosList{},
  2363  	})
  2364  
  2365  	allScheduleItem.register(KindPodChaos, &ChaosKind{
  2366  		chaos: &PodChaos{},
  2367  		list:  &PodChaosList{},
  2368  	})
  2369  
  2370  	allScheduleItem.register(KindStressChaos, &ChaosKind{
  2371  		chaos: &StressChaos{},
  2372  		list:  &StressChaosList{},
  2373  	})
  2374  
  2375  	allScheduleItem.register(KindTimeChaos, &ChaosKind{
  2376  		chaos: &TimeChaos{},
  2377  		list:  &TimeChaosList{},
  2378  	})
  2379  
  2380  	allScheduleItem.register(KindWorkflow, &ChaosKind{
  2381  		chaos: &Workflow{},
  2382  		list:  &WorkflowList{},
  2383  	})
  2384  
  2385  }
  2386