mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-04-15 07:16:34 +00:00
Merge pull request #618 from replicatedhq/divolgin/sc-51321/kots-does-not-automatically-re-write-private
Adding some utility interfaces for collectors
This commit is contained in:
105
pkg/apis/troubleshoot/v1beta2/collector_interfaces.go
Normal file
105
pkg/apis/troubleshoot/v1beta2/collector_interfaces.go
Normal file
@@ -0,0 +1,105 @@
|
||||
package v1beta2
|
||||
|
||||
import (
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
func (c *Run) GetImage() string {
|
||||
return c.Image
|
||||
}
|
||||
|
||||
func (c *Run) SetImage(image string) {
|
||||
c.Image = image
|
||||
}
|
||||
|
||||
func (c *Run) GetImagePullSecret() *ImagePullSecrets {
|
||||
return c.ImagePullSecret
|
||||
}
|
||||
|
||||
func (c *Run) SetImagePullSecret(secrets *ImagePullSecrets) {
|
||||
c.ImagePullSecret = secrets
|
||||
}
|
||||
|
||||
func (c *Run) GetNamespace() string {
|
||||
return c.Namespace
|
||||
}
|
||||
|
||||
func (c *CopyFromHost) GetImage() string {
|
||||
return c.Image
|
||||
}
|
||||
|
||||
func (c *CopyFromHost) SetImage(image string) {
|
||||
c.Image = image
|
||||
}
|
||||
|
||||
func (c *CopyFromHost) GetImagePullSecret() *ImagePullSecrets {
|
||||
return c.ImagePullSecret
|
||||
}
|
||||
|
||||
func (c *CopyFromHost) SetImagePullSecret(secrets *ImagePullSecrets) {
|
||||
c.ImagePullSecret = secrets
|
||||
}
|
||||
|
||||
func (c *CopyFromHost) GetNamespace() string {
|
||||
return c.Namespace
|
||||
}
|
||||
|
||||
func (c *Sysctl) GetImage() string {
|
||||
return c.Image
|
||||
}
|
||||
|
||||
func (c *Sysctl) SetImage(image string) {
|
||||
c.Image = image
|
||||
}
|
||||
|
||||
func (c *Sysctl) GetImagePullSecret() *ImagePullSecrets {
|
||||
return c.ImagePullSecret
|
||||
}
|
||||
|
||||
func (c *Sysctl) SetImagePullSecret(secrets *ImagePullSecrets) {
|
||||
c.ImagePullSecret = secrets
|
||||
}
|
||||
|
||||
func (c *Sysctl) GetNamespace() string {
|
||||
return c.Namespace
|
||||
}
|
||||
|
||||
func (c *Collectd) GetImage() string {
|
||||
return c.Image
|
||||
}
|
||||
|
||||
func (c *Collectd) SetImage(image string) {
|
||||
c.Image = image
|
||||
}
|
||||
|
||||
func (c *Collectd) GetImagePullSecret() *ImagePullSecrets {
|
||||
return c.ImagePullSecret
|
||||
}
|
||||
|
||||
func (c *Collectd) SetImagePullSecret(secrets *ImagePullSecrets) {
|
||||
c.ImagePullSecret = secrets
|
||||
}
|
||||
|
||||
func (c *Collectd) GetNamespace() string {
|
||||
return c.Namespace
|
||||
}
|
||||
|
||||
func (c *RunPod) GetPodSpec() corev1.PodSpec {
|
||||
return c.PodSpec
|
||||
}
|
||||
|
||||
func (c *RunPod) SetPodSpec(podSpec corev1.PodSpec) {
|
||||
c.PodSpec = podSpec
|
||||
}
|
||||
|
||||
func (c *RunPod) GetImagePullSecret() *ImagePullSecrets {
|
||||
return c.ImagePullSecret
|
||||
}
|
||||
|
||||
func (c *RunPod) SetImagePullSecret(secrets *ImagePullSecrets) {
|
||||
c.ImagePullSecret = secrets
|
||||
}
|
||||
|
||||
func (c *RunPod) GetNamespace() string {
|
||||
return c.Namespace
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package v1beta2
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/replicatedhq/troubleshoot/pkg/multitype"
|
||||
@@ -538,3 +539,20 @@ func pickNamespaceOrDefault(collectorNS string, overrideNS string) string {
|
||||
}
|
||||
return "default"
|
||||
}
|
||||
|
||||
func GetCollector(collector *Collect) interface{} {
|
||||
if collector == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
reflected := reflect.ValueOf(collector).Elem()
|
||||
for i := 0; i < reflected.NumField(); i++ {
|
||||
if reflected.Field(i).IsNil() {
|
||||
continue
|
||||
}
|
||||
|
||||
return reflect.Indirect(reflected.Field(i)).Addr().Interface()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -355,6 +355,17 @@ func (in *AnalyzerSpec) DeepCopyInto(out *AnalyzerSpec) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if in.HostAnalyzers != nil {
|
||||
in, out := &in.HostAnalyzers, &out.HostAnalyzers
|
||||
*out = make([]*HostAnalyze, len(*in))
|
||||
for i := range *in {
|
||||
if (*in)[i] != nil {
|
||||
in, out := &(*in)[i], &(*out)[i]
|
||||
*out = new(HostAnalyze)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AnalyzerSpec.
|
||||
@@ -1637,6 +1648,11 @@ func (in *HostCollect) DeepCopyInto(out *HostCollect) {
|
||||
*out = new(HostOS)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
if in.HostRun != nil {
|
||||
in, out := &in.HostRun, &out.HostRun
|
||||
*out = new(HostRun)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HostCollect.
|
||||
@@ -1992,6 +2008,27 @@ func (in *HostPreflightStatus) DeepCopy() *HostPreflightStatus {
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *HostRun) DeepCopyInto(out *HostRun) {
|
||||
*out = *in
|
||||
in.HostCollectorMeta.DeepCopyInto(&out.HostCollectorMeta)
|
||||
if in.Args != nil {
|
||||
in, out := &in.Args, &out.Args
|
||||
*out = make([]string, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HostRun.
|
||||
func (in *HostRun) DeepCopy() *HostRun {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(HostRun)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *HostServices) DeepCopyInto(out *HostServices) {
|
||||
*out = *in
|
||||
@@ -3792,6 +3829,17 @@ func (in *SupportBundleSpec) DeepCopyInto(out *SupportBundleSpec) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if in.HostAnalyzers != nil {
|
||||
in, out := &in.HostAnalyzers, &out.HostAnalyzers
|
||||
*out = make([]*HostAnalyze, len(*in))
|
||||
for i := range *in {
|
||||
if (*in)[i] != nil {
|
||||
in, out := &(*in)[i], &(*out)[i]
|
||||
*out = new(HostAnalyze)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SupportBundleSpec.
|
||||
|
||||
33
pkg/collect/interfaces.go
Normal file
33
pkg/collect/interfaces.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package collect
|
||||
|
||||
import (
|
||||
"github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
type ImageRunner interface {
|
||||
GetImage() string
|
||||
SetImage(string)
|
||||
|
||||
GetImagePullSecret() *v1beta2.ImagePullSecrets
|
||||
SetImagePullSecret(*v1beta2.ImagePullSecrets)
|
||||
|
||||
GetNamespace() string
|
||||
}
|
||||
|
||||
var _ ImageRunner = &v1beta2.Run{}
|
||||
var _ ImageRunner = &v1beta2.CopyFromHost{}
|
||||
var _ ImageRunner = &v1beta2.Sysctl{}
|
||||
var _ ImageRunner = &v1beta2.Collectd{}
|
||||
|
||||
type PodSpecRunner interface {
|
||||
GetPodSpec() corev1.PodSpec
|
||||
SetPodSpec(corev1.PodSpec)
|
||||
|
||||
GetImagePullSecret() *v1beta2.ImagePullSecrets
|
||||
SetImagePullSecret(*v1beta2.ImagePullSecrets)
|
||||
|
||||
GetNamespace() string
|
||||
}
|
||||
|
||||
var _ PodSpecRunner = &v1beta2.RunPod{}
|
||||
57
pkg/collect/interfaces_test.go
Normal file
57
pkg/collect/interfaces_test.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package collect
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_interfaces(t *testing.T) {
|
||||
runCollector := &v1beta2.Run{}
|
||||
clusterInfoCollector := &v1beta2.ClusterInfo{}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
collect *v1beta2.Collect
|
||||
want interface{}
|
||||
wantRunner bool
|
||||
}{
|
||||
{
|
||||
name: "image runner collector",
|
||||
collect: &v1beta2.Collect{
|
||||
Run: runCollector,
|
||||
},
|
||||
want: runCollector,
|
||||
wantRunner: true,
|
||||
},
|
||||
{
|
||||
name: "not image runner collector",
|
||||
collect: &v1beta2.Collect{
|
||||
ClusterInfo: clusterInfoCollector,
|
||||
},
|
||||
want: clusterInfoCollector,
|
||||
wantRunner: false,
|
||||
},
|
||||
{
|
||||
name: "no collector",
|
||||
collect: &v1beta2.Collect{},
|
||||
want: nil,
|
||||
wantRunner: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
req := require.New(t)
|
||||
|
||||
got := v1beta2.GetCollector(tt.collect)
|
||||
req.EqualValues(tt.want, got)
|
||||
|
||||
runner, ok := got.(ImageRunner)
|
||||
req.EqualValues(tt.wantRunner, ok)
|
||||
if tt.wantRunner {
|
||||
req.EqualValues(tt.want, runner)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user