Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cilium chaos
Browse files Browse the repository at this point in the history
Basic node isolation chaos implementation using cilium policy injection
grahambrereton-form3 committed Nov 13, 2023
1 parent 4a14670 commit d99e2d0
Showing 41 changed files with 4,717 additions and 98 deletions.
61 changes: 61 additions & 0 deletions api/v1alpha1/ciliumchaos_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2023 Chaos Mesh Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +kubebuilder:object:root=true
// +chaos-mesh:experiment

// CiliumChaos is the control script's spec.
type CiliumChaos struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// Spec defines the behavior of a node chaos experiment
Spec CiliumChaosSpec `json:"spec"`

// +optional
// Most recently observed status of the chaos experiment
Status CiliumChaosStatus `json:"status,omitempty"`
}

var _ InnerObject = (*CiliumChaos)(nil)

// CiliumChaosSpec defines the attributes that a user creates on a chaos experiment affecting cilium CNI.
type CiliumChaosSpec struct {
NodeSelector `json:",inline"`

// Duration represents the duration of the chaos action.
Duration *string `json:"duration" webhook:"Duration"`

// RemoteCluster represents the remote cluster where the chaos will be deployed
// +optional
RemoteCluster string `json:"remoteCluster,omitempty"`
}

// CiliumChaosStatus represents the current status of the chaos experiment about pods.
type CiliumChaosStatus struct {
ChaosStatus `json:",inline"`
}

func (obj *CiliumChaos) GetSelectorSpecs() map[string]interface{} {
return map[string]interface{}{
".": &obj.Spec.NodeSelector,
}
}
43 changes: 43 additions & 0 deletions api/v1alpha1/selector.go
Original file line number Diff line number Diff line change
@@ -135,3 +135,46 @@ func (in PodSelectorSpec) ClusterScoped() bool {

return false
}

type NodeSelector struct {
// Selector is used to select nodes into which to inject chaos.
Selector NodeSelectorSpec `json:"selector"`

// Mode defines the mode to run chaos action.
// Supported mode: one / all / fixed / fixed-percent / random-max-percent
// +kubebuilder:validation:Enum=one;all;fixed;fixed-percent;random-max-percent
Mode SelectorMode `json:"mode"`

// Value is required when the mode is set to `FixedMode` / `FixedPercentMode` / `RandomMaxPercentMode`.
// If `FixedMode`, provide an integer of pods to do chaos action.
// If `FixedPercentMode`, provide a number from 0-100 to specify the percent of pods the server can do chaos action.
// IF `RandomMaxPercentMode`, provide a number from 0-100 to specify the max percent of pods to do chaos action
// +optional
Value string `json:"value,omitempty"`
}

type NodeSelectorSpec struct {
// An array of node names.
// +optional
Names []string `json:"names,omitempty"`

// Map of string keys and values that can be used to select objects.
// A selector based on fields.
// +optional
FieldSelectors map[string]string `json:"fieldSelectors,omitempty"`

// Map of string keys and values that can be used to select objects.
// A selector based on labels.
// +optional
LabelSelectors map[string]string `json:"labelSelectors,omitempty"`

// a slice of label selector expressions that can be used to select objects.
// A list of selectors based on set-based label expressions.
// +optional
ExpressionSelectors LabelSelectorRequirements `json:"expressionSelectors,omitempty" swaggerignore:"true"`

// Map of string keys and values that can be used to select objects.
// A selector based on annotations.
// +optional
AnnotationSelectors map[string]string `json:"annotationSelectors,omitempty"`
}
149 changes: 149 additions & 0 deletions api/v1alpha1/zz_generated.chaosmesh.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions api/v1alpha1/zz_generated.chaosmesh_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d99e2d0

Please sign in to comment.