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 Mar 20, 2023
1 parent 1957a8d commit ba793e0
Show file tree
Hide file tree
Showing 12 changed files with 2,010 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}
}
323 changes: 323 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
}
258 changes: 258 additions & 0 deletions insights/v1alpha1/techpreview.datagather.testsuite.yaml
@@ -0,0 +1,258 @@
apiVersion: apiextensions.k8s.io/v1 # Hack because controller-gen complains if we don't have this
name: "[TechPreview] 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: {}
onUpdate:
- name: status is present and startTime is added
initial: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
insightsRequestID: xyz
updated: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
insightsRequestID: xyz
startTime: 2023-03-13T11:34:06Z
expected: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
insightsRequestID: xyz
startTime: 2023-03-13T11:34:06Z
- name: startTime cannot be removed from status
initial: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
insightsRequestID: xyz
startTime: 2023-03-13T11:34:06Z
updated: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
insightsRequestID: xyz
expectedStatusError: "status: Invalid value: \"object\": cannot remove startTime attribute from status"
- name: startTime is immutable once set
initial: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
insightsRequestID: xyz
startTime: 2023-03-13T11:34:06Z
updated: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
insightsRequestID: xyz
startTime: 2023-03-13T12:34:06Z
expectedStatusError: "Invalid value: \"string\": startTime is immutable once set"
- name: Status is presentt and insightsRequestID is added
initial: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
relatedObjects:
- name: periodic-job-xyz
resource: "pods"
group: ""
namespace: "openshift-insights"
updated: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
insightsRequestID: testing-xyz
relatedObjects:
- name: periodic-job-xyz
resource: "pods"
group: ""
namespace: "openshift-insights"
expected: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
insightsRequestID: testing-xyz
relatedObjects:
- name: periodic-job-xyz
group: ""
resource: "pods"
namespace: "openshift-insights"
- name: insightsRequestID cannot be removed from status
initial: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
insightsRequestID: testing-xyz
relatedObjects:
- name: periodic-job-xyz
group: ""
resource: "pods"
namespace: "openshift-insights"
updated: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
relatedObjects:
- name: periodic-job-xyz
group: ""
resource: "pods"
namespace: "openshift-insights"
expectedStatusError: "status: Invalid value: \"object\": cannot remove insightsRequestID attribute from status"
- name: insightsRequestID is immutable once set
initial: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
insightsRequestID: testing-xyz
relatedObjects:
- name: periodic-job-xyz
group: ""
resource: "pods"
namespace: "openshift-insights"
updated: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
insightsRequestID: testing-xyz-updated
relatedObjects:
- name: periodic-job-xyz
group: ""
resource: "pods"
namespace: "openshift-insights"
expectedStatusError: "Invalid value: \"string\": insightsRequestID is immutable once set"
- name: finishTime cannot be removed from status
initial: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
finishTime: 2023-03-13T11:34:06Z
relatedObjects:
- name: periodic-job-xyz
group: ""
resource: "pods"
namespace: "openshift-insights"
updated: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
relatedObjects:
- name: periodic-job-xyz
group: ""
resource: "pods"
namespace: "openshift-insights"
expectedStatusError: "status: Invalid value: \"object\": cannot remove finishTime attribute from status"
- name: dataGatherState cannot be removed from status
initial: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
dataGatherState: Running
updated: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
relatedObjects:
- name: periodic-job-xyz
group: ""
resource: "pods"
namespace: "openshift-insights"
expectedStatusError: "status: Invalid value: \"object\": cannot remove dataGatherState attribute from status"
- name: dataGatherState cannot transition from Running to Pending
initial: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
dataGatherState: Running
updated: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
dataGatherState: Pending
expectedStatusError: "status.dataGatherState: Invalid value: \"string\": dataGatherState cannot transition from Running to Pending"
- name: dataGatherState cannot transition from Completed to Pending
initial: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
dataGatherState: Completed
updated: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
dataGatherState: Pending
expectedStatusError: "status.dataGatherState: Invalid value: \"string\": dataGatherState cannot transition from Completed to Pending"
- name: dataGatherState cannot transition from Failed to Pending
initial: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
dataGatherState: Failed
updated: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
dataGatherState: Pending
expectedStatusError: "status.dataGatherState: Invalid value: \"string\": dataGatherState cannot transition from Failed to Pending"
- name: dataGatherState cannot transition from Completed to Running
initial: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
dataGatherState: Completed
updated: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
dataGatherState: Running
expectedStatusError: "status.dataGatherState: Invalid value: \"string\": dataGatherState cannot transition from Completed to Running"
- name: dataGatherState cannot transition from Failed to Running
initial: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
dataGatherState: Failed
updated: |
apiVersion: insights.openshift.io/v1alpha1
kind: DataGather
spec: {} # No spec is required for a DataGather
status:
dataGatherState: Running
expectedStatusError: "status.dataGatherState: Invalid value: \"string\": dataGatherState cannot transition from Failed to Running"

0 comments on commit ba793e0

Please sign in to comment.