Skip to content

Commit

Permalink
Merge pull request #417 from gianlucam76/techsupport
Browse files Browse the repository at this point in the history
(feat) introduce techsupport
  • Loading branch information
gianlucam76 authored Jan 3, 2025
2 parents e820eb9 + 6df08a5 commit 065fe5a
Show file tree
Hide file tree
Showing 65 changed files with 2,171 additions and 87 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
go-version: 1.22.7
go-version: 1.23.4
- name: Build
run: make build
- name: FMT
Expand All @@ -37,7 +37,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
go-version: 1.22.7
go-version: 1.23.4
- name: ut
run: make test
env:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ GOIMPORTS := $(TOOLS_BIN_DIR)/goimports
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint
GINKGO := $(TOOLS_BIN_DIR)/ginkgo

GOLANGCI_LINT_VERSION := "v1.61.0"
GOLANGCI_LINT_VERSION := "v1.62.2"

KUSTOMIZE_VER := v5.3.0
KUSTOMIZE_BIN := kustomize
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/clusterhealthcheck_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ type ClusterHealthCheckSpec struct {
// +patchStrategy=merge,retainKeys
LivenessChecks []LivenessCheck `json:"livenessChecks"`

// Notification is a list of source of events to evaluate.
// Notification is a list of notification mechanisms.
// +patchMergeKey=name
// +patchStrategy=merge,retainKeys
Notifications []Notification `json:"notifications"`
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ type ResourceSelector struct {

// Namespace of the resource deployed in the Cluster.
// Empty for resources scoped at cluster level.
// For namespaced resources, an empty string "" indicates all namespaces.
// +optional
Namespace string `json:"namespace,omitempty"`

Expand Down
206 changes: 206 additions & 0 deletions api/v1beta1/techsupport_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
/*
Copyright 2024. projectsveltos.io. All rights reserved.
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 v1beta1

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

const (
// TechsupportFinalizer allows TechsupportReconciler to clean up resources associated with
// Techsupport instance before removing it from the apiserver.
TechsupportFinalizer = "techsupportfinalizer.projectsveltos.io"
)

// LogFilter allows to select which logs to collect
type Log struct {
// Namespace of the pods deployed in the Cluster.
// An empty string "" indicates all namespaces.
// +optional
Namespace string `json:"namespace,omitempty"`

// Name of the pods deployed in the Cluster.
// +optional
Name string `json:"name,omitempty"`

// LabelFilters allows to filter pods based on current labels.
// +optional
LabelFilters []LabelFilter `json:"labelFilters,omitempty"`

// A relative time in seconds before the current time from which to collect logs.
// If this value precedes the time a pod was started, only logs since the pod
// start will be returned.
// +optional
SinceSeconds *int64 `json:"sinceSeconds,omitempty"`
}

// EventType represents the possible types of events.
type EventType string

const (
EventTypeNormal EventType = "Normal"
EventTypeWarning EventType = "Warning"
)

type Event struct {
// Namespace of the events.
// An empty string "" indicates all namespaces.
// +optional
Namespace string `json:"namespace,omitempty"`

// Type filters events based on the type of the events (Normal, Warning),
// +kubebuilder:validation:Enum=Normal;Warning
// +optional
Type string `json:"type,omitempty"`
}

type FromManagement struct {
// Resources indicates what resorces to collect
// +optional
Resources []ResourceSelector `json:"resources,omitempty"`

// Logs indicates what pods' log to collect
// +optional
Logs []Log `json:"logs,omitempty"`

// Events indicates what events to collect
// +optional
Events []Event `json:"events,omitempty"`
}

type FromManaged struct {
// ClusterSelector identifies clusters to collect techsupport from.
// +optional
ClusterSelector Selector `json:"clusterSelector,omitempty"`

// ClusterRefs identifies clusters to collect techsupport from.
// +optional
ClusterRefs []corev1.ObjectReference `json:"clusterRefs,omitempty"`

// Resources indicates what resorces to collect
// +optional
Resources []ResourceSelector `json:"resources,omitempty"`

// Logs indicates what pods' log to collect
// +optional
Logs []Log `json:"logs,omitempty"`

// Events indicates what events to collect
// +optional
Events []Event `json:"events,omitempty"`
}

type SchedulingConfig struct {
// Schedule in Cron format, see https://en.wikipedia.org/wiki/Cron.
Schedule string `json:"schedule"`

// Optional deadline in seconds for starting the job if it misses scheduled
// time for any reason. Missed jobs executions will be counted as failed ones.
// +optional
StartingDeadlineSeconds *int64 `json:"startingDeadlineSeconds,omitempty"`
}

// +kubebuilder:validation:Enum:=Collected;InProgress;Failed
type CollectionStatus string

const (
// CollectionStatusStatusInProgress indicates that collection is being collected
CollectionStatusInProgress = CollectionStatus("InProgress")

// CollectionStatusStatusCollected indicates that collection succeeded
CollectionStatusCollected = CollectionStatus("Collected")

// CollectionStatusStatusFailed indicates that last collection failed
CollectionStatusFailed = CollectionStatus("Failed")
)

// TechsupportSpec defines the desired state of Techsupport
type TechsupportSpec struct {
// FromManagement identifies which resources and logs to collect
// from the management cluster
// +optional
FromManagement FromManagement `json:"fromManagement,omitempty"`

// FromManaged specifies which resources and logs to collect from
// matching managed cluster.
// +optional
FromManaged FromManaged `json:"fromManaged,omitempty"`

// OnDemand indicates if tech support should be collected immediately.
// +optional
OnDemand bool `json:"onDemand,omitempty"`

// SchedulingConfig defines a schedule options for recurring tech support
// collections.
// +optional
SchedulingConfig *SchedulingConfig `json:"schedulingConfig,omitempty"`

// Notification is a list of notification mechanisms.
// +patchMergeKey=name
// +patchStrategy=merge,retainKeys
Notifications []Notification `json:"notifications"`
}

// TechsupportStatus defines the observed state of Techsupport
type TechsupportStatus struct {
// Information when next techsupport is scheduled
// +optional
NextScheduleTime *metav1.Time `json:"nextScheduleTime,omitempty"`

// Information when was the last time a techsupport was successfully scheduled.
// +optional
LastRunTime *metav1.Time `json:"lastRunTime,omitempty"`

// Status indicates what happened to last techsupport collection.
LastRunStatus *CollectionStatus `json:"lastRunStatus,omitempty"`

// FailureMessage provides more information about the error, if
// any occurred
FailureMessage *string `json:"failureMessage,omitempty"`

// Hash represents of a unique value for techsupport Spec at a fixed point in
// time
Hash []byte `json:"hash"`
}

//+kubebuilder:object:root=true
//+kubebuilder:resource:path=techsupports,scope=Cluster
//+kubebuilder:subresource:status
//+kubebuilder:storageversion

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

Spec TechsupportSpec `json:"spec,omitempty"`
Status TechsupportStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// TechsupportList contains a list of Techsupport instances
type TechsupportList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Techsupport `json:"items"`
}

func init() {
SchemeBuilder.Register(&Techsupport{}, &TechsupportList{})
}
Loading

0 comments on commit 065fe5a

Please sign in to comment.