Skip to content

Commit

Permalink
Add Certificate Chaos
Browse files Browse the repository at this point in the history
  • Loading branch information
gkoutsoumpakis-form3 authored and miketonks-form3 committed Jun 27, 2024
1 parent 8ef1c80 commit f0864d1
Show file tree
Hide file tree
Showing 36 changed files with 4,902 additions and 219 deletions.
120 changes: 120 additions & 0 deletions api/v1alpha1/certificatechaos_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Copyright 2021 Chaos Mesh Authors.PodPVCChaos
//
// 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"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
)

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

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

// Spec defines the behavior of a certificate chaos experiment
Spec CertificateChaosSpec `json:"spec"`

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

var _ InnerObjectWithCustomStatus = (*CertificateChaos)(nil)
var _ InnerObjectWithSelector = (*CertificateChaos)(nil)
var _ InnerObject = (*CertificateChaos)(nil)

// CertificateChaosSpec defines the attributes that a user creates on a chaos experiment about pods.
type CertificateChaosSpec struct {
CertificateSelector `json:"selector"`

// Duration represents the duration of the chaos action.
// Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
// +optional
// +kubebuilder:default="90m"
Duration *string `json:"duration,omitempty" webhook:"Duration"`

// CertificateExpiry represents the expiry period for the requested certificate.
// Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
// +optional
// +kubebuilder:default="1h"
CertificateExpiry *metav1.Duration `json:"certificateExpiry,omitempty"`

// RenewBefore represents when the cert-manager should rotate the certificate.
// Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
// +optional
// +kubebuilder:default="30m"
RenewBefore *metav1.Duration `json:"renewBefore,omitempty"`

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

type CertificateSelector struct {
GenericSelectorSpec `json:",inline"`
}

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

// Instances keeps track of the state for each certificate
// +optional
Instances map[string]Instance `json:"affectedFluxResources,omitempty"`
}

type Instance struct {
FluxResource FluxResource `json:"fluxResource"`
OriginalExpiry *metav1.Duration `json:"originalExpiry,omitempty"`
OriginalRenewBefore *metav1.Duration `json:"originalRenewBefore,omitempty"`
CertificateReadyAt *metav1.Time `json:"certificateReadyAt,omitempty"`
SecretName string `json:"secretName,omitempty"`
}

type FluxResource struct {
Group string `json:"group"`
Version string `json:"version"`
Kind string `json:"kind"`
Namespace string `json:"namespace"`
Name string `json:"name"`
}

func (e *FluxResource) NamespacedName() string {
return types.NamespacedName{Name: e.Name, Namespace: e.Namespace}.String()
}

func (e *FluxResource) GVK() schema.GroupVersionKind {
return schema.GroupVersionKind{
Group: e.Group,
Kind: e.Kind,
Version: e.Version,
}
}

func (obj *CertificateChaos) GetSelectorSpecs() map[string]interface{} {
return map[string]interface{}{
".": &obj.Spec.CertificateSelector,
}
}

func (obj *CertificateChaos) GetCustomStatus() interface{} {
return &obj.Status.Instances
}
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 f0864d1

Please sign in to comment.