Skip to content

Commit

Permalink
Merge f3d76c6 into 41a0ff8
Browse files Browse the repository at this point in the history
  • Loading branch information
sshutovskyi-f3 committed Jul 12, 2024
2 parents 41a0ff8 + f3d76c6 commit 688c68e
Show file tree
Hide file tree
Showing 37 changed files with 4,088 additions and 20 deletions.
36 changes: 36 additions & 0 deletions api/v1alpha1/cloudstackapiconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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

type CloudStackAPIConfig struct {
// Address defines the address of the CloudStack instsance.
Address string `json:"address"`

// VerifySSL defines whether certificates should be verified when connecting to the API.
// +optional
VerifySSL bool `json:"verifySSL,omitempty"`

// SecretName defines the name of the secret where the API credentials are stored.
SecretName string `json:"secretName"`

// APIKeyField defines the key under which the value for API key is stored inside the secret.
// +optional
APIKeyField string `json:"apiKeyField,omitempty" default:"api-key"`

// APISecretField defines the key under which the value for API secret is stored inside the secret.
// +optional
APISecretField string `json:"apiSecretField,omitempty" default:"api-secret"`
}
118 changes: 118 additions & 0 deletions api/v1alpha1/cloudstackhostchaos_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// 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 (
"encoding/json"

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

// +kubebuilder:object:root=true
// +kubebuilder:resource:shortName=csh
// +kubebuilder:printcolumn:name="action",type=string,JSONPath=`.spec.action`
// +kubebuilder:printcolumn:name="duration",type=string,JSONPath=`.spec.duration`
// +chaos-mesh:experiment
// +chaos-mesh:oneshot=in.Spec.Action==HostStop

// CloudStackHostChaos is the Schema for the cloudstackchaos API.
type CloudStackHostChaos struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec CloudStackHostChaosSpec `json:"spec"`
Status CloudStackHostChaosStatus `json:"status,omitempty"`
}

var (
_ InnerObjectWithSelector = (*CloudStackHostChaos)(nil)
_ InnerObject = (*CloudStackHostChaos)(nil)
)

// CloudStackHostChaosAction represents the chaos action about cloudstack.
type CloudStackHostChaosAction string

const (
// HostStop represents the chaos action of stopping the host.
HostStop CloudStackHostChaosAction = "host-stop"
)

// CloudStackHostChaosSpec is the content of the specification for a CloudStackChaos.
type CloudStackHostChaosSpec struct {
// APIConfig defines the configuration ncessary to connect to the CloudStack API.
APIConfig CloudStackAPIConfig `json:"apiConfig"`

// Selector defines the parameters that can be used to select target VMs.
Selector CloudStackHostChaosSelector `json:"selector"`

// DryRun defines whether the chaos should run a dry-run mode.
// +optional
DryRun bool `json:"dryRun,omitempty"`

// Action defines the specific cloudstack chaos action.
// Supported action: host-stop
// Default action: host-stop
// +kubebuilder:validation:Enum=host-stop
Action CloudStackHostChaosAction `json:"action"`

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

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

// CloudStackHostChaosStatus represents the status of a CloudStackChaos.
type CloudStackHostChaosStatus struct {
ChaosStatus `json:",inline"`
}

type CloudStackHostChaosSelector struct {
// Hypervisor defines the target hypervisor.
// +optional
Hypervisor *string `json:"hypervisor,omitempty"`

// ID defines the ID of the host.
// +optional
ID *string `json:"id,omitempty"`

// Keyword defines the keyword to list the VMs by.
// +optional
Keyword *string `json:"keyword,omitempty"`

// Name defines the name of the host
// +optiional
Name *string `json:"name,omitempty"`

// ZoneID defines the availability zone the host belongs to.
// +optional
ZoneID *string `json:"zoneId,omitempty"`

// ClusterID defines the cluster the host belongs to.
// +optional
ClusterID *string `json:"clusterId,omitempty"`
}

func (selector *CloudStackHostChaosSelector) Id() string {
v, _ := json.Marshal(selector)
return string(v)
}

func (obj *CloudStackHostChaos) GetSelectorSpecs() map[string]interface{} {
return map[string]interface{}{".": &obj.Spec.Selector}
}
24 changes: 24 additions & 0 deletions api/v1alpha1/cloudstackhostchaos_webhook.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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 (
"reflect"
)

func (in *CloudStackHostChaosSpec) Default(root interface{}, structField *reflect.StructField) {
setDefaultsFromTags(in)
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,6 @@ type CloudStackVMChaosSpec struct {
RemoteCluster string `json:"remoteCluster,omitempty"`
}

type CloudStackAPIConfig struct {
// Address defines the address of the CloudStack instsance.
Address string `json:"address"`

// VerifySSL defines whether certificates should be verified when connecting to the API.
// +optional
VerifySSL bool `json:"verifySSL,omitempty"`

// SecretName defines the name of the secret where the API credentials are stored.
SecretName string `json:"secretName"`

// APIKeyField defines the key under which the value for API key is stored inside the secret.
// +optional
APIKeyField string `json:"apiKeyField,omitempty" default:"api-key"`

// APISecretField defines the key under which the value for API secret is stored inside the secret.
// +optional
APISecretField string `json:"apiSecretField,omitempty" default:"api-secret"`
}

// CloudStackVMChaosStatus represents the status of a CloudStackChaos.
type CloudStackVMChaosStatus struct {
ChaosStatus `json:",inline"`
Expand Down
File renamed without changes.
153 changes: 153 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.

Loading

0 comments on commit 688c68e

Please sign in to comment.