diff --git a/pkg/apiserver/apiserver.go b/pkg/apiserver/apiserver.go index 2d265e7b..0060cb8a 100644 --- a/pkg/apiserver/apiserver.go +++ b/pkg/apiserver/apiserver.go @@ -21,12 +21,12 @@ import ( "github.com/kdoctor-io/kdoctor/pkg/apiserver/filters" "github.com/kdoctor-io/kdoctor/pkg/apiserver/registry" - "github.com/kdoctor-io/kdoctor/pkg/apiserver/registry/kdoctor/pluginreport" + "github.com/kdoctor-io/kdoctor/pkg/apiserver/registry/kdoctor/kdoctorreport" "github.com/kdoctor-io/kdoctor/pkg/k8s/apis/system/v1beta1" "github.com/kdoctor-io/kdoctor/pkg/k8s/client/clientset/versioned" ) -const DefaultPluginReportPath = "/report" +const DefaultKdoctorReportPath = "/report" var ( Scheme = runtime.NewScheme() @@ -60,7 +60,7 @@ func (s *kdoctorServerOptions) Config() (*Config, error) { return nil, err } - pluginReportDir := DefaultPluginReportPath + pluginReportDir := DefaultKdoctorReportPath env, ok := os.LookupEnv("ENV_CONTROLLER_REPORT_STORAGE_PATH") if ok { pluginReportDir = env @@ -140,7 +140,7 @@ func (c completedConfig) New() (*kdoctorServer, error) { apiGroupInfo := genericapiserver.NewDefaultAPIGroupInfo(GroupName, Scheme, metav1.ParameterCodec, Codecs) v1beta1storage := map[string]rest.Storage{} - v1beta1storage["pluginreports"] = registry.RESTInPeace(pluginreport.NewREST(clientSet, Scheme, c.GenericConfig.RESTOptionsGetter)) + v1beta1storage["kdoctorreports"] = registry.RESTInPeace(kdoctorreport.NewREST(clientSet, Scheme, c.GenericConfig.RESTOptionsGetter)) apiGroupInfo.VersionedResourcesStorageMap["v1beta1"] = v1beta1storage err = s.GenericAPIServer.InstallAPIGroup(&apiGroupInfo) diff --git a/pkg/apiserver/printers/table_generator.go b/pkg/apiserver/printers/table_generator.go index c6ea9672..3c71f7b0 100644 --- a/pkg/apiserver/printers/table_generator.go +++ b/pkg/apiserver/printers/table_generator.go @@ -44,7 +44,7 @@ func (t TableGenerator) ConvertToTable(ctx context.Context, obj runtime.Object, var err error table.Rows, err = metatable.MetaToTableRow(obj, func(obj runtime.Object, m metav1.Object, name, age string) ([]interface{}, error) { - pluginReport := obj.(*v1beta1.PluginReport) + pluginReport := obj.(*v1beta1.KdoctorReport) return []interface{}{ name, pluginReport.Spec.ToTalRoundNumber, diff --git a/pkg/apiserver/registry/kdoctor/pluginreport/etcd.go b/pkg/apiserver/registry/kdoctor/kdoctorreport/etcd.go similarity index 76% rename from pkg/apiserver/registry/kdoctor/pluginreport/etcd.go rename to pkg/apiserver/registry/kdoctor/kdoctorreport/etcd.go index 6bd67ee1..e9bc3d7b 100644 --- a/pkg/apiserver/registry/kdoctor/pluginreport/etcd.go +++ b/pkg/apiserver/registry/kdoctor/kdoctorreport/etcd.go @@ -1,7 +1,7 @@ // Copyright 2023 Authors of kdoctor-io // SPDX-License-Identifier: Apache-2.0 -package pluginreport +package kdoctorreport import ( "context" @@ -36,15 +36,15 @@ const dir = "/report" func NewREST(clientSet *versioned.Clientset, scheme *runtime.Scheme, optsGetter generic.RESTOptionsGetter) (*registry.REST, error) { strategy := NewStrategy(scheme) - restOptions, err := optsGetter.GetRESTOptions(v1beta1.Resource("pluginreports")) + restOptions, err := optsGetter.GetRESTOptions(v1beta1.Resource("kdoctorreports")) if nil != err { return nil, err } dryRunnableStorage, destroyFunc := NewStorage(clientSet, restOptions) store := &genericregistry.Store{ - NewFunc: func() runtime.Object { return &v1beta1.PluginReport{} }, - NewListFunc: func() runtime.Object { return &v1beta1.PluginReportList{} }, + NewFunc: func() runtime.Object { return &v1beta1.KdoctorReport{} }, + NewListFunc: func() runtime.Object { return &v1beta1.KdoctorReportList{} }, KeyRootFunc: func(ctx context.Context) string { return restOptions.ResourcePrefix }, @@ -52,10 +52,10 @@ func NewREST(clientSet *versioned.Clientset, scheme *runtime.Scheme, optsGetter return genericregistry.NoNamespaceKeyFunc(ctx, restOptions.ResourcePrefix, name) }, ObjectNameFunc: func(obj runtime.Object) (string, error) { - return obj.(*v1beta1.PluginReport).Name, nil + return obj.(*v1beta1.KdoctorReport).Name, nil }, - DefaultQualifiedResource: v1beta1.Resource("pluginreports"), - PredicateFunc: MatchPluginReport, + DefaultQualifiedResource: v1beta1.Resource("kdoctorreports"), + PredicateFunc: MatchKdoctorReport, CreateStrategy: strategy, UpdateStrategy: strategy, @@ -65,7 +65,7 @@ func NewREST(clientSet *versioned.Clientset, scheme *runtime.Scheme, optsGetter Storage: dryRunnableStorage, DestroyFunc: destroyFunc, - // TableConvertor: printers.NewTableGenerator(v1beta1.Resource("pluginreports")), + // TableConvertor: printers.NewTableGenerator(v1beta1.Resource("kdoctorreports")), } return ®istry.REST{Store: store}, nil @@ -73,7 +73,7 @@ func NewREST(clientSet *versioned.Clientset, scheme *runtime.Scheme, optsGetter func NewStorage(clientSet *versioned.Clientset, restOptions generic.RESTOptions) (genericregistry.DryRunnableStorage, factory.DestroyFunc) { dryRunnableStorage := genericregistry.DryRunnableStorage{ - Storage: &pluginReportStorage{ + Storage: &kdoctorReportStorage{ clientSet: clientSet, }, Codec: restOptions.StorageConfig.Codec, @@ -82,31 +82,31 @@ func NewStorage(clientSet *versioned.Clientset, restOptions generic.RESTOptions) return dryRunnableStorage, func() {} } -var _ storage.Interface = &pluginReportStorage{} +var _ storage.Interface = &kdoctorReportStorage{} -type pluginReportStorage struct { +type kdoctorReportStorage struct { clientSet *versioned.Clientset resourceName string } -func (p pluginReportStorage) Versioner() storage.Versioner { +func (p kdoctorReportStorage) Versioner() storage.Versioner { return storage.APIObjectVersioner{} } -func (p pluginReportStorage) Create(ctx context.Context, key string, obj, out runtime.Object, ttl uint64) error { +func (p kdoctorReportStorage) Create(ctx context.Context, key string, obj, out runtime.Object, ttl uint64) error { return fmt.Errorf("create API not implement") } -func (p pluginReportStorage) Delete(ctx context.Context, key string, out runtime.Object, preconditions *storage.Preconditions, validateDeletion storage.ValidateObjectFunc, cachedExistingObject runtime.Object) error { +func (p kdoctorReportStorage) Delete(ctx context.Context, key string, out runtime.Object, preconditions *storage.Preconditions, validateDeletion storage.ValidateObjectFunc, cachedExistingObject runtime.Object) error { return fmt.Errorf("delete API not implement") } -func (p pluginReportStorage) Watch(ctx context.Context, key string, opts storage.ListOptions) (watch.Interface, error) { +func (p kdoctorReportStorage) Watch(ctx context.Context, key string, opts storage.ListOptions) (watch.Interface, error) { return nil, fmt.Errorf("watch API not implement") } -func (p pluginReportStorage) Get(ctx context.Context, key string, opts storage.GetOptions, objPtr runtime.Object) error { +func (p kdoctorReportStorage) Get(ctx context.Context, key string, opts storage.GetOptions, objPtr runtime.Object) error { klog.Infof("Get called with key: %v on resource %v\n", key, p.resourceName) var taskStatus *crd.TaskStatus @@ -198,8 +198,8 @@ func (p pluginReportStorage) Get(ctx context.Context, key string, opts storage.G return fmt.Errorf("no '%s' reports found", name) } - pluginReport := objPtr.(*v1beta1.PluginReport) - pluginReport.Spec = v1beta1.PluginReportSpec{ + kdoctorReport := objPtr.(*v1beta1.KdoctorReport) + kdoctorReport.Spec = v1beta1.KdoctorReportSpec{ TaskName: name, TaskType: taskType, ToTalRoundNumber: toTalRoundNumber, @@ -210,11 +210,11 @@ func (p pluginReportStorage) Get(ctx context.Context, key string, opts storage.G Report: getReports, } - pluginReport.Name = name - pluginReport.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{ + kdoctorReport.Name = name + kdoctorReport.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{ Group: v1beta1.GroupName, Version: v1beta1.V1betaVersion, - Kind: v1beta1.KindPluginReport, + Kind: v1beta1.KindKdoctorReport, }) return nil @@ -222,7 +222,7 @@ func (p pluginReportStorage) Get(ctx context.Context, key string, opts storage.G const summary = "summary" -func (p pluginReportStorage) GetList(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object) error { +func (p kdoctorReportStorage) GetList(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object) error { readDir, err := os.ReadDir(dir) if nil != err { return fmt.Errorf("failed to read directory %s, error: %w", dir, err) @@ -235,16 +235,16 @@ func (p pluginReportStorage) GetList(ctx context.Context, key string, opts stora fileNameList = append(fileNameList, item.Name()) } - pluginReportList := listObj.(*v1beta1.PluginReportList) + kdoctorReportList := listObj.(*v1beta1.KdoctorReportList) var resList []runtime.Object { - netDNSPluginReports, err := p.getNetDNSPluginReports(ctx, fileNameList) + netDNSKdoctorReports, err := p.getNetDNSKdoctorReports(ctx, fileNameList) if nil != err { return err } - for i := range netDNSPluginReports { - resList = append(resList, netDNSPluginReports[i].DeepCopy()) + for i := range netDNSKdoctorReports { + resList = append(resList, netDNSKdoctorReports[i].DeepCopy()) } } @@ -268,29 +268,29 @@ func (p pluginReportStorage) GetList(ctx context.Context, key string, opts stora } } - err = meta.SetList(pluginReportList, resList) + err = meta.SetList(kdoctorReportList, resList) if nil != err { return err } - pluginReportList.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{ + kdoctorReportList.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{ Group: v1beta1.GroupName, Version: v1beta1.V1betaVersion, - Kind: v1beta1.KindPluginReportList, + Kind: v1beta1.KindKdoctorReportList, }) return nil } -func (p pluginReportStorage) GuaranteedUpdate(ctx context.Context, key string, destination runtime.Object, ignoreNotFound bool, preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, cachedExistingObject runtime.Object) error { +func (p kdoctorReportStorage) GuaranteedUpdate(ctx context.Context, key string, destination runtime.Object, ignoreNotFound bool, preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, cachedExistingObject runtime.Object) error { return fmt.Errorf("GuaranteedUpdate API not implement") } -func (p pluginReportStorage) Count(key string) (int64, error) { +func (p kdoctorReportStorage) Count(key string) (int64, error) { return 0, fmt.Errorf("Count not supported for key: %s", key) } -func (p pluginReportStorage) getLatestRoundReports(key string, fileNameList []string) (*[]v1beta1.Report, int64, error) { +func (p kdoctorReportStorage) getLatestRoundReports(key string, fileNameList []string) (*[]v1beta1.Report, int64, error) { var reports []v1beta1.Report for _, netDNSFileName := range fileNameList { split := strings.Split(netDNSFileName, "_") @@ -342,8 +342,8 @@ func (p pluginReportStorage) getLatestRoundReports(key string, fileNameList []st return result, latestRoundNumber, nil } -func (p pluginReportStorage) getNetDNSPluginReports(ctx context.Context, fileNameList []string) ([]*v1beta1.PluginReport, error) { - var resList []*v1beta1.PluginReport +func (p kdoctorReportStorage) getNetDNSKdoctorReports(ctx context.Context, fileNameList []string) ([]*v1beta1.KdoctorReport, error) { + var resList []*v1beta1.KdoctorReport netDNSList, err := p.clientSet.KdoctorV1beta1().Netdnses().List(ctx, metav1.ListOptions{}) if nil != err { @@ -389,7 +389,7 @@ func (p pluginReportStorage) getNetDNSPluginReports(ctx context.Context, fileNam finishedRoundNumber = int64(tmpNetDNS.Status.History[0].RoundNumber) } - pluginReportSpec := v1beta1.PluginReportSpec{ + kdoctorReportSpec := v1beta1.KdoctorReportSpec{ TaskName: tmpNetDNS.Name, TaskType: v1beta1.NetDNSTaskName, ToTalRoundNumber: *tmpNetDNS.Status.ExpectedRound, @@ -400,23 +400,23 @@ func (p pluginReportStorage) getNetDNSPluginReports(ctx context.Context, fileNam Report: result, } - pluginReport := &v1beta1.PluginReport{} - pluginReport.Name = tmpNetDNS.Name - pluginReport.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{ + kdoctorReport := &v1beta1.KdoctorReport{} + kdoctorReport.Name = tmpNetDNS.Name + kdoctorReport.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{ Group: v1beta1.GroupName, Version: v1beta1.V1betaVersion, - Kind: v1beta1.KindPluginReport, + Kind: v1beta1.KindKdoctorReport, }) - pluginReport.Spec = pluginReportSpec + kdoctorReport.Spec = kdoctorReportSpec - resList = append(resList, pluginReport) + resList = append(resList, kdoctorReport) } return resList, nil } -func (p pluginReportStorage) getHttpAppHealthyReports(ctx context.Context, fileNameList []string) ([]*v1beta1.PluginReport, error) { - var resList []*v1beta1.PluginReport +func (p kdoctorReportStorage) getHttpAppHealthyReports(ctx context.Context, fileNameList []string) ([]*v1beta1.KdoctorReport, error) { + var resList []*v1beta1.KdoctorReport httpAppHealthyList, err := p.clientSet.KdoctorV1beta1().AppHttpHealthies().List(ctx, metav1.ListOptions{}) if nil != err { @@ -462,7 +462,7 @@ func (p pluginReportStorage) getHttpAppHealthyReports(ctx context.Context, fileN finishedRoundNumber = int64(tmpHttpAppHealthy.Status.History[0].RoundNumber) } - pluginReportSpec := v1beta1.PluginReportSpec{ + kdoctorReportSpec := v1beta1.KdoctorReportSpec{ TaskName: tmpHttpAppHealthy.Name, TaskType: v1beta1.AppHttpHealthyTaskName, ToTalRoundNumber: *tmpHttpAppHealthy.Status.ExpectedRound, @@ -473,23 +473,23 @@ func (p pluginReportStorage) getHttpAppHealthyReports(ctx context.Context, fileN Report: result, } - pluginReport := &v1beta1.PluginReport{} - pluginReport.Name = tmpHttpAppHealthy.Name - pluginReport.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{ + kdoctorReport := &v1beta1.KdoctorReport{} + kdoctorReport.Name = tmpHttpAppHealthy.Name + kdoctorReport.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{ Group: v1beta1.GroupName, Version: v1beta1.V1betaVersion, - Kind: v1beta1.KindPluginReport, + Kind: v1beta1.KindKdoctorReport, }) - pluginReport.Spec = pluginReportSpec + kdoctorReport.Spec = kdoctorReportSpec - resList = append(resList, pluginReport) + resList = append(resList, kdoctorReport) } return resList, nil } -func (p pluginReportStorage) getNetReachHealthyReports(ctx context.Context, fileNameList []string) ([]*v1beta1.PluginReport, error) { - var resList []*v1beta1.PluginReport +func (p kdoctorReportStorage) getNetReachHealthyReports(ctx context.Context, fileNameList []string) ([]*v1beta1.KdoctorReport, error) { + var resList []*v1beta1.KdoctorReport netReachHealthyList, err := p.clientSet.KdoctorV1beta1().NetReaches().List(ctx, metav1.ListOptions{}) if nil != err { @@ -535,7 +535,7 @@ func (p pluginReportStorage) getNetReachHealthyReports(ctx context.Context, file finishedRoundNumber = int64(tmpNetReachHealthy.Status.History[0].RoundNumber) } - pluginReportSpec := v1beta1.PluginReportSpec{ + kdoctorReportSpec := v1beta1.KdoctorReportSpec{ TaskName: tmpNetReachHealthy.Name, TaskType: v1beta1.NetReachTaskName, ToTalRoundNumber: *tmpNetReachHealthy.Status.ExpectedRound, @@ -546,16 +546,16 @@ func (p pluginReportStorage) getNetReachHealthyReports(ctx context.Context, file Report: result, } - pluginReport := &v1beta1.PluginReport{} - pluginReport.Name = tmpNetReachHealthy.Name - pluginReport.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{ + kdoctorReport := &v1beta1.KdoctorReport{} + kdoctorReport.Name = tmpNetReachHealthy.Name + kdoctorReport.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{ Group: v1beta1.GroupName, Version: v1beta1.V1betaVersion, - Kind: v1beta1.KindPluginReport, + Kind: v1beta1.KindKdoctorReport, }) - pluginReport.Spec = pluginReportSpec + kdoctorReport.Spec = kdoctorReportSpec - resList = append(resList, pluginReport) + resList = append(resList, kdoctorReport) } return resList, nil diff --git a/pkg/apiserver/registry/kdoctor/pluginreport/keyer.go b/pkg/apiserver/registry/kdoctor/kdoctorreport/keyer.go similarity index 98% rename from pkg/apiserver/registry/kdoctor/pluginreport/keyer.go rename to pkg/apiserver/registry/kdoctor/kdoctorreport/keyer.go index e16d7002..de8ca55c 100644 --- a/pkg/apiserver/registry/kdoctor/pluginreport/keyer.go +++ b/pkg/apiserver/registry/kdoctor/kdoctorreport/keyer.go @@ -1,7 +1,7 @@ // Copyright (c) 2019 Tigera, Inc. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -package pluginreport +package kdoctorreport import ( "fmt" diff --git a/pkg/apiserver/registry/kdoctor/kdoctorreport/strategy.go b/pkg/apiserver/registry/kdoctor/kdoctorreport/strategy.go new file mode 100644 index 00000000..0a3bf33e --- /dev/null +++ b/pkg/apiserver/registry/kdoctor/kdoctorreport/strategy.go @@ -0,0 +1,92 @@ +// Copyright 2023 Authors of kdoctor-io +// SPDX-License-Identifier: Apache-2.0 + +package kdoctorreport + +import ( + "context" + "fmt" + + "k8s.io/apimachinery/pkg/fields" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/validation/field" + "k8s.io/apiserver/pkg/registry/generic" + "k8s.io/apiserver/pkg/registry/rest" + "k8s.io/apiserver/pkg/storage" + "k8s.io/apiserver/pkg/storage/names" + + "github.com/kdoctor-io/kdoctor/pkg/k8s/apis/system/v1beta1" +) + +type kdoctorReportStrategy struct { + runtime.ObjectTyper + names.NameGenerator +} + +var _ rest.RESTCreateStrategy = &kdoctorReportStrategy{} +var _ rest.RESTUpdateStrategy = &kdoctorReportStrategy{} + +func NewStrategy(typer runtime.ObjectTyper) kdoctorReportStrategy { + return kdoctorReportStrategy{ + ObjectTyper: typer, + NameGenerator: names.SimpleNameGenerator, + } +} + +func (p kdoctorReportStrategy) NamespaceScoped() bool { + return true +} + +func (p kdoctorReportStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) { +} + +func (p kdoctorReportStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) { +} + +func (p kdoctorReportStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList { + return field.ErrorList{} +} + +func (p kdoctorReportStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string { + return []string{} +} + +func (p kdoctorReportStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string { + return []string{} +} + +func (p kdoctorReportStrategy) AllowCreateOnUpdate() bool { + return false +} + +func (p kdoctorReportStrategy) AllowUnconditionalUpdate() bool { + return false +} + +func (p kdoctorReportStrategy) Canonicalize(obj runtime.Object) { +} + +func (p kdoctorReportStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList { + return field.ErrorList{} +} + +func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) { + kdoctorReport, ok := obj.(*v1beta1.KdoctorReport) + if !ok { + return nil, nil, fmt.Errorf("given object is not a KdoctorReport") + } + return labels.Set(kdoctorReport.ObjectMeta.Labels), SelectableFields(kdoctorReport), nil +} + +func MatchKdoctorReport(label labels.Selector, field fields.Selector) storage.SelectionPredicate { + return storage.SelectionPredicate{ + Label: label, + Field: field, + GetAttrs: GetAttrs, + } +} + +func SelectableFields(obj *v1beta1.KdoctorReport) fields.Set { + return generic.ObjectMetaFieldsSet(&obj.ObjectMeta, true) +} diff --git a/pkg/apiserver/registry/kdoctor/pluginreport/strategy.go b/pkg/apiserver/registry/kdoctor/pluginreport/strategy.go deleted file mode 100644 index 856bcf6b..00000000 --- a/pkg/apiserver/registry/kdoctor/pluginreport/strategy.go +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2023 Authors of kdoctor-io -// SPDX-License-Identifier: Apache-2.0 - -package pluginreport - -import ( - "context" - "fmt" - - "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/validation/field" - "k8s.io/apiserver/pkg/registry/generic" - "k8s.io/apiserver/pkg/registry/rest" - "k8s.io/apiserver/pkg/storage" - "k8s.io/apiserver/pkg/storage/names" - - "github.com/kdoctor-io/kdoctor/pkg/k8s/apis/system/v1beta1" -) - -type pluginReportStrategy struct { - runtime.ObjectTyper - names.NameGenerator -} - -var _ rest.RESTCreateStrategy = &pluginReportStrategy{} -var _ rest.RESTUpdateStrategy = &pluginReportStrategy{} - -func NewStrategy(typer runtime.ObjectTyper) pluginReportStrategy { - return pluginReportStrategy{ - ObjectTyper: typer, - NameGenerator: names.SimpleNameGenerator, - } -} - -func (p pluginReportStrategy) NamespaceScoped() bool { - return true -} - -func (p pluginReportStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) { -} - -func (p pluginReportStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) { -} - -func (p pluginReportStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList { - return field.ErrorList{} -} - -func (p pluginReportStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string { - return []string{} -} - -func (p pluginReportStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string { - return []string{} -} - -func (p pluginReportStrategy) AllowCreateOnUpdate() bool { - return false -} - -func (p pluginReportStrategy) AllowUnconditionalUpdate() bool { - return false -} - -func (p pluginReportStrategy) Canonicalize(obj runtime.Object) { -} - -func (p pluginReportStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList { - return field.ErrorList{} -} - -func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) { - pluginReport, ok := obj.(*v1beta1.PluginReport) - if !ok { - return nil, nil, fmt.Errorf("given object is not a PluginReport") - } - return labels.Set(pluginReport.ObjectMeta.Labels), SelectableFields(pluginReport), nil -} - -func MatchPluginReport(label labels.Selector, field fields.Selector) storage.SelectionPredicate { - return storage.SelectionPredicate{ - Label: label, - Field: field, - GetAttrs: GetAttrs, - } -} - -func SelectableFields(obj *v1beta1.PluginReport) fields.Set { - return generic.ObjectMetaFieldsSet(&obj.ObjectMeta, true) -} diff --git a/pkg/k8s/apis/system/v1beta1/pluginreport_types.go b/pkg/k8s/apis/system/v1beta1/kdoctorreport_types.go similarity index 88% rename from pkg/k8s/apis/system/v1beta1/pluginreport_types.go rename to pkg/k8s/apis/system/v1beta1/kdoctorreport_types.go index 1340b8e6..e58dc4df 100644 --- a/pkg/k8s/apis/system/v1beta1/pluginreport_types.go +++ b/pkg/k8s/apis/system/v1beta1/kdoctorreport_types.go @@ -12,26 +12,26 @@ import ( // +genclient:nonNamespaced // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// PluginReport +// KdoctorReport // +k8s:openapi-gen=true -type PluginReport struct { +type KdoctorReport struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec PluginReportSpec `json:"spec,omitempty"` + Spec KdoctorReportSpec `json:"spec,omitempty"` } -// PluginReportList +// KdoctorReportList // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type PluginReportList struct { +type KdoctorReportList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty"` - Items []PluginReport `json:"items"` + Items []KdoctorReport `json:"items"` } -// PluginReportSpec defines the desired state of PluginReport -type PluginReportSpec struct { +// KdoctorReportSpec defines the desired state of KdoctorReport +type KdoctorReportSpec struct { TaskName string `json:"TaskName"` TaskType string `json:"TaskType"` ToTalRoundNumber int64 `json:"RoundNumber"` diff --git a/pkg/k8s/apis/system/v1beta1/register.go b/pkg/k8s/apis/system/v1beta1/register.go index 17fc8821..296f9b80 100644 --- a/pkg/k8s/apis/system/v1beta1/register.go +++ b/pkg/k8s/apis/system/v1beta1/register.go @@ -11,10 +11,10 @@ import ( const ( // GroupName is the group name used in this package. - GroupName = "system.kdoctor.io" - V1betaVersion = "v1beta1" - KindPluginReport = "PluginReport" - KindPluginReportList = "PluginReportList" + GroupName = "system.kdoctor.io" + V1betaVersion = "v1beta1" + KindKdoctorReport = "KdoctorReport" + KindKdoctorReportList = "KdoctorReportList" ) // SchemeGroupVersion is group version used to register these objects. @@ -30,8 +30,8 @@ var ( // Adds the list of known types to the given scheme. func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, - &PluginReport{}, - &PluginReportList{}, + &KdoctorReport{}, + &KdoctorReportList{}, ) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) return nil diff --git a/pkg/k8s/apis/system/v1beta1/zz_generated.deepcopy.go b/pkg/k8s/apis/system/v1beta1/zz_generated.deepcopy.go index 507f350e..79021d17 100644 --- a/pkg/k8s/apis/system/v1beta1/zz_generated.deepcopy.go +++ b/pkg/k8s/apis/system/v1beta1/zz_generated.deepcopy.go @@ -122,6 +122,95 @@ func (in *HttpMetrics) DeepCopy() *HttpMetrics { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KdoctorReport) DeepCopyInto(out *KdoctorReport) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KdoctorReport. +func (in *KdoctorReport) DeepCopy() *KdoctorReport { + if in == nil { + return nil + } + out := new(KdoctorReport) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *KdoctorReport) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KdoctorReportList) DeepCopyInto(out *KdoctorReportList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]KdoctorReport, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KdoctorReportList. +func (in *KdoctorReportList) DeepCopy() *KdoctorReportList { + if in == nil { + return nil + } + out := new(KdoctorReportList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *KdoctorReportList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KdoctorReportSpec) DeepCopyInto(out *KdoctorReportSpec) { + *out = *in + if in.FailedRoundNumber != nil { + in, out := &in.FailedRoundNumber, &out.FailedRoundNumber + *out = make([]int64, len(*in)) + copy(*out, *in) + } + if in.Report != nil { + in, out := &in.Report, &out.Report + *out = new([]Report) + if **in != nil { + in, out := *in, *out + *out = make([]Report, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KdoctorReportSpec. +func (in *KdoctorReportSpec) DeepCopy() *KdoctorReportSpec { + if in == nil { + return nil + } + out := new(KdoctorReportSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *LatencyDistribution) DeepCopyInto(out *LatencyDistribution) { *out = *in @@ -233,95 +322,6 @@ func (in *NetReachTaskDetail) DeepCopy() *NetReachTaskDetail { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PluginReport) DeepCopyInto(out *PluginReport) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PluginReport. -func (in *PluginReport) DeepCopy() *PluginReport { - if in == nil { - return nil - } - out := new(PluginReport) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *PluginReport) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PluginReportList) DeepCopyInto(out *PluginReportList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]PluginReport, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PluginReportList. -func (in *PluginReportList) DeepCopy() *PluginReportList { - if in == nil { - return nil - } - out := new(PluginReportList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *PluginReportList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PluginReportSpec) DeepCopyInto(out *PluginReportSpec) { - *out = *in - if in.FailedRoundNumber != nil { - in, out := &in.FailedRoundNumber, &out.FailedRoundNumber - *out = make([]int64, len(*in)) - copy(*out, *in) - } - if in.Report != nil { - in, out := &in.Report, &out.Report - *out = new([]Report) - if **in != nil { - in, out := *in, *out - *out = make([]Report, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PluginReportSpec. -func (in *PluginReportSpec) DeepCopy() *PluginReportSpec { - if in == nil { - return nil - } - out := new(PluginReportSpec) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Report) DeepCopyInto(out *Report) { *out = *in diff --git a/pkg/pluginManager/apphttphealthy/agentExecuteTask.go b/pkg/pluginManager/apphttphealthy/agentExecuteTask.go index 73e522d0..e678590b 100644 --- a/pkg/pluginManager/apphttphealthy/agentExecuteTask.go +++ b/pkg/pluginManager/apphttphealthy/agentExecuteTask.go @@ -56,13 +56,10 @@ func SendRequestAndReport(logger *zap.Logger, targetName string, req *loadHttp.H report.Metrics = *result if len(failureReason) == 0 { report.FailureReason = nil - } else { - report.FailureReason = pointer.String(failureReason) - } - if report.FailureReason == nil { report.Succeed = true logger.Sugar().Infof("succeed to test %v", req.Url) } else { + report.FailureReason = pointer.String(failureReason) report.Succeed = false logger.Sugar().Warnf("failed to test %v", req.Url) } diff --git a/pkg/pluginManager/netdns/agentExecuteTask.go b/pkg/pluginManager/netdns/agentExecuteTask.go index 38ece41f..bd1ed447 100644 --- a/pkg/pluginManager/netdns/agentExecuteTask.go +++ b/pkg/pluginManager/netdns/agentExecuteTask.go @@ -64,13 +64,10 @@ func SendRequestAndReport(logger *zap.Logger, targetName string, req *loadDns.Dn report.Metrics = *result if len(failureReason) == 0 { report.FailureReason = nil - } else { - report.FailureReason = pointer.String(failureReason) - } - if report.FailureReason == nil { report.Succeed = true logger.Sugar().Infof("succeed to test %v", req.DnsServerAddr) } else { + report.FailureReason = pointer.String(failureReason) report.Succeed = false logger.Sugar().Warnf("failed to test %v", req.DnsServerAddr) } diff --git a/pkg/pluginManager/netreach/agentExecuteTask.go b/pkg/pluginManager/netreach/agentExecuteTask.go index a1a02184..294d2216 100644 --- a/pkg/pluginManager/netreach/agentExecuteTask.go +++ b/pkg/pluginManager/netreach/agentExecuteTask.go @@ -58,13 +58,10 @@ func SendRequestAndReport(logger *zap.Logger, targetName string, req *loadHttp.H report.Metrics = *result if len(failureReason) == 0 { report.FailureReason = nil - } else { - report.FailureReason = pointer.String(failureReason) - } - if report.FailureReason == nil { report.Succeed = true logger.Sugar().Infof("succeed to test %v", req.Url) } else { + report.FailureReason = pointer.String(failureReason) report.Succeed = false logger.Sugar().Warnf("failed to test %v", req.Url) }