Skip to content

Commit

Permalink
new Insights 'DataGather' CRD to allow on-demand data gathering
Browse files Browse the repository at this point in the history
  • Loading branch information
tremes committed Dec 5, 2022
1 parent 94ac871 commit 1712c6f
Show file tree
Hide file tree
Showing 12 changed files with 1,146 additions and 0 deletions.
5 changes: 5 additions & 0 deletions insights/.codegen.yaml
@@ -0,0 +1,5 @@
schemapatch:
requiredFeatureSets:
- ""
- "Default"
- "TechPreviewNoUpgrade"
26 changes: 26 additions & 0 deletions insights/install.go
@@ -0,0 +1,26 @@
package insights

import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"

insightsv1alpha1 "github.com/openshift/api/insights/v1alpha1"
)

const (
GroupName = "insights.openshift.io"
)

var (
schemeBuilder = runtime.NewSchemeBuilder(insightsv1alpha1.Install)
// Install is a function which adds every version of this group to a scheme
Install = schemeBuilder.AddToScheme
)

func Resource(resource string) schema.GroupResource {
return schema.GroupResource{Group: GroupName, Resource: resource}
}

func Kind(kind string) schema.GroupKind {
return schema.GroupKind{Group: GroupName, Kind: kind}
}
243 changes: 243 additions & 0 deletions insights/v1alpha1/0000_10_01_datagather.crd.yaml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions insights/v1alpha1/Makefile
@@ -0,0 +1,3 @@
.PHONY: test
test:
make -C ../../tests test GINKGO_EXTRA_ARGS=--focus="insights.openshift.io/v1alpha1"
8 changes: 8 additions & 0 deletions insights/v1alpha1/doc.go
@@ -0,0 +1,8 @@
// +k8s:deepcopy-gen=package,register
// +k8s:defaulter-gen=TypeMeta
// +k8s:openapi-gen=true

// +kubebuilder:validation:Optional
// +groupName=insights.openshift.io
// Package v1alpha1 is the v1alpha1 version of the API.
package v1alpha1
38 changes: 38 additions & 0 deletions insights/v1alpha1/register.go
@@ -0,0 +1,38 @@
package v1alpha1

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

var (
GroupName = "insights.openshift.io"
GroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"}
schemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
// Install is a function which adds this version to a scheme
Install = schemeBuilder.AddToScheme

// SchemeGroupVersion generated code relies on this name
// Deprecated
SchemeGroupVersion = GroupVersion
// AddToScheme exists solely to keep the old generators creating valid code
// DEPRECATED
AddToScheme = schemeBuilder.AddToScheme
)

// Resource generated code relies on this being here, but it logically belongs to the group
// DEPRECATED
func Resource(resource string) schema.GroupResource {
return schema.GroupResource{Group: GroupName, Resource: resource}
}

// Adds the list of known types to api.Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(GroupVersion,
&DataGather{},
&DataGatherList{},
)
metav1.AddToGroupVersion(scheme, GroupVersion)
return nil
}
14 changes: 14 additions & 0 deletions insights/v1alpha1/techpreview.datagather.testsuite.yaml
@@ -0,0 +1,14 @@
apiVersion: apiextensions.k8s.io/v1 # Hack because controller-gen complains if we don't have this
name: "[Stable] DataGather"
crd: 0000_10_01_datagather.crd.yaml
tests:
onCreate:
- name: Should be able to create a minimal DataGather
initial: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
expected: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {}
125 changes: 125 additions & 0 deletions insights/v1alpha1/types_insights.go
@@ -0,0 +1,125 @@
package v1alpha1

import (
configv1 "github.com/openshift/api/config/v1"
operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +genclient
// +kubebuilder:resource:scope=Namespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
//
// DataGather provides data gather configuration options and status for the particular Insights data gathering.
//
// Compatibility level 4: No compatibility is provided, the API can change at any point for any reason. These capabilities should not be used by applications needing long term support.
// +openshift:compatibility-gen:level=4
type DataGather struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// spec holds user settable values for configuration
// +kubebuilder:validation:Required
Spec DataGatherSpec `json:"spec"`
// status holds observed values from the cluster. They may not be overridden.
// +optional
Status DataGatherStatus `json:"status"`
}

type DataGatherSpec struct {
// dataPolicy allows user to enable additional global obfuscation of the IP addresses and base domain
// in the Insights archive data. Valid values are "None" and "ObfuscateNetworking".
// When set to None the data is not obfuscated.
// When set to ObfuscateNetworking the IP addresses and the cluster domain name are obfuscated.
// When omitted, this means no opinion and the platform is left to choose a reasonable default, which is subject to change over time.
// The current default is None.
// +optional
DataPolicy DataPolicy `json:"dataPolicy"`
// disabledGatherers is a list of gatherers to be excluded from the gathering. All the gatherers can be disabled by providing "all" value.
// If all the gatherers are disabled, the Insights operator does not gather any data.
// The particular gatherers IDs can be found at https://github.com/openshift/insights-operator/blob/master/docs/gathered-data.md.
// Run the following command to get the names of last active gatherers:
// "oc get insightsoperators.operator.openshift.io cluster -o json | jq '.status.gatherStatus.gatherers[].name'"
// An example of disabling gatherers looks like this: `disabledGatherers: ["clusterconfig/machine_configs", "workloads/workload_info"]`
// +optional
DisabledGatherers []string `json:"disabledGatherers"`
}

const (
// No data obfuscation
NoPolicy DataPolicy = "None"
// IP addresses and cluster domain name are obfuscated
ObfuscateNetworking DataPolicy = "ObfuscateNetworking"
// Data gathering is running
Running State = "Running"
// Data gathering is completed
Completed State = "Completed"
// Data gathering failed
Failed State = "Failed"
// Data gathering is pending
Pending State = "Pending"
)

// dataPolicy declares valid data policy types
// +kubebuilder:validation:Enum="";None;ObfuscateNetworking
type DataPolicy string

// state declares valid gathering state types
// +kubebuilder:validation:Enum=Running;Completed;Failed
type State string

type DataGatherStatus struct {
// state reflects the current state of the data gathering process.
State State `json:"state,omitempty"`
// gatherers is a list of active gatherers (and their statuses) in the last gathering.
// +listType=atomic
Gatherers []GathererStatus `json:"gatherers,omitempty"`
// startTime is the time when Insights data gathering started.
StartTime metav1.Time `json:"startTime,omitempty"`
// finishTime is the time when Insights data gathering finished.
FinishTime metav1.Time `json:"finishTime,omitempty"`
// relatedObjects is a list of resources which are useful when debugging or inspecting the data
// gathering Pod
RelatedObjects []configv1.ObjectReference `json:"relatedObjects,omitempty"`
// healthChecks provides basic information about active Insights health checks
// in a cluster.
// +listType=atomic
// +optional
HealthChecks []operatorv1.HealthCheck `json:"healthChecks,omitempty"`
// conditions provide details on the status of the gatherer job.
// +listType=atomic
// +optional
Conditions []metav1.Condition `json:"conditions"`
}

// gathererStatus represents information about a particular
// data gatherer.
type GathererStatus struct {
// conditions provide details on the status of each gatherer.
// +listType=atomic
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinItems=1
Conditions []metav1.Condition `json:"conditions"`
// name is the name of the gatherer.
// +kubebuilder:validation:Required
// +kubebuilder:validation:MaxLength=256
// +kubebuilder:validation:MinLength=5
Name string `json:"name"`
// lastGatherDuration represents the time spent gathering.
// +kubebuilder:validation:Required
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Pattern="^([1-9][0-9]*(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
LastGatherDuration metav1.Duration `json:"lastGatherDuration"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// DataGatherList is a collection of items
//
// Compatibility level 4: No compatibility is provided, the API can change at any point for any reason. These capabilities should not be used by applications needing long term support.
// +openshift:compatibility-gen:level=4
type DataGatherList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []DataGather `json:"items"`
}
161 changes: 161 additions & 0 deletions insights/v1alpha1/zz_generated.deepcopy.go

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

0 comments on commit 1712c6f

Please sign in to comment.