diff --git a/Makefile b/Makefile index 0d53fafe..5e339d8c 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ REGISTRY ?= projectsveltos IMAGE_NAME ?= sveltosctl export SVELTOSCTL_IMG ?= $(REGISTRY)/$(IMAGE_NAME) TAG ?= main -ARCH ?= amd64 +ARCH ?= $(shell go env GOARCH) # Directories. ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) @@ -44,6 +44,22 @@ KUSTOMIZE_PKG := sigs.k8s.io/kustomize/kustomize/v5 $(KUSTOMIZE): # Build kustomize from tools folder. CGO_ENABLED=0 GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(KUSTOMIZE_PKG) $(KUSTOMIZE_BIN) $(KUSTOMIZE_VER) +CONVERSION_GEN_VER := v0.30.0 +CONVERSION_GEN_BIN := conversion-gen +# We are intentionally using the binary without version suffix, to avoid the version +# in generated files. +CONVERSION_GEN := $(abspath $(TOOLS_BIN_DIR)/$(CONVERSION_GEN_BIN)) +CONVERSION_GEN_PKG := k8s.io/code-generator/cmd/conversion-gen + +.PHONY: $(CONVERSION_GEN_BIN) +$(CONVERSION_GEN_BIN): $(CONVERSION_GEN) ## Build a local copy of conversion-gen. + +## We are forcing a rebuilt of conversion-gen via PHONY so that we're always using an up-to-date version. +## We can't use a versioned name for the binary, because that would be reflected in generated files. +.PHONY: $(CONVERSION_GEN) +$(CONVERSION_GEN): # Build conversion-gen from tools folder. + GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(CONVERSION_GEN_PKG) $(CONVERSION_GEN_BIN) $(CONVERSION_GEN_VER) + SETUP_ENVTEST_VER := v0.0.0-20240522175850-2e9781e9fc60 SETUP_ENVTEST_BIN := setup-envtest SETUP_ENVTEST := $(abspath $(TOOLS_BIN_DIR)/$(SETUP_ENVTEST_BIN)-$(SETUP_ENVTEST_VER)) @@ -83,7 +99,7 @@ help: ## Display this help. ##@ Tools .PHONY: tools -tools: $(GOLANGCI_LINT) $(GOIMPORTS) $(GINKGO) $(KUBECTL) $(SETUP_ENVTEST) $(CONTROLLER_GEN) ## build all tools +tools: $(GOLANGCI_LINT) $(GOIMPORTS) $(GINKGO) $(KUBECTL) $(SETUP_ENVTEST) $(CONTROLLER_GEN) $(CONVERSION_GEN) ## build all tools .PHONY: clean clean: ## Remove all built tools @@ -100,11 +116,27 @@ generate-modules: ## Run go mod tidy to ensure modules are up to date generate: ## Run all generate-manifests-*, generate-go-deepcopy-* $(MAKE) generate-modules generate-manifests generate-go-deepcopy cp k8s/sveltosctl.yaml manifest/manifest.yaml - cat config/crd/bases/utils.projectsveltos.io_snapshots.yaml >> manifest/manifest.yaml - cat config/crd/bases/utils.projectsveltos.io_techsupports.yaml >> manifest/manifest.yaml + mkdir tmp; $(KUSTOMIZE) build config/default -o tmp + echo "---" >> manifest/manifest.yaml + cat tmp/apiextensions.k8s.io_v1_customresourcedefinition_snapshots.utils.projectsveltos.io.yaml >> manifest/manifest.yaml + echo "---" >> manifest/manifest.yaml + cat tmp/apiextensions.k8s.io_v1_customresourcedefinition_techsupports.utils.projectsveltos.io.yaml >> manifest/manifest.yaml + rm -rf tmp MANIFEST_IMG=$(SVELTOSCTL_IMG) MANIFEST_TAG=$(TAG) $(MAKE) set-manifest-image $(MAKE) fmt +.PHONY: generate-go-conversions +generate-go-conversions: $(CONVERSION_GEN) ## Generate conversions go code for utils.projectsveltos.io api + $(MAKE) clean-generated-conversions SRC_DIRS="./api/v1alpha1" + $(CONVERSION_GEN) \ + --output-file=zz_generated.conversion.go \ + --go-header-file=./hack/boilerplate.generatego.txt \ + ./api/v1alpha1 + +.PHONY: clean-generated-conversions +clean-generated-conversions: ## Remove files generated by conversion-gen from the mentioned dirs. Example SRC_DIRS="./api/v1alpha4" + (IFS=','; for i in $(SRC_DIRS); do find $$i -type f -name 'zz_generated.conversion*' -exec rm -f {} \;; done) + set-manifest-image: sed -i'' -e 's@image: .*@image: '"${MANIFEST_IMG}:$(MANIFEST_TAG)"'@' ./manifest/manifest.yaml diff --git a/README.md b/README.md index 8cae428d..1c1a938c 100644 --- a/README.md +++ b/README.md @@ -260,12 +260,14 @@ Define a Techsupport instance, following for instance will collect a techsupport from all managed clusters matching cluster selectors __env=fv__ ``` -apiVersion: utils.projectsveltos.io/v1alpha1 +apiVersion: utils.projectsveltos.io/v1beta1 kind: Techsupport metadata: name: hourly spec: - clusterSelector: env=fv + clusterSelector: + matchLabels: + env: fv schedule: “00 * * * *” storage: /techsupport logs: @@ -311,7 +313,7 @@ A snapshot allows an administrator to perform the following tasks: Define a Snapshot instance, following for instance will take a snaphost every hour. ``` -apiVersion: utils.projectsveltos.io/v1alpha1 +apiVersion: utils.projectsveltos.io/v1beta1 kind: Snapshot metadata: name: hourly diff --git a/api/v1alpha1/doc.go b/api/v1alpha1/doc.go new file mode 100644 index 00000000..a6296e91 --- /dev/null +++ b/api/v1alpha1/doc.go @@ -0,0 +1,20 @@ +/* +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 v1alpha1 + +// +k8s:conversion-gen=github.com/projectsveltos/sveltosctl/api/v1beta1 +// +k8s:deepcopy-gen=package diff --git a/api/v1alpha1/groupversion_info.go b/api/v1alpha1/groupversion_info.go index 6bc67cfd..31b7f1a6 100644 --- a/api/v1alpha1/groupversion_info.go +++ b/api/v1alpha1/groupversion_info.go @@ -33,4 +33,6 @@ var ( // AddToScheme adds the types in this group-version to the given scheme. AddToScheme = SchemeBuilder.AddToScheme + + localSchemeBuilder = SchemeBuilder.SchemeBuilder ) diff --git a/api/v1alpha1/techsupport_conversion.go b/api/v1alpha1/techsupport_conversion.go new file mode 100644 index 00000000..2e602403 --- /dev/null +++ b/api/v1alpha1/techsupport_conversion.go @@ -0,0 +1,92 @@ +/* +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 v1alpha1 + +import ( + "fmt" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + apimachineryconversion "k8s.io/apimachinery/pkg/conversion" + "sigs.k8s.io/controller-runtime/pkg/conversion" + + libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" + utilsv1beta1 "github.com/projectsveltos/sveltosctl/api/v1beta1" +) + +// ConvertTo converts v1alpha1 to the Hub version (v1beta1). +func (src *Techsupport) ConvertTo(dstRaw conversion.Hub) error { + dst := dstRaw.(*utilsv1beta1.Techsupport) + err := Convert_v1alpha1_Techsupport_To_v1beta1_Techsupport(src, dst, nil) + if err != nil { + return err + } + + if src.Spec.ClusterSelector == "" { + dst.Spec.ClusterSelector.LabelSelector = metav1.LabelSelector{} + } + + return nil +} + +// ConvertFrom converts from the Hub version (v1beta1) to this v1alpha1. +func (dst *Techsupport) ConvertFrom(srcRaw conversion.Hub) error { + src := srcRaw.(*utilsv1beta1.Techsupport) + err := Convert_v1beta1_Techsupport_To_v1alpha1_Techsupport(src, dst, nil) + if err != nil { + return err + } + + if src.Spec.ClusterSelector.MatchLabels == nil { + dst.Spec.ClusterSelector = "" + } + + return nil +} + +func Convert_v1alpha1_TechsupportSpec_To_v1beta1_TechsupportSpec(srcSpec *TechsupportSpec, dstSpec *utilsv1beta1.TechsupportSpec, + scope apimachineryconversion.Scope) error { + + if err := autoConvert_v1alpha1_TechsupportSpec_To_v1beta1_TechsupportSpec(srcSpec, dstSpec, nil); err != nil { + return err + } + + labelSelector, err := metav1.ParseToLabelSelector(string(srcSpec.ClusterSelector)) + if err != nil { + return fmt.Errorf("error converting labels.Selector to metav1.Selector: %w", err) + } + dstSpec.ClusterSelector = libsveltosv1beta1.Selector{LabelSelector: *labelSelector} + + return nil +} + +func Convert_v1beta1_TechsupportSpec_To_v1alpha1_TechsupportSpec(srcSpec *utilsv1beta1.TechsupportSpec, dstSpec *TechsupportSpec, + scope apimachineryconversion.Scope) error { + + if err := autoConvert_v1beta1_TechsupportSpec_To_v1alpha1_TechsupportSpec(srcSpec, dstSpec, nil); err != nil { + return err + } + + labelSelector, err := srcSpec.ClusterSelector.ToSelector() + if err != nil { + return fmt.Errorf("failed to convert : %w", err) + } + + dstSpec.ClusterSelector = libsveltosv1alpha1.Selector(labelSelector.String()) + + return nil +} diff --git a/api/v1alpha1/zz_generated.conversion.go b/api/v1alpha1/zz_generated.conversion.go new file mode 100644 index 00000000..1dd5c6bf --- /dev/null +++ b/api/v1alpha1/zz_generated.conversion.go @@ -0,0 +1,428 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kubernetes Authors. + +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. +*/ +// Code generated by conversion-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + unsafe "unsafe" + + corev1 "k8s.io/api/core/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + conversion "k8s.io/apimachinery/pkg/conversion" + runtime "k8s.io/apimachinery/pkg/runtime" + + apiv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + apiv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" + v1beta1 "github.com/projectsveltos/sveltosctl/api/v1beta1" +) + +func init() { + localSchemeBuilder.Register(RegisterConversions) +} + +// RegisterConversions adds conversion functions to the given scheme. +// Public to allow building arbitrary schemes. +func RegisterConversions(s *runtime.Scheme) error { + if err := s.AddGeneratedConversionFunc((*Log)(nil), (*v1beta1.Log)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_Log_To_v1beta1_Log(a.(*Log), b.(*v1beta1.Log), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1beta1.Log)(nil), (*Log)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_Log_To_v1alpha1_Log(a.(*v1beta1.Log), b.(*Log), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*Resource)(nil), (*v1beta1.Resource)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_Resource_To_v1beta1_Resource(a.(*Resource), b.(*v1beta1.Resource), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1beta1.Resource)(nil), (*Resource)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_Resource_To_v1alpha1_Resource(a.(*v1beta1.Resource), b.(*Resource), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*Snapshot)(nil), (*v1beta1.Snapshot)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_Snapshot_To_v1beta1_Snapshot(a.(*Snapshot), b.(*v1beta1.Snapshot), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1beta1.Snapshot)(nil), (*Snapshot)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_Snapshot_To_v1alpha1_Snapshot(a.(*v1beta1.Snapshot), b.(*Snapshot), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*SnapshotList)(nil), (*v1beta1.SnapshotList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_SnapshotList_To_v1beta1_SnapshotList(a.(*SnapshotList), b.(*v1beta1.SnapshotList), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1beta1.SnapshotList)(nil), (*SnapshotList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_SnapshotList_To_v1alpha1_SnapshotList(a.(*v1beta1.SnapshotList), b.(*SnapshotList), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*SnapshotSpec)(nil), (*v1beta1.SnapshotSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_SnapshotSpec_To_v1beta1_SnapshotSpec(a.(*SnapshotSpec), b.(*v1beta1.SnapshotSpec), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1beta1.SnapshotSpec)(nil), (*SnapshotSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_SnapshotSpec_To_v1alpha1_SnapshotSpec(a.(*v1beta1.SnapshotSpec), b.(*SnapshotSpec), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*SnapshotStatus)(nil), (*v1beta1.SnapshotStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_SnapshotStatus_To_v1beta1_SnapshotStatus(a.(*SnapshotStatus), b.(*v1beta1.SnapshotStatus), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1beta1.SnapshotStatus)(nil), (*SnapshotStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_SnapshotStatus_To_v1alpha1_SnapshotStatus(a.(*v1beta1.SnapshotStatus), b.(*SnapshotStatus), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*Techsupport)(nil), (*v1beta1.Techsupport)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_Techsupport_To_v1beta1_Techsupport(a.(*Techsupport), b.(*v1beta1.Techsupport), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1beta1.Techsupport)(nil), (*Techsupport)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_Techsupport_To_v1alpha1_Techsupport(a.(*v1beta1.Techsupport), b.(*Techsupport), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*TechsupportList)(nil), (*v1beta1.TechsupportList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_TechsupportList_To_v1beta1_TechsupportList(a.(*TechsupportList), b.(*v1beta1.TechsupportList), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1beta1.TechsupportList)(nil), (*TechsupportList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_TechsupportList_To_v1alpha1_TechsupportList(a.(*v1beta1.TechsupportList), b.(*TechsupportList), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*TechsupportSpec)(nil), (*v1beta1.TechsupportSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_TechsupportSpec_To_v1beta1_TechsupportSpec(a.(*TechsupportSpec), b.(*v1beta1.TechsupportSpec), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1beta1.TechsupportSpec)(nil), (*TechsupportSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_TechsupportSpec_To_v1alpha1_TechsupportSpec(a.(*v1beta1.TechsupportSpec), b.(*TechsupportSpec), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*TechsupportStatus)(nil), (*v1beta1.TechsupportStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_TechsupportStatus_To_v1beta1_TechsupportStatus(a.(*TechsupportStatus), b.(*v1beta1.TechsupportStatus), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1beta1.TechsupportStatus)(nil), (*TechsupportStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_TechsupportStatus_To_v1alpha1_TechsupportStatus(a.(*v1beta1.TechsupportStatus), b.(*TechsupportStatus), scope) + }); err != nil { + return err + } + return nil +} + +func autoConvert_v1alpha1_Log_To_v1beta1_Log(in *Log, out *v1beta1.Log, s conversion.Scope) error { + out.Namespace = in.Namespace + out.LabelFilters = *(*[]apiv1beta1.LabelFilter)(unsafe.Pointer(&in.LabelFilters)) + out.SinceSeconds = (*int64)(unsafe.Pointer(in.SinceSeconds)) + return nil +} + +// Convert_v1alpha1_Log_To_v1beta1_Log is an autogenerated conversion function. +func Convert_v1alpha1_Log_To_v1beta1_Log(in *Log, out *v1beta1.Log, s conversion.Scope) error { + return autoConvert_v1alpha1_Log_To_v1beta1_Log(in, out, s) +} + +func autoConvert_v1beta1_Log_To_v1alpha1_Log(in *v1beta1.Log, out *Log, s conversion.Scope) error { + out.Namespace = in.Namespace + out.LabelFilters = *(*[]apiv1alpha1.LabelFilter)(unsafe.Pointer(&in.LabelFilters)) + out.SinceSeconds = (*int64)(unsafe.Pointer(in.SinceSeconds)) + return nil +} + +// Convert_v1beta1_Log_To_v1alpha1_Log is an autogenerated conversion function. +func Convert_v1beta1_Log_To_v1alpha1_Log(in *v1beta1.Log, out *Log, s conversion.Scope) error { + return autoConvert_v1beta1_Log_To_v1alpha1_Log(in, out, s) +} + +func autoConvert_v1alpha1_Resource_To_v1beta1_Resource(in *Resource, out *v1beta1.Resource, s conversion.Scope) error { + out.Namespace = in.Namespace + out.Group = in.Group + out.Version = in.Version + out.Kind = in.Kind + out.LabelFilters = *(*[]apiv1beta1.LabelFilter)(unsafe.Pointer(&in.LabelFilters)) + return nil +} + +// Convert_v1alpha1_Resource_To_v1beta1_Resource is an autogenerated conversion function. +func Convert_v1alpha1_Resource_To_v1beta1_Resource(in *Resource, out *v1beta1.Resource, s conversion.Scope) error { + return autoConvert_v1alpha1_Resource_To_v1beta1_Resource(in, out, s) +} + +func autoConvert_v1beta1_Resource_To_v1alpha1_Resource(in *v1beta1.Resource, out *Resource, s conversion.Scope) error { + out.Namespace = in.Namespace + out.Group = in.Group + out.Version = in.Version + out.Kind = in.Kind + out.LabelFilters = *(*[]apiv1alpha1.LabelFilter)(unsafe.Pointer(&in.LabelFilters)) + return nil +} + +// Convert_v1beta1_Resource_To_v1alpha1_Resource is an autogenerated conversion function. +func Convert_v1beta1_Resource_To_v1alpha1_Resource(in *v1beta1.Resource, out *Resource, s conversion.Scope) error { + return autoConvert_v1beta1_Resource_To_v1alpha1_Resource(in, out, s) +} + +func autoConvert_v1alpha1_Snapshot_To_v1beta1_Snapshot(in *Snapshot, out *v1beta1.Snapshot, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + if err := Convert_v1alpha1_SnapshotSpec_To_v1beta1_SnapshotSpec(&in.Spec, &out.Spec, s); err != nil { + return err + } + if err := Convert_v1alpha1_SnapshotStatus_To_v1beta1_SnapshotStatus(&in.Status, &out.Status, s); err != nil { + return err + } + return nil +} + +// Convert_v1alpha1_Snapshot_To_v1beta1_Snapshot is an autogenerated conversion function. +func Convert_v1alpha1_Snapshot_To_v1beta1_Snapshot(in *Snapshot, out *v1beta1.Snapshot, s conversion.Scope) error { + return autoConvert_v1alpha1_Snapshot_To_v1beta1_Snapshot(in, out, s) +} + +func autoConvert_v1beta1_Snapshot_To_v1alpha1_Snapshot(in *v1beta1.Snapshot, out *Snapshot, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + if err := Convert_v1beta1_SnapshotSpec_To_v1alpha1_SnapshotSpec(&in.Spec, &out.Spec, s); err != nil { + return err + } + if err := Convert_v1beta1_SnapshotStatus_To_v1alpha1_SnapshotStatus(&in.Status, &out.Status, s); err != nil { + return err + } + return nil +} + +// Convert_v1beta1_Snapshot_To_v1alpha1_Snapshot is an autogenerated conversion function. +func Convert_v1beta1_Snapshot_To_v1alpha1_Snapshot(in *v1beta1.Snapshot, out *Snapshot, s conversion.Scope) error { + return autoConvert_v1beta1_Snapshot_To_v1alpha1_Snapshot(in, out, s) +} + +func autoConvert_v1alpha1_SnapshotList_To_v1beta1_SnapshotList(in *SnapshotList, out *v1beta1.SnapshotList, s conversion.Scope) error { + out.ListMeta = in.ListMeta + out.Items = *(*[]v1beta1.Snapshot)(unsafe.Pointer(&in.Items)) + return nil +} + +// Convert_v1alpha1_SnapshotList_To_v1beta1_SnapshotList is an autogenerated conversion function. +func Convert_v1alpha1_SnapshotList_To_v1beta1_SnapshotList(in *SnapshotList, out *v1beta1.SnapshotList, s conversion.Scope) error { + return autoConvert_v1alpha1_SnapshotList_To_v1beta1_SnapshotList(in, out, s) +} + +func autoConvert_v1beta1_SnapshotList_To_v1alpha1_SnapshotList(in *v1beta1.SnapshotList, out *SnapshotList, s conversion.Scope) error { + out.ListMeta = in.ListMeta + out.Items = *(*[]Snapshot)(unsafe.Pointer(&in.Items)) + return nil +} + +// Convert_v1beta1_SnapshotList_To_v1alpha1_SnapshotList is an autogenerated conversion function. +func Convert_v1beta1_SnapshotList_To_v1alpha1_SnapshotList(in *v1beta1.SnapshotList, out *SnapshotList, s conversion.Scope) error { + return autoConvert_v1beta1_SnapshotList_To_v1alpha1_SnapshotList(in, out, s) +} + +func autoConvert_v1alpha1_SnapshotSpec_To_v1beta1_SnapshotSpec(in *SnapshotSpec, out *v1beta1.SnapshotSpec, s conversion.Scope) error { + out.Schedule = in.Schedule + out.StartingDeadlineSeconds = (*int64)(unsafe.Pointer(in.StartingDeadlineSeconds)) + out.Storage = in.Storage + out.SuccessfulSnapshotLimit = (*int32)(unsafe.Pointer(in.SuccessfulSnapshotLimit)) + return nil +} + +// Convert_v1alpha1_SnapshotSpec_To_v1beta1_SnapshotSpec is an autogenerated conversion function. +func Convert_v1alpha1_SnapshotSpec_To_v1beta1_SnapshotSpec(in *SnapshotSpec, out *v1beta1.SnapshotSpec, s conversion.Scope) error { + return autoConvert_v1alpha1_SnapshotSpec_To_v1beta1_SnapshotSpec(in, out, s) +} + +func autoConvert_v1beta1_SnapshotSpec_To_v1alpha1_SnapshotSpec(in *v1beta1.SnapshotSpec, out *SnapshotSpec, s conversion.Scope) error { + out.Schedule = in.Schedule + out.StartingDeadlineSeconds = (*int64)(unsafe.Pointer(in.StartingDeadlineSeconds)) + out.Storage = in.Storage + out.SuccessfulSnapshotLimit = (*int32)(unsafe.Pointer(in.SuccessfulSnapshotLimit)) + return nil +} + +// Convert_v1beta1_SnapshotSpec_To_v1alpha1_SnapshotSpec is an autogenerated conversion function. +func Convert_v1beta1_SnapshotSpec_To_v1alpha1_SnapshotSpec(in *v1beta1.SnapshotSpec, out *SnapshotSpec, s conversion.Scope) error { + return autoConvert_v1beta1_SnapshotSpec_To_v1alpha1_SnapshotSpec(in, out, s) +} + +func autoConvert_v1alpha1_SnapshotStatus_To_v1beta1_SnapshotStatus(in *SnapshotStatus, out *v1beta1.SnapshotStatus, s conversion.Scope) error { + out.NextScheduleTime = (*v1.Time)(unsafe.Pointer(in.NextScheduleTime)) + out.LastRunTime = (*v1.Time)(unsafe.Pointer(in.LastRunTime)) + out.LastRunStatus = (*v1beta1.CollectionStatus)(unsafe.Pointer(in.LastRunStatus)) + out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) + return nil +} + +// Convert_v1alpha1_SnapshotStatus_To_v1beta1_SnapshotStatus is an autogenerated conversion function. +func Convert_v1alpha1_SnapshotStatus_To_v1beta1_SnapshotStatus(in *SnapshotStatus, out *v1beta1.SnapshotStatus, s conversion.Scope) error { + return autoConvert_v1alpha1_SnapshotStatus_To_v1beta1_SnapshotStatus(in, out, s) +} + +func autoConvert_v1beta1_SnapshotStatus_To_v1alpha1_SnapshotStatus(in *v1beta1.SnapshotStatus, out *SnapshotStatus, s conversion.Scope) error { + out.NextScheduleTime = (*v1.Time)(unsafe.Pointer(in.NextScheduleTime)) + out.LastRunTime = (*v1.Time)(unsafe.Pointer(in.LastRunTime)) + out.LastRunStatus = (*CollectionStatus)(unsafe.Pointer(in.LastRunStatus)) + out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) + return nil +} + +// Convert_v1beta1_SnapshotStatus_To_v1alpha1_SnapshotStatus is an autogenerated conversion function. +func Convert_v1beta1_SnapshotStatus_To_v1alpha1_SnapshotStatus(in *v1beta1.SnapshotStatus, out *SnapshotStatus, s conversion.Scope) error { + return autoConvert_v1beta1_SnapshotStatus_To_v1alpha1_SnapshotStatus(in, out, s) +} + +func autoConvert_v1alpha1_Techsupport_To_v1beta1_Techsupport(in *Techsupport, out *v1beta1.Techsupport, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + if err := Convert_v1alpha1_TechsupportSpec_To_v1beta1_TechsupportSpec(&in.Spec, &out.Spec, s); err != nil { + return err + } + if err := Convert_v1alpha1_TechsupportStatus_To_v1beta1_TechsupportStatus(&in.Status, &out.Status, s); err != nil { + return err + } + return nil +} + +// Convert_v1alpha1_Techsupport_To_v1beta1_Techsupport is an autogenerated conversion function. +func Convert_v1alpha1_Techsupport_To_v1beta1_Techsupport(in *Techsupport, out *v1beta1.Techsupport, s conversion.Scope) error { + return autoConvert_v1alpha1_Techsupport_To_v1beta1_Techsupport(in, out, s) +} + +func autoConvert_v1beta1_Techsupport_To_v1alpha1_Techsupport(in *v1beta1.Techsupport, out *Techsupport, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + if err := Convert_v1beta1_TechsupportSpec_To_v1alpha1_TechsupportSpec(&in.Spec, &out.Spec, s); err != nil { + return err + } + if err := Convert_v1beta1_TechsupportStatus_To_v1alpha1_TechsupportStatus(&in.Status, &out.Status, s); err != nil { + return err + } + return nil +} + +// Convert_v1beta1_Techsupport_To_v1alpha1_Techsupport is an autogenerated conversion function. +func Convert_v1beta1_Techsupport_To_v1alpha1_Techsupport(in *v1beta1.Techsupport, out *Techsupport, s conversion.Scope) error { + return autoConvert_v1beta1_Techsupport_To_v1alpha1_Techsupport(in, out, s) +} + +func autoConvert_v1alpha1_TechsupportList_To_v1beta1_TechsupportList(in *TechsupportList, out *v1beta1.TechsupportList, s conversion.Scope) error { + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]v1beta1.Techsupport, len(*in)) + for i := range *in { + if err := Convert_v1alpha1_Techsupport_To_v1beta1_Techsupport(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } + return nil +} + +// Convert_v1alpha1_TechsupportList_To_v1beta1_TechsupportList is an autogenerated conversion function. +func Convert_v1alpha1_TechsupportList_To_v1beta1_TechsupportList(in *TechsupportList, out *v1beta1.TechsupportList, s conversion.Scope) error { + return autoConvert_v1alpha1_TechsupportList_To_v1beta1_TechsupportList(in, out, s) +} + +func autoConvert_v1beta1_TechsupportList_To_v1alpha1_TechsupportList(in *v1beta1.TechsupportList, out *TechsupportList, s conversion.Scope) error { + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Techsupport, len(*in)) + for i := range *in { + if err := Convert_v1beta1_Techsupport_To_v1alpha1_Techsupport(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } + return nil +} + +// Convert_v1beta1_TechsupportList_To_v1alpha1_TechsupportList is an autogenerated conversion function. +func Convert_v1beta1_TechsupportList_To_v1alpha1_TechsupportList(in *v1beta1.TechsupportList, out *TechsupportList, s conversion.Scope) error { + return autoConvert_v1beta1_TechsupportList_To_v1alpha1_TechsupportList(in, out, s) +} + +func autoConvert_v1alpha1_TechsupportSpec_To_v1beta1_TechsupportSpec(in *TechsupportSpec, out *v1beta1.TechsupportSpec, s conversion.Scope) error { + // WARNING: in.ClusterSelector requires manual conversion: inconvertible types (github.com/projectsveltos/libsveltos/api/v1alpha1.Selector vs github.com/projectsveltos/libsveltos/api/v1beta1.Selector) + out.Resources = *(*[]v1beta1.Resource)(unsafe.Pointer(&in.Resources)) + out.Logs = *(*[]v1beta1.Log)(unsafe.Pointer(&in.Logs)) + out.Tar = in.Tar + out.Schedule = in.Schedule + out.StartingDeadlineSeconds = (*int64)(unsafe.Pointer(in.StartingDeadlineSeconds)) + out.Storage = in.Storage + out.SuccessfulTechsupportLimit = (*int32)(unsafe.Pointer(in.SuccessfulTechsupportLimit)) + return nil +} + +func autoConvert_v1beta1_TechsupportSpec_To_v1alpha1_TechsupportSpec(in *v1beta1.TechsupportSpec, out *TechsupportSpec, s conversion.Scope) error { + // WARNING: in.ClusterSelector requires manual conversion: inconvertible types (github.com/projectsveltos/libsveltos/api/v1beta1.Selector vs github.com/projectsveltos/libsveltos/api/v1alpha1.Selector) + out.Resources = *(*[]Resource)(unsafe.Pointer(&in.Resources)) + out.Logs = *(*[]Log)(unsafe.Pointer(&in.Logs)) + out.Tar = in.Tar + out.Schedule = in.Schedule + out.StartingDeadlineSeconds = (*int64)(unsafe.Pointer(in.StartingDeadlineSeconds)) + out.Storage = in.Storage + out.SuccessfulTechsupportLimit = (*int32)(unsafe.Pointer(in.SuccessfulTechsupportLimit)) + return nil +} + +func autoConvert_v1alpha1_TechsupportStatus_To_v1beta1_TechsupportStatus(in *TechsupportStatus, out *v1beta1.TechsupportStatus, s conversion.Scope) error { + out.NextScheduleTime = (*v1.Time)(unsafe.Pointer(in.NextScheduleTime)) + out.LastRunTime = (*v1.Time)(unsafe.Pointer(in.LastRunTime)) + out.LastRunStatus = (*v1beta1.CollectionStatus)(unsafe.Pointer(in.LastRunStatus)) + out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) + out.MatchingClusterRefs = *(*[]corev1.ObjectReference)(unsafe.Pointer(&in.MatchingClusterRefs)) + return nil +} + +// Convert_v1alpha1_TechsupportStatus_To_v1beta1_TechsupportStatus is an autogenerated conversion function. +func Convert_v1alpha1_TechsupportStatus_To_v1beta1_TechsupportStatus(in *TechsupportStatus, out *v1beta1.TechsupportStatus, s conversion.Scope) error { + return autoConvert_v1alpha1_TechsupportStatus_To_v1beta1_TechsupportStatus(in, out, s) +} + +func autoConvert_v1beta1_TechsupportStatus_To_v1alpha1_TechsupportStatus(in *v1beta1.TechsupportStatus, out *TechsupportStatus, s conversion.Scope) error { + out.NextScheduleTime = (*v1.Time)(unsafe.Pointer(in.NextScheduleTime)) + out.LastRunTime = (*v1.Time)(unsafe.Pointer(in.LastRunTime)) + out.LastRunStatus = (*CollectionStatus)(unsafe.Pointer(in.LastRunStatus)) + out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) + out.MatchingClusterRefs = *(*[]corev1.ObjectReference)(unsafe.Pointer(&in.MatchingClusterRefs)) + return nil +} + +// Convert_v1beta1_TechsupportStatus_To_v1alpha1_TechsupportStatus is an autogenerated conversion function. +func Convert_v1beta1_TechsupportStatus_To_v1alpha1_TechsupportStatus(in *v1beta1.TechsupportStatus, out *TechsupportStatus, s conversion.Scope) error { + return autoConvert_v1beta1_TechsupportStatus_To_v1alpha1_TechsupportStatus(in, out, s) +} diff --git a/api/v1beta1/collection_status.go b/api/v1beta1/collection_status.go new file mode 100644 index 00000000..30af0523 --- /dev/null +++ b/api/v1beta1/collection_status.go @@ -0,0 +1,31 @@ +/* +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 + +// +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") +) diff --git a/api/v1beta1/groupversion_info.go b/api/v1beta1/groupversion_info.go new file mode 100644 index 00000000..98d23bc0 --- /dev/null +++ b/api/v1beta1/groupversion_info.go @@ -0,0 +1,36 @@ +/* +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 v1alpha1 contains API Schema definitions for the config v1alpha1 API group +// +kubebuilder:object:generate=true +// +groupName=utils.projectsveltos.io +package v1beta1 + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/scheme" +) + +var ( + // GroupVersion is group version used to register these objects + GroupVersion = schema.GroupVersion{Group: "utils.projectsveltos.io", Version: "v1beta1"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} + + // AddToScheme adds the types in this group-version to the given scheme. + AddToScheme = SchemeBuilder.AddToScheme +) diff --git a/api/v1beta1/snapshot_conversion.go b/api/v1beta1/snapshot_conversion.go new file mode 100644 index 00000000..7825bb56 --- /dev/null +++ b/api/v1beta1/snapshot_conversion.go @@ -0,0 +1,20 @@ +/* +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 + +// Hub marks this type as a conversion hub. +func (*Snapshot) Hub() {} diff --git a/api/v1beta1/snapshot_types.go b/api/v1beta1/snapshot_types.go new file mode 100644 index 00000000..00cd24f8 --- /dev/null +++ b/api/v1beta1/snapshot_types.go @@ -0,0 +1,96 @@ +/* +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 ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +const ( + // SnapshotFinalizer allows SnapshotReconciler to clean up resources associated with + // Snapshot instance before removing it from the apiserver. + SnapshotFinalizer = "snapshotfinalizer.projectsveltos.io" +) + +// SnapshotSpec defines the desired state of Snapshot +type SnapshotSpec 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"` + + // Storage represents directory where snapshots will be stored. + // It must be an existing directory. + // Snapshots will be stored in this directory in a subdirectory named + // with Snapshot instance name. + Storage string `json:"storage"` + + // The number of successful finished snapshots to retains. + // If specified, only SuccessfulSnapshotLimit will be retained. Once such + // number is reached, for any new successful snapshots, the oldest one is + // deleted. + // +optional + SuccessfulSnapshotLimit *int32 `json:"successfulSnapshotLimit,omitempty"` +} + +// SnapshotStatus defines the observed state of Snapshot +type SnapshotStatus struct { + // Information when next snapshot is scheduled + // +optional + NextScheduleTime *metav1.Time `json:"nextScheduleTime,omitempty"` + + // Information when was the last time a snapshot was successfully scheduled. + // +optional + LastRunTime *metav1.Time `json:"lastRunTime,omitempty"` + + // Status indicates what happened to last snapshot collection. + LastRunStatus *CollectionStatus `json:"lastRunStatus,omitempty"` + + // FailureMessage provides more information about the error, if + // any occurred + FailureMessage *string `json:"failureMessage,omitempty"` +} + +//+kubebuilder:object:root=true +//+kubebuilder:resource:path=snapshots,scope=Cluster +//+kubebuilder:subresource:status +//+kubebuilder:storageversion + +// Snapshot is the Schema for the snapshot API +type Snapshot struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec SnapshotSpec `json:"spec,omitempty"` + Status SnapshotStatus `json:"status,omitempty"` +} + +//+kubebuilder:object:root=true + +// SnapshotList contains a list of Snapshot +type SnapshotList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []Snapshot `json:"items"` +} + +func init() { + SchemeBuilder.Register(&Snapshot{}, &SnapshotList{}) +} diff --git a/api/v1beta1/techsupport_conversion.go b/api/v1beta1/techsupport_conversion.go new file mode 100644 index 00000000..6e358b20 --- /dev/null +++ b/api/v1beta1/techsupport_conversion.go @@ -0,0 +1,20 @@ +/* +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 + +// Hub marks this type as a conversion hub. +func (*Techsupport) Hub() {} diff --git a/api/v1beta1/techsupport_types.go b/api/v1beta1/techsupport_types.go new file mode 100644 index 00000000..64b79a19 --- /dev/null +++ b/api/v1beta1/techsupport_types.go @@ -0,0 +1,156 @@ +/* +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" + + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" +) + +const ( + // TechsupportFinalizer allows TechsupportReconciler to clean up resources associated with + // Techsupport instance before removing it from the apiserver. + TechsupportFinalizer = "techsupportfinalizer.projectsveltos.io" +) + +// Resource indicates the type of resources to collect. +type Resource struct { + // Namespace of the resource deployed in the Cluster. + // Empty for resources scoped at cluster level. + // +optional + Namespace string `json:"namespace,omitempty"` + + // Group of the resource deployed in the Cluster. + Group string `json:"group"` + + // Version of the resource deployed in the Cluster. + Version string `json:"version"` + + // Kind of the resource deployed in the Cluster. + // +kubebuilder:validation:MinLength=1 + Kind string `json:"kind"` + + // LabelFilters allows to filter resources based on current labels. + LabelFilters []libsveltosv1beta1.LabelFilter `json:"labelFilters,omitempty"` +} + +// LogFilter allows to select which logs to collect +type Log struct { + // Namespace of the pods deployed in the Cluster. + // +optional + Namespace string `json:"namespace,omitempty"` + + // LabelFilters allows to filter pods based on current labels. + LabelFilters []libsveltosv1beta1.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. + // If this value is in the future, no logs will be returned. Only one of sinceSeconds or sinceTime may be specified. + // +optional + SinceSeconds *int64 `json:"sinceSeconds,omitempty"` +} + +// TechsupportSpec defines the desired state of Techsupport +type TechsupportSpec struct { + // ClusterSelector identifies clusters to collect techsupport from. + ClusterSelector libsveltosv1beta1.Selector `json:"clusterSelector"` + + // Resources indicates what resorces to collect + // +optional + Resources []Resource `json:"resources,omitempty"` + + // Logs indicates what pods' log to collect + // +optional + Logs []Log `json:"logs,omitempty"` + + // If set denerates a tar file with all collected logs/resources + // +kubebuilder:default:=false + // +optional + Tar bool `json:"tar,omitempty"` + + // 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"` + + // Storage represents directory where techsupports will be stored. + // It must be an existing directory. + // Techsupports will be stored in this directory in a subdirectory named + // with Techsupport instance name. + Storage string `json:"storage"` + + // The number of successful finished techsupport to retains. + // If specified, only SuccessfulTechsupportLimit will be retained. Once such + // number is reached, for any new successful snapshots, the oldest one is + // deleted. + // +optional + SuccessfulTechsupportLimit *int32 `json:"successfulTechsupportLimit,omitempty"` +} + +// TechsupportStatus defines the observed state of Techsupport +type TechsupportStatus struct { + // Information when next snapshot is scheduled + // +optional + NextScheduleTime *metav1.Time `json:"nextScheduleTime,omitempty"` + + // Information when was the last time a snapshot 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"` + + // MatchingClusterRefs reference all the clusters currently matching + // Techsupport + MatchingClusterRefs []corev1.ObjectReference `json:"machingClusters,omitempty"` +} + +//+kubebuilder:object:root=true +//+kubebuilder:resource:path=techsupports,scope=Cluster +//+kubebuilder:subresource:status +//+kubebuilder:storageversion + +// Techsupport is the Schema for the snapshot 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{}) +} diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go new file mode 100644 index 00000000..2987fadc --- /dev/null +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -0,0 +1,327 @@ +//go:build !ignore_autogenerated + +/* +Copyright 2022. 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. +*/ + +// Code generated by controller-gen. DO NOT EDIT. + +package v1beta1 + +import ( + v1 "k8s.io/api/core/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + + apiv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Log) DeepCopyInto(out *Log) { + *out = *in + if in.LabelFilters != nil { + in, out := &in.LabelFilters, &out.LabelFilters + *out = make([]apiv1beta1.LabelFilter, len(*in)) + copy(*out, *in) + } + if in.SinceSeconds != nil { + in, out := &in.SinceSeconds, &out.SinceSeconds + *out = new(int64) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Log. +func (in *Log) DeepCopy() *Log { + if in == nil { + return nil + } + out := new(Log) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Resource) DeepCopyInto(out *Resource) { + *out = *in + if in.LabelFilters != nil { + in, out := &in.LabelFilters, &out.LabelFilters + *out = make([]apiv1beta1.LabelFilter, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Resource. +func (in *Resource) DeepCopy() *Resource { + if in == nil { + return nil + } + out := new(Resource) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Snapshot) DeepCopyInto(out *Snapshot) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Snapshot. +func (in *Snapshot) DeepCopy() *Snapshot { + if in == nil { + return nil + } + out := new(Snapshot) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Snapshot) 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 *SnapshotList) DeepCopyInto(out *SnapshotList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Snapshot, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SnapshotList. +func (in *SnapshotList) DeepCopy() *SnapshotList { + if in == nil { + return nil + } + out := new(SnapshotList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *SnapshotList) 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 *SnapshotSpec) DeepCopyInto(out *SnapshotSpec) { + *out = *in + if in.StartingDeadlineSeconds != nil { + in, out := &in.StartingDeadlineSeconds, &out.StartingDeadlineSeconds + *out = new(int64) + **out = **in + } + if in.SuccessfulSnapshotLimit != nil { + in, out := &in.SuccessfulSnapshotLimit, &out.SuccessfulSnapshotLimit + *out = new(int32) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SnapshotSpec. +func (in *SnapshotSpec) DeepCopy() *SnapshotSpec { + if in == nil { + return nil + } + out := new(SnapshotSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SnapshotStatus) DeepCopyInto(out *SnapshotStatus) { + *out = *in + if in.NextScheduleTime != nil { + in, out := &in.NextScheduleTime, &out.NextScheduleTime + *out = (*in).DeepCopy() + } + if in.LastRunTime != nil { + in, out := &in.LastRunTime, &out.LastRunTime + *out = (*in).DeepCopy() + } + if in.LastRunStatus != nil { + in, out := &in.LastRunStatus, &out.LastRunStatus + *out = new(CollectionStatus) + **out = **in + } + if in.FailureMessage != nil { + in, out := &in.FailureMessage, &out.FailureMessage + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SnapshotStatus. +func (in *SnapshotStatus) DeepCopy() *SnapshotStatus { + if in == nil { + return nil + } + out := new(SnapshotStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Techsupport) DeepCopyInto(out *Techsupport) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Techsupport. +func (in *Techsupport) DeepCopy() *Techsupport { + if in == nil { + return nil + } + out := new(Techsupport) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Techsupport) 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 *TechsupportList) DeepCopyInto(out *TechsupportList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Techsupport, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TechsupportList. +func (in *TechsupportList) DeepCopy() *TechsupportList { + if in == nil { + return nil + } + out := new(TechsupportList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TechsupportList) 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 *TechsupportSpec) DeepCopyInto(out *TechsupportSpec) { + *out = *in + in.ClusterSelector.DeepCopyInto(&out.ClusterSelector) + if in.Resources != nil { + in, out := &in.Resources, &out.Resources + *out = make([]Resource, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Logs != nil { + in, out := &in.Logs, &out.Logs + *out = make([]Log, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.StartingDeadlineSeconds != nil { + in, out := &in.StartingDeadlineSeconds, &out.StartingDeadlineSeconds + *out = new(int64) + **out = **in + } + if in.SuccessfulTechsupportLimit != nil { + in, out := &in.SuccessfulTechsupportLimit, &out.SuccessfulTechsupportLimit + *out = new(int32) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TechsupportSpec. +func (in *TechsupportSpec) DeepCopy() *TechsupportSpec { + if in == nil { + return nil + } + out := new(TechsupportSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TechsupportStatus) DeepCopyInto(out *TechsupportStatus) { + *out = *in + if in.NextScheduleTime != nil { + in, out := &in.NextScheduleTime, &out.NextScheduleTime + *out = (*in).DeepCopy() + } + if in.LastRunTime != nil { + in, out := &in.LastRunTime, &out.LastRunTime + *out = (*in).DeepCopy() + } + if in.LastRunStatus != nil { + in, out := &in.LastRunStatus, &out.LastRunStatus + *out = new(CollectionStatus) + **out = **in + } + if in.FailureMessage != nil { + in, out := &in.FailureMessage, &out.FailureMessage + *out = new(string) + **out = **in + } + if in.MatchingClusterRefs != nil { + in, out := &in.MatchingClusterRefs, &out.MatchingClusterRefs + *out = make([]v1.ObjectReference, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TechsupportStatus. +func (in *TechsupportStatus) DeepCopy() *TechsupportStatus { + if in == nil { + return nil + } + out := new(TechsupportStatus) + in.DeepCopyInto(out) + return out +} diff --git a/config/crd/bases/utils.projectsveltos.io_snapshots.yaml b/config/crd/bases/utils.projectsveltos.io_snapshots.yaml index 8aeca693..0b3a7dac 100644 --- a/config/crd/bases/utils.projectsveltos.io_snapshots.yaml +++ b/config/crd/bases/utils.projectsveltos.io_snapshots.yaml @@ -15,6 +15,89 @@ spec: scope: Cluster versions: - name: v1alpha1 + schema: + openAPIV3Schema: + description: Snapshot is the Schema for the snapshot API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: SnapshotSpec defines the desired state of Snapshot + properties: + schedule: + description: Schedule in Cron format, see https://en.wikipedia.org/wiki/Cron. + type: string + startingDeadlineSeconds: + description: |- + 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. + format: int64 + type: integer + storage: + description: |- + Storage represents directory where snapshots will be stored. + It must be an existing directory. + Snapshots will be stored in this directory in a subdirectory named + with Snapshot instance name. + type: string + successfulSnapshotLimit: + description: |- + The number of successful finished snapshots to retains. + If specified, only SuccessfulSnapshotLimit will be retained. Once such + number is reached, for any new successful snapshots, the oldest one is + deleted. + format: int32 + type: integer + required: + - schedule + - storage + type: object + status: + description: SnapshotStatus defines the observed state of Snapshot + properties: + failureMessage: + description: |- + FailureMessage provides more information about the error, if + any occurred + type: string + lastRunStatus: + description: Status indicates what happened to last snapshot collection. + enum: + - Collected + - InProgress + - Failed + type: string + lastRunTime: + description: Information when was the last time a snapshot was successfully + scheduled. + format: date-time + type: string + nextScheduleTime: + description: Information when next snapshot is scheduled + format: date-time + type: string + type: object + type: object + served: true + storage: false + subresources: + status: {} + - name: v1beta1 schema: openAPIV3Schema: description: Snapshot is the Schema for the snapshot API diff --git a/config/crd/bases/utils.projectsveltos.io_techsupports.yaml b/config/crd/bases/utils.projectsveltos.io_techsupports.yaml index 92c16765..36e8d16b 100644 --- a/config/crd/bases/utils.projectsveltos.io_techsupports.yaml +++ b/config/crd/bases/utils.projectsveltos.io_techsupports.yaml @@ -206,6 +206,296 @@ spec: will affect numerous schemas. Don't make new APIs embed an underspecified API type they do not control. + Instead of using this type, create a locally provided and used type that is well-focused on your reference. + For example, ServiceReferences for admission registration: https://github.com/kubernetes/api/blob/release-1.17/admissionregistration/v1/types.go#L533 . + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: |- + If referring to a piece of an object instead of an entire object, this string + should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container within a pod, this would take on a value like: + "spec.containers{name}" (where "name" refers to the name of the container that triggered + the event) or if no container name is specified "spec.containers[2]" (container with + index 2 in this pod). This syntax is chosen only to have some well-defined way of + referencing a part of an object. + TODO: this design is not final and this field is subject to change in the future. + type: string + kind: + description: |- + Kind of the referent. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + namespace: + description: |- + Namespace of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ + type: string + resourceVersion: + description: |- + Specific resourceVersion to which this reference is made, if any. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency + type: string + uid: + description: |- + UID of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids + type: string + type: object + x-kubernetes-map-type: atomic + type: array + nextScheduleTime: + description: Information when next snapshot is scheduled + format: date-time + type: string + type: object + type: object + served: true + storage: false + subresources: + status: {} + - name: v1beta1 + schema: + openAPIV3Schema: + description: Techsupport is the Schema for the snapshot API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: TechsupportSpec defines the desired state of Techsupport + properties: + clusterSelector: + description: ClusterSelector identifies clusters to collect techsupport + from. + properties: + matchExpressions: + description: matchExpressions is a list of label selector requirements. + The requirements are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key that the selector applies + to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + logs: + description: Logs indicates what pods' log to collect + items: + description: LogFilter allows to select which logs to collect + properties: + labelFilters: + description: LabelFilters allows to filter pods based on current + labels. + items: + properties: + key: + description: Key is the label key + type: string + operation: + description: Operation is the comparison operation + enum: + - Equal + - Different + type: string + value: + description: Value is the label value + type: string + required: + - key + - operation + - value + type: object + type: array + namespace: + description: Namespace of the pods deployed in the Cluster. + type: string + sinceSeconds: + description: |- + 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. + If this value is in the future, no logs will be returned. Only one of sinceSeconds or sinceTime may be specified. + format: int64 + type: integer + type: object + type: array + resources: + description: Resources indicates what resorces to collect + items: + description: Resource indicates the type of resources to collect. + properties: + group: + description: Group of the resource deployed in the Cluster. + type: string + kind: + description: Kind of the resource deployed in the Cluster. + minLength: 1 + type: string + labelFilters: + description: LabelFilters allows to filter resources based on + current labels. + items: + properties: + key: + description: Key is the label key + type: string + operation: + description: Operation is the comparison operation + enum: + - Equal + - Different + type: string + value: + description: Value is the label value + type: string + required: + - key + - operation + - value + type: object + type: array + namespace: + description: |- + Namespace of the resource deployed in the Cluster. + Empty for resources scoped at cluster level. + type: string + version: + description: Version of the resource deployed in the Cluster. + type: string + required: + - group + - kind + - version + type: object + type: array + schedule: + description: Schedule in Cron format, see https://en.wikipedia.org/wiki/Cron. + type: string + startingDeadlineSeconds: + description: |- + 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. + format: int64 + type: integer + storage: + description: |- + Storage represents directory where techsupports will be stored. + It must be an existing directory. + Techsupports will be stored in this directory in a subdirectory named + with Techsupport instance name. + type: string + successfulTechsupportLimit: + description: |- + The number of successful finished techsupport to retains. + If specified, only SuccessfulTechsupportLimit will be retained. Once such + number is reached, for any new successful snapshots, the oldest one is + deleted. + format: int32 + type: integer + tar: + default: false + description: If set denerates a tar file with all collected logs/resources + type: boolean + required: + - clusterSelector + - schedule + - storage + type: object + status: + description: TechsupportStatus defines the observed state of Techsupport + properties: + failureMessage: + description: |- + FailureMessage provides more information about the error, if + any occurred + type: string + lastRunStatus: + description: Status indicates what happened to last techsupport collection. + enum: + - Collected + - InProgress + - Failed + type: string + lastRunTime: + description: Information when was the last time a snapshot was successfully + scheduled. + format: date-time + type: string + machingClusters: + description: |- + MatchingClusterRefs reference all the clusters currently matching + Techsupport + items: + description: |- + ObjectReference contains enough information to let you inspect or modify the referred object. + --- + New uses of this type are discouraged because of difficulty describing its usage when embedded in APIs. + 1. Ignored fields. It includes many fields which are not generally honored. For instance, ResourceVersion and FieldPath are both very rarely valid in actual usage. + 2. Invalid usage help. It is impossible to add specific help for individual usage. In most embedded usages, there are particular + restrictions like, "must refer only to types A and B" or "UID not honored" or "name must be restricted". + Those cannot be well described when embedded. + 3. Inconsistent validation. Because the usages are different, the validation rules are different by usage, which makes it hard for users to predict what will happen. + 4. The fields are both imprecise and overly precise. Kind is not a precise mapping to a URL. This can produce ambiguity + during interpretation and require a REST mapping. In most cases, the dependency is on the group,resource tuple + and the version of the actual struct is irrelevant. + 5. We cannot easily change it. Because this type is embedded in many locations, updates to this type + will affect numerous schemas. Don't make new APIs embed an underspecified API type they do not control. + + Instead of using this type, create a locally provided and used type that is well-focused on your reference. For example, ServiceReferences for admission registration: https://github.com/kubernetes/api/blob/release-1.17/admissionregistration/v1/types.go#L533 . properties: diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml new file mode 100644 index 00000000..64a626d8 --- /dev/null +++ b/config/crd/kustomization.yaml @@ -0,0 +1,22 @@ +# This kustomization.yaml is not intended to be run by itself, +# since it depends on service name and namespace that are out of this kustomize package. +# It should be run by config/default +resources: +- bases/utils.projectsveltos.io_techsupports.yaml +- bases/utils.projectsveltos.io_snapshots.yaml +#+kubebuilder:scaffold:crdkustomizeresource + +patches: +# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix. +# patches here are for enabling the conversion webhook for each CRD +- path: patches/webhook_in_techsupports.yaml +#+kubebuilder:scaffold:crdkustomizewebhookpatch + +# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix. +# patches here are for enabling the CA injection for each CRD +- path: patches/cainjection_in_techsupports.yaml +#+kubebuilder:scaffold:crdkustomizecainjectionpatch + +# the following config is for teaching kustomize how to do kustomization for CRDs. +configurations: +- kustomizeconfig.yaml diff --git a/config/crd/kustomizeconfig.yaml b/config/crd/kustomizeconfig.yaml new file mode 100644 index 00000000..ec5c150a --- /dev/null +++ b/config/crd/kustomizeconfig.yaml @@ -0,0 +1,19 @@ +# This file is for teaching kustomize how to substitute name and namespace reference in CRD +nameReference: +- kind: Service + version: v1 + fieldSpecs: + - kind: CustomResourceDefinition + version: v1 + group: apiextensions.k8s.io + path: spec/conversion/webhook/clientConfig/service/name + +namespace: +- kind: CustomResourceDefinition + version: v1 + group: apiextensions.k8s.io + path: spec/conversion/webhook/clientConfig/service/namespace + create: false + +varReference: +- path: metadata/annotations diff --git a/config/crd/patches/cainjection_in_snapshots.yaml b/config/crd/patches/cainjection_in_snapshots.yaml new file mode 100644 index 00000000..50345f2e --- /dev/null +++ b/config/crd/patches/cainjection_in_snapshots.yaml @@ -0,0 +1,7 @@ +# The following patch adds a directive for certmanager to inject CA into the CRD +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) + name: snapshots.utils.projectsveltos.io diff --git a/config/crd/patches/cainjection_in_techsupports.yaml b/config/crd/patches/cainjection_in_techsupports.yaml new file mode 100644 index 00000000..e81d923f --- /dev/null +++ b/config/crd/patches/cainjection_in_techsupports.yaml @@ -0,0 +1,7 @@ +# The following patch adds a directive for certmanager to inject CA into the CRD +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + cert-manager.io/inject-ca-from: projectsveltos/projectsveltos-serving-cert # this is hardcoded with conversion-webhook repo + name: techsupports.utils.projectsveltos.io diff --git a/config/crd/patches/webhook_in_techsupports.yaml b/config/crd/patches/webhook_in_techsupports.yaml new file mode 100644 index 00000000..5d119dee --- /dev/null +++ b/config/crd/patches/webhook_in_techsupports.yaml @@ -0,0 +1,16 @@ +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: techsupports.utils.projectsveltos.io +spec: + conversion: + strategy: Webhook + webhook: + clientConfig: + service: + namespace: projectsveltos + name: webhook-service + path: /convert + conversionReviewVersions: + - v1 diff --git a/config/default/kustomization.yaml b/config/default/kustomization.yaml new file mode 100644 index 00000000..ee164e17 --- /dev/null +++ b/config/default/kustomization.yaml @@ -0,0 +1,65 @@ +# Adds namespace to all resources. +namespace: projectsveltos + +# Value of this field is prepended to the +# names of all resources, e.g. a deployment named +# "wordpress" becomes "alices-wordpress". +# Note that it should also match with the prefix (text before '-') of the namespace +# field above. +namePrefix: sveltosctl- + +# Labels to add to all resources and selectors. +#commonLabels: +# someName: someValue + +resources: +- ../crd +# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in +# crd/kustomization.yaml +#- ../webhook +# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required. +#- ../certmanager +# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'. +#- ../prometheus + +patches: + + +# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in +# crd/kustomization.yaml +#- manager_webhook_patch.yaml + +# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. +# Uncomment 'CERTMANAGER' sections in crd/kustomization.yaml to enable the CA injection in the admission webhooks. +# 'CERTMANAGER' needs to be enabled to use ca injection +#- webhookcainjection_patch.yaml + +# the following config is for teaching kustomize how to do var substitution +vars: +# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix. +#- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR +# objref: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert # this name should match the one in certificate.yaml +# fieldref: +# fieldpath: metadata.namespace +#- name: CERTIFICATE_NAME +# objref: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert # this name should match the one in certificate.yaml +#- name: SERVICE_NAMESPACE # namespace of the service +# objref: +# kind: Service +# version: v1 +# name: webhook-service +# fieldref: +# fieldpath: metadata.namespace +#- name: SERVICE_NAME +# objref: +# kind: Service +# version: v1 +# name: webhook-service diff --git a/go.mod b/go.mod index e188d3c4..a9f3f65c 100644 --- a/go.mod +++ b/go.mod @@ -12,17 +12,17 @@ require ( github.com/onsi/ginkgo/v2 v2.19.0 github.com/onsi/gomega v1.33.1 github.com/pkg/errors v0.9.1 - github.com/projectsveltos/addon-controller v0.32.1-0.20240611173725-4d8403710b08 - github.com/projectsveltos/event-manager v0.32.1-0.20240611185106-669cd9050c03 - github.com/projectsveltos/libsveltos v0.32.1-0.20240611141238-c8675b616482 + github.com/projectsveltos/addon-controller v0.33.1-0.20240705125553-0befa1b74158 + github.com/projectsveltos/event-manager v0.33.1-0.20240705132126-4d256b7478af + github.com/projectsveltos/libsveltos v0.33.1-0.20240704143403-57a4cb3560e3 github.com/robfig/cron/v3 v3.0.1 gopkg.in/yaml.v2 v2.4.0 - k8s.io/api v0.30.1 - k8s.io/apiextensions-apiserver v0.30.1 - k8s.io/apimachinery v0.30.1 - k8s.io/client-go v0.30.1 - k8s.io/klog/v2 v2.120.1 - k8s.io/kubectl v0.30.1 + k8s.io/api v0.30.2 + k8s.io/apiextensions-apiserver v0.30.2 + k8s.io/apimachinery v0.30.2 + k8s.io/client-go v0.30.2 + k8s.io/klog/v2 v2.130.1 + k8s.io/kubectl v0.30.2 sigs.k8s.io/cluster-api v1.7.3 sigs.k8s.io/controller-runtime v0.18.4 sigs.k8s.io/yaml v1.4.0 @@ -31,14 +31,14 @@ require ( require ( github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect - github.com/BurntSushi/toml v1.3.2 // indirect + github.com/BurntSushi/toml v1.4.0 // indirect github.com/MakeNowJust/heredoc v1.0.0 // indirect github.com/Masterminds/goutils v1.1.1 // indirect github.com/Masterminds/semver/v3 v3.2.1 // indirect github.com/Masterminds/sprig/v3 v3.2.3 // indirect github.com/Masterminds/squirrel v1.5.4 // indirect github.com/Microsoft/hcsshim v0.11.4 // indirect - github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect + github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/blang/semver/v4 v4.0.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect @@ -48,13 +48,13 @@ require ( github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/dariubs/percent v1.0.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/docker/cli v24.0.6+incompatible // indirect - github.com/docker/distribution v2.8.2+incompatible // indirect - github.com/docker/docker v24.0.9+incompatible // indirect + github.com/distribution/reference v0.5.0 // indirect + github.com/docker/cli v25.0.1+incompatible // indirect + github.com/docker/distribution v2.8.3+incompatible // indirect + github.com/docker/docker v25.0.5+incompatible // indirect github.com/docker/docker-credential-helpers v0.7.0 // indirect - github.com/docker/go-connections v0.4.0 // indirect + github.com/docker/go-connections v0.5.0 // indirect github.com/docker/go-metrics v0.0.1 // indirect - github.com/docker/go-units v0.5.0 // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/evanphx/json-patch v5.7.0+incompatible // indirect github.com/evanphx/json-patch/v5 v5.9.0 // indirect @@ -118,12 +118,11 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect - github.com/morikuni/aec v1.0.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/go-digest/blake3 v0.0.0-20231025023718-d50d2fec9c98 // indirect - github.com/opencontainers/image-spec v1.1.0-rc5 // indirect + github.com/opencontainers/image-spec v1.1.0-rc6 // indirect github.com/peterbourgon/diskv v2.0.1+incompatible // indirect github.com/prometheus/client_golang v1.19.1 // indirect github.com/prometheus/client_model v0.5.0 // indirect @@ -166,13 +165,13 @@ require ( gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - helm.sh/helm/v3 v3.15.1 // indirect - k8s.io/apiserver v0.30.1 // indirect - k8s.io/cli-runtime v0.30.1 // indirect - k8s.io/component-base v0.30.1 // indirect + helm.sh/helm/v3 v3.15.2 // indirect + k8s.io/apiserver v0.30.2 // indirect + k8s.io/cli-runtime v0.30.2 // indirect + k8s.io/component-base v0.30.2 // indirect k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 // indirect - oras.land/oras-go v1.2.4 // indirect + oras.land/oras-go v1.2.5 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/kustomize/api v0.17.2 // indirect sigs.k8s.io/kustomize/kyaml v0.17.1 // indirect diff --git a/go.sum b/go.sum index afeda7d2..7fd62c77 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,8 @@ github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= -github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= +github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU= github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU= github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ= @@ -31,8 +31,8 @@ github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df h github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= -github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so= -github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= +github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 h1:4daAzAu0S6Vi7/lbWECcX0j45yZReDZ56BQsrVBOEEY= +github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535/go.mod h1:oGkLhpf+kjZl6xBf758TQhh5XrAeiJv/7FRz/2spLIg= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -84,22 +84,20 @@ github.com/distribution/distribution/v3 v3.0.0-20221208165359-362910506bc2 h1:aB github.com/distribution/distribution/v3 v3.0.0-20221208165359-362910506bc2/go.mod h1:WHNsWjnIn2V1LYOrME7e8KxSeKunYHsxEm4am0BUtcI= github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0= github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= -github.com/docker/cli v24.0.6+incompatible h1:fF+XCQCgJjjQNIMjzaSmiKJSCcfcXb3TWTcc7GAneOY= -github.com/docker/cli v24.0.6+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= -github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8= -github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v24.0.9+incompatible h1:HPGzNmwfLZWdxHqK9/II92pyi1EpYKsAqcl4G0Of9v0= -github.com/docker/docker v24.0.9+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/cli v25.0.1+incompatible h1:mFpqnrS6Hsm3v1k7Wa/BO23oz0k121MTbTO1lpcGSkU= +github.com/docker/cli v25.0.1+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= +github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk= +github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= +github.com/docker/docker v25.0.5+incompatible h1:UmQydMduGkrD5nQde1mecF/YnSbTOaPeFIeP5C4W+DE= +github.com/docker/docker v25.0.5+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker-credential-helpers v0.7.0 h1:xtCHsjxogADNZcdv1pKUHXryefjlVRqWqIhk/uXJp0A= github.com/docker/docker-credential-helpers v0.7.0/go.mod h1:rETQfLdHNT3foU5kuNkFR1R1V12OJRRO5lzt2D1b5X0= -github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= -github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= +github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c= +github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c h1:+pKlWGMw7gf6bQ+oDZB4KHQFypsfjYlq/C4rfL7D3g8= github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c/go.mod h1:Uw6UezgYA44ePAFQYUehOuCzmy5zmg/+nl2ZfMWGkpA= github.com/docker/go-metrics v0.0.1 h1:AgB/0SvBxihN0X8OR4SjsblXkbMvalQ8cjmtKQ2rQV8= github.com/docker/go-metrics v0.0.1/go.mod h1:cG1hvH2utMXtqgqqYE9plW6lDxS3/5ayHzueweSI3Vw= -github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= -github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1 h1:ZClxb8laGDf5arXfYcAtECDFgAgHklGI8CxgjHnXKJ4= github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 h1:bWDMxwH3px2JBh6AyO7hdCn/PkvCZXii8TGj7sbtEbQ= @@ -336,8 +334,6 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0= github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4= -github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= -github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= @@ -353,8 +349,8 @@ github.com/opencontainers/go-digest v1.0.1-0.20220411205349-bde1400a84be h1:f2Pl github.com/opencontainers/go-digest v1.0.1-0.20220411205349-bde1400a84be/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/go-digest/blake3 v0.0.0-20231025023718-d50d2fec9c98 h1:LTxrNWOPwquJy9Cu3oz6QHJIO5M5gNyOZtSybXdyLA4= github.com/opencontainers/go-digest/blake3 v0.0.0-20231025023718-d50d2fec9c98/go.mod h1:kqQaIc6bZstKgnGpL7GD5dWoLKbA6mH1Y9ULjGImBnM= -github.com/opencontainers/image-spec v1.1.0-rc5 h1:Ygwkfw9bpDvs+c9E34SdgGOj41dX/cbdlwvlWt0pnFI= -github.com/opencontainers/image-spec v1.1.0-rc5/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8= +github.com/opencontainers/image-spec v1.1.0-rc6 h1:XDqvyKsJEbRtATzkgItUqBA7QHk58yxX1Ov9HERHNqU= +github.com/opencontainers/image-spec v1.1.0-rc6/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM= github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5 h1:Ii+DKncOVM8Cu1Hc+ETb5K+23HdAMvESYE3ZJ5b5cMI= @@ -367,12 +363,12 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/poy/onpar v1.1.2 h1:QaNrNiZx0+Nar5dLgTVp5mXkyoVFIbepjyEoGSnhbAY= github.com/poy/onpar v1.1.2/go.mod h1:6X8FLNoxyr9kkmnlqpK6LSoiOtrO6MICtWwEuWkLjzg= -github.com/projectsveltos/addon-controller v0.32.1-0.20240611173725-4d8403710b08 h1:/7DEMm00hnLaqPrV9sNY7BKqnXU2dQGPk8XzoE9AFdE= -github.com/projectsveltos/addon-controller v0.32.1-0.20240611173725-4d8403710b08/go.mod h1:VP2FHId1gPANxpBIrN3b6qMcV5HcjVnNuJQI22xspwk= -github.com/projectsveltos/event-manager v0.32.1-0.20240611185106-669cd9050c03 h1:5FGj69I4U6vcQIMK5AQGAulFS1x7c0ufL/sjFYKCJE0= -github.com/projectsveltos/event-manager v0.32.1-0.20240611185106-669cd9050c03/go.mod h1:udPJLkj9NZuF60LUOzSZpnt+HFwTiQLpA0QzCFWbv/Y= -github.com/projectsveltos/libsveltos v0.32.1-0.20240611141238-c8675b616482 h1:FSLwV0I/Z4mzcfY+iP46bz1CT07AMzK34xXdPm7Fahs= -github.com/projectsveltos/libsveltos v0.32.1-0.20240611141238-c8675b616482/go.mod h1:z6avfRqeHbzqkThyqqqoGcCWMI0JBeAjdeZlbJ7P8TI= +github.com/projectsveltos/addon-controller v0.33.1-0.20240705125553-0befa1b74158 h1:SQMrXsYMdwPGcbOVop/k79iR/2Ngg69pl0MG7OZ3saw= +github.com/projectsveltos/addon-controller v0.33.1-0.20240705125553-0befa1b74158/go.mod h1:UYDb/D7rJr6ZpsSyGcS9ioIJfwoNn9/vQrfcl4bfPs4= +github.com/projectsveltos/event-manager v0.33.1-0.20240705132126-4d256b7478af h1:GB0up7Bx3ChS5MlEw79NPwtObuZjzo0agIaMj/CIskA= +github.com/projectsveltos/event-manager v0.33.1-0.20240705132126-4d256b7478af/go.mod h1:Eiu4HH8YMEMEYNCw4ilt3iP/9UqaMZqMalXvDUS83W0= +github.com/projectsveltos/libsveltos v0.33.1-0.20240704143403-57a4cb3560e3 h1:FQaAXI+9K4SHLgWxV8OMEV1b/IO9G9/oIvM4p3v90og= +github.com/projectsveltos/libsveltos v0.33.1-0.20240704143403-57a4cb3560e3/go.mod h1:GRQ9Otq55Aii1icSvkrTjyDOniBZjYVA5018BRpMvdA= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g= @@ -623,36 +619,36 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g= -helm.sh/helm/v3 v3.15.1 h1:22ztacHz4gMqhXNqCQ9NAg6BFWoRUryNLvnkz6OVyw0= -helm.sh/helm/v3 v3.15.1/go.mod h1:fvfoRcB8UKRUV5jrIfOTaN/pG1TPhuqSb56fjYdTKXg= +helm.sh/helm/v3 v3.15.2 h1:/3XINUFinJOBjQplGnjw92eLGpgXXp1L8chWPkCkDuw= +helm.sh/helm/v3 v3.15.2/go.mod h1:FzSIP8jDQaa6WAVg9F+OkKz7J0ZmAga4MABtTbsb9WQ= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -k8s.io/api v0.30.1 h1:kCm/6mADMdbAxmIh0LBjS54nQBE+U4KmbCfIkF5CpJY= -k8s.io/api v0.30.1/go.mod h1:ddbN2C0+0DIiPntan/bye3SW3PdwLa11/0yqwvuRrJM= -k8s.io/apiextensions-apiserver v0.30.1 h1:4fAJZ9985BmpJG6PkoxVRpXv9vmPUOVzl614xarePws= -k8s.io/apiextensions-apiserver v0.30.1/go.mod h1:R4GuSrlhgq43oRY9sF2IToFh7PVlF1JjfWdoG3pixk4= -k8s.io/apimachinery v0.30.1 h1:ZQStsEfo4n65yAdlGTfP/uSHMQSoYzU/oeEbkmF7P2U= -k8s.io/apimachinery v0.30.1/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc= -k8s.io/apiserver v0.30.1 h1:BEWEe8bzS12nMtDKXzCF5Q5ovp6LjjYkSp8qOPk8LZ8= -k8s.io/apiserver v0.30.1/go.mod h1:i87ZnQ+/PGAmSbD/iEKM68bm1D5reX8fO4Ito4B01mo= -k8s.io/cli-runtime v0.30.1 h1:kSBBpfrJGS6lllc24KeniI9JN7ckOOJKnmFYH1RpTOw= -k8s.io/cli-runtime v0.30.1/go.mod h1:zhHgbqI4J00pxb6gM3gJPVf2ysDjhQmQtnTxnMScab8= -k8s.io/client-go v0.30.1 h1:uC/Ir6A3R46wdkgCV3vbLyNOYyCJ8oZnjtJGKfytl/Q= -k8s.io/client-go v0.30.1/go.mod h1:wrAqLNs2trwiCH/wxxmT/x3hKVH9PuV0GGW0oDoHVqc= +k8s.io/api v0.30.2 h1:+ZhRj+28QT4UOH+BKznu4CBgPWgkXO7XAvMcMl0qKvI= +k8s.io/api v0.30.2/go.mod h1:ULg5g9JvOev2dG0u2hig4Z7tQ2hHIuS+m8MNZ+X6EmI= +k8s.io/apiextensions-apiserver v0.30.2 h1:l7Eue2t6QiLHErfn2vwK4KgF4NeDgjQkCXtEbOocKIE= +k8s.io/apiextensions-apiserver v0.30.2/go.mod h1:lsJFLYyK40iguuinsb3nt+Sj6CmodSI4ACDLep1rgjw= +k8s.io/apimachinery v0.30.2 h1:fEMcnBj6qkzzPGSVsAZtQThU62SmQ4ZymlXRC5yFSCg= +k8s.io/apimachinery v0.30.2/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc= +k8s.io/apiserver v0.30.2 h1:ACouHiYl1yFI2VFI3YGM+lvxgy6ir4yK2oLOsLI1/tw= +k8s.io/apiserver v0.30.2/go.mod h1:BOTdFBIch9Sv0ypSEcUR6ew/NUFGocRFNl72Ra7wTm8= +k8s.io/cli-runtime v0.30.2 h1:ooM40eEJusbgHNEqnHziN9ZpLN5U4WcQGsdLKVxpkKE= +k8s.io/cli-runtime v0.30.2/go.mod h1:Y4g/2XezFyTATQUbvV5WaChoUGhojv/jZAtdp5Zkm0A= +k8s.io/client-go v0.30.2 h1:sBIVJdojUNPDU/jObC+18tXWcTJVcwyqS9diGdWHk50= +k8s.io/client-go v0.30.2/go.mod h1:JglKSWULm9xlJLx4KCkfLLQ7XwtlbflV6uFFSHTMgVs= k8s.io/cluster-bootstrap v0.29.3 h1:DIMDZSN8gbFMy9CS2mAS2Iqq/fIUG783WN/1lqi5TF8= k8s.io/cluster-bootstrap v0.29.3/go.mod h1:aPAg1VtXx3uRrx5qU2jTzR7p1rf18zLXWS+pGhiqPto= -k8s.io/component-base v0.30.1 h1:bvAtlPh1UrdaZL20D9+sWxsJljMi0QZ3Lmw+kmZAaxQ= -k8s.io/component-base v0.30.1/go.mod h1:e/X9kDiOebwlI41AvBHuWdqFriSRrX50CdwA9TFaHLI= -k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw= -k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= +k8s.io/component-base v0.30.2 h1:pqGBczYoW1sno8q9ObExUqrYSKhtE5rW3y6gX88GZII= +k8s.io/component-base v0.30.2/go.mod h1:yQLkQDrkK8J6NtP+MGJOws+/PPeEXNpwFixsUI7h/OE= +k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= +k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag= k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98= -k8s.io/kubectl v0.30.1 h1:sHFIRI3oP0FFZmBAVEE8ErjnTyXDPkBcvO88mH9RjuY= -k8s.io/kubectl v0.30.1/go.mod h1:7j+L0Cc38RYEcx+WH3y44jRBe1Q1jxdGPKkX0h4iDq0= +k8s.io/kubectl v0.30.2 h1:cgKNIvsOiufgcs4yjvgkK0+aPCfa8pUwzXdJtkbhsH8= +k8s.io/kubectl v0.30.2/go.mod h1:rz7GHXaxwnigrqob0lJsiA07Df8RE3n1TSaC2CTeuB4= k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 h1:jgGTlFYnhF1PM1Ax/lAlxUPE+KfCIXHaathvJg1C3ak= k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -oras.land/oras-go v1.2.4 h1:djpBY2/2Cs1PV87GSJlxv4voajVOMZxqqtq9AB8YNvY= -oras.land/oras-go v1.2.4/go.mod h1:DYcGfb3YF1nKjcezfX2SNlDAeQFKSXmf+qrFmrh4324= +oras.land/oras-go v1.2.5 h1:XpYuAwAb0DfQsunIyMfeET92emK8km3W4yEzZvUbsTo= +oras.land/oras-go v1.2.5/go.mod h1:PuAwRShRZCsZb7g8Ar3jKKQR/2A/qN+pkYxIOd/FAoo= sigs.k8s.io/cluster-api v1.7.3 h1:DsSRxsA+18jxLqPAo29abZ9kOPK1/xwhSuQb/MROzSs= sigs.k8s.io/cluster-api v1.7.3/go.mod h1:V9ZhKLvQtsDODwjXOKgbitjyCmC71yMBwDcMyNNIov0= sigs.k8s.io/controller-runtime v0.18.4 h1:87+guW1zhvuPLh1PHybKdYFLU0YJp4FhJRmiHvm5BZw= diff --git a/hack/boilerplate.generatego.txt b/hack/boilerplate.generatego.txt new file mode 100644 index 00000000..e332f2ab --- /dev/null +++ b/hack/boilerplate.generatego.txt @@ -0,0 +1,15 @@ +/* +Copyright The Kubernetes Authors. + +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. +*/ \ No newline at end of file diff --git a/hack/tools/go.mod b/hack/tools/go.mod index ed7d79e2..70b20455 100644 --- a/hack/tools/go.mod +++ b/hack/tools/go.mod @@ -5,7 +5,7 @@ go 1.22.0 require ( github.com/onsi/ginkgo/v2 v2.19.0 golang.org/x/oauth2 v0.21.0 - k8s.io/client-go v0.30.1 + k8s.io/client-go v0.30.2 sigs.k8s.io/controller-tools v0.15.0 sigs.k8s.io/kind v0.23.0 ) @@ -45,9 +45,9 @@ require ( gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/api v0.30.1 // indirect + k8s.io/api v0.30.2 // indirect k8s.io/apiextensions-apiserver v0.30.0 // indirect - k8s.io/apimachinery v0.30.1 // indirect + k8s.io/apimachinery v0.30.2 // indirect k8s.io/klog/v2 v2.120.1 // indirect k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect diff --git a/hack/tools/go.sum b/hack/tools/go.sum index 9dcd7c5c..1dd412c3 100644 --- a/hack/tools/go.sum +++ b/hack/tools/go.sum @@ -166,14 +166,14 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/api v0.30.1 h1:kCm/6mADMdbAxmIh0LBjS54nQBE+U4KmbCfIkF5CpJY= -k8s.io/api v0.30.1/go.mod h1:ddbN2C0+0DIiPntan/bye3SW3PdwLa11/0yqwvuRrJM= +k8s.io/api v0.30.2 h1:+ZhRj+28QT4UOH+BKznu4CBgPWgkXO7XAvMcMl0qKvI= +k8s.io/api v0.30.2/go.mod h1:ULg5g9JvOev2dG0u2hig4Z7tQ2hHIuS+m8MNZ+X6EmI= k8s.io/apiextensions-apiserver v0.30.0 h1:jcZFKMqnICJfRxTgnC4E+Hpcq8UEhT8B2lhBcQ+6uAs= k8s.io/apiextensions-apiserver v0.30.0/go.mod h1:N9ogQFGcrbWqAY9p2mUAL5mGxsLqwgtUce127VtRX5Y= -k8s.io/apimachinery v0.30.1 h1:ZQStsEfo4n65yAdlGTfP/uSHMQSoYzU/oeEbkmF7P2U= -k8s.io/apimachinery v0.30.1/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc= -k8s.io/client-go v0.30.1 h1:uC/Ir6A3R46wdkgCV3vbLyNOYyCJ8oZnjtJGKfytl/Q= -k8s.io/client-go v0.30.1/go.mod h1:wrAqLNs2trwiCH/wxxmT/x3hKVH9PuV0GGW0oDoHVqc= +k8s.io/apimachinery v0.30.2 h1:fEMcnBj6qkzzPGSVsAZtQThU62SmQ4ZymlXRC5yFSCg= +k8s.io/apimachinery v0.30.2/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc= +k8s.io/client-go v0.30.2 h1:sBIVJdojUNPDU/jObC+18tXWcTJVcwyqS9diGdWHk50= +k8s.io/client-go v0.30.2/go.mod h1:JglKSWULm9xlJLx4KCkfLLQ7XwtlbflV6uFFSHTMgVs= k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw= k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag= diff --git a/internal/collector/client_test.go b/internal/collector/client_test.go index a0311fad..a9a256f1 100644 --- a/internal/collector/client_test.go +++ b/internal/collector/client_test.go @@ -27,12 +27,12 @@ import ( . "github.com/onsi/gomega" "k8s.io/klog/v2/textlogger" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/collector" ) var ( - clusterConfigurationInstance = `apiVersion: config.projectsveltos.io/v1alpha1 + clusterConfigurationInstance = `apiVersion: config.projectsveltos.io/v1beta1 kind: ClusterConfiguration metadata: creationTimestamp: "2022-10-05T22:31:43Z" @@ -40,7 +40,7 @@ metadata: name: sveltos-management-workload namespace: default ownerReferences: - - apiVersion: config.projectsveltos.io/v1alpha1 + - apiVersion: config.projectsveltos.io/v1beta1 kind: ClusterProfile name: mgianluc uid: 7dbfec81-be91-4e65-a237-f314b72b292b diff --git a/internal/collector/collector_suite_test.go b/internal/collector/collector_suite_test.go index 8d764726..3b5270f5 100644 --- a/internal/collector/collector_suite_test.go +++ b/internal/collector/collector_suite_test.go @@ -25,8 +25,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/cluster-api/util" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" ) func TestSnapshotter(t *testing.T) { @@ -45,8 +45,12 @@ func generateClusterProfile() *configv1alpha1.ClusterProfile { Name: randomString(), }, Spec: configv1alpha1.Spec{ - ClusterSelector: libsveltosv1alpha1.Selector("zone:west"), - SyncMode: configv1alpha1.SyncModeContinuous, + ClusterSelector: libsveltosv1beta1.Selector{ + LabelSelector: metav1.LabelSelector{ + MatchLabels: map[string]string{"zone": "west"}, + }, + }, + SyncMode: configv1alpha1.SyncModeContinuous, }, } } diff --git a/internal/commands/loglevel/loglevel_suite_test.go b/internal/commands/loglevel/loglevel_suite_test.go index 2b856a4d..e5a3f600 100644 --- a/internal/commands/loglevel/loglevel_suite_test.go +++ b/internal/commands/loglevel/loglevel_suite_test.go @@ -23,7 +23,7 @@ import ( . "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" ) func TestShow(t *testing.T) { @@ -31,8 +31,8 @@ func TestShow(t *testing.T) { RunSpecs(t, "LogLevel Suite") } -func getDebuggingConfiguration() *libsveltosv1alpha1.DebuggingConfiguration { - return &libsveltosv1alpha1.DebuggingConfiguration{ +func getDebuggingConfiguration() *libsveltosv1beta1.DebuggingConfiguration { + return &libsveltosv1beta1.DebuggingConfiguration{ ObjectMeta: metav1.ObjectMeta{ Name: "default", }, diff --git a/internal/commands/loglevel/set.go b/internal/commands/loglevel/set.go index 02be840d..b125a0c8 100644 --- a/internal/commands/loglevel/set.go +++ b/internal/commands/loglevel/set.go @@ -23,10 +23,10 @@ import ( docopt "github.com/docopt/docopt-go" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" ) -func updateDebuggingConfiguration(ctx context.Context, logSeverity libsveltosv1alpha1.LogLevel, +func updateDebuggingConfiguration(ctx context.Context, logSeverity libsveltosv1beta1.LogLevel, component string) error { cc, err := collectLogLevelConfiguration(ctx) @@ -35,18 +35,18 @@ func updateDebuggingConfiguration(ctx context.Context, logSeverity libsveltosv1a } found := false - spec := make([]libsveltosv1alpha1.ComponentConfiguration, len(cc)) + spec := make([]libsveltosv1beta1.ComponentConfiguration, len(cc)) for i, c := range cc { if string(c.component) == component { - spec[i] = libsveltosv1alpha1.ComponentConfiguration{ + spec[i] = libsveltosv1beta1.ComponentConfiguration{ Component: c.component, LogLevel: logSeverity, } found = true break } else { - spec[i] = libsveltosv1alpha1.ComponentConfiguration{ + spec[i] = libsveltosv1beta1.ComponentConfiguration{ Component: c.component, LogLevel: c.logSeverity, } @@ -55,8 +55,8 @@ func updateDebuggingConfiguration(ctx context.Context, logSeverity libsveltosv1a if !found { spec = append(spec, - libsveltosv1alpha1.ComponentConfiguration{ - Component: libsveltosv1alpha1.Component(component), + libsveltosv1beta1.ComponentConfiguration{ + Component: libsveltosv1beta1.Component(component), LogLevel: logSeverity, }, ) @@ -99,13 +99,13 @@ Description: debug := parsedArgs["--debug"].(bool) verbose := parsedArgs["--verbose"].(bool) - var logSeverity libsveltosv1alpha1.LogLevel + var logSeverity libsveltosv1beta1.LogLevel if info { - logSeverity = libsveltosv1alpha1.LogLevelInfo + logSeverity = libsveltosv1beta1.LogLevelInfo } else if debug { - logSeverity = libsveltosv1alpha1.LogLevelDebug + logSeverity = libsveltosv1beta1.LogLevelDebug } else if verbose { - logSeverity = libsveltosv1alpha1.LogLevelVerbose + logSeverity = libsveltosv1beta1.LogLevelVerbose } return updateDebuggingConfiguration(ctx, logSeverity, component) diff --git a/internal/commands/loglevel/set_test.go b/internal/commands/loglevel/set_test.go index 3c22e1a4..83a875a3 100644 --- a/internal/commands/loglevel/set_test.go +++ b/internal/commands/loglevel/set_test.go @@ -23,7 +23,7 @@ import ( . "github.com/onsi/gomega" "sigs.k8s.io/controller-runtime/pkg/client/fake" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/commands/loglevel" "github.com/projectsveltos/sveltosctl/internal/utils" ) @@ -36,8 +36,8 @@ var _ = Describe("Set", func() { c := fake.NewClientBuilder().WithScheme(scheme).Build() utils.InitalizeManagementClusterAcces(scheme, nil, nil, c) - Expect(loglevel.UpdateDebuggingConfiguration(context.TODO(), libsveltosv1alpha1.LogLevelDebug, - string(libsveltosv1alpha1.ComponentAddonManager))).To(Succeed()) + Expect(loglevel.UpdateDebuggingConfiguration(context.TODO(), libsveltosv1beta1.LogLevelDebug, + string(libsveltosv1beta1.ComponentAddonManager))).To(Succeed()) k8sAccess := utils.GetAccessInstance() @@ -46,17 +46,17 @@ var _ = Describe("Set", func() { Expect(currentDC).ToNot(BeNil()) Expect(currentDC.Spec.Configuration).ToNot(BeNil()) Expect(len(currentDC.Spec.Configuration)).To(Equal(1)) - Expect(currentDC.Spec.Configuration[0].Component).To(Equal(libsveltosv1alpha1.ComponentAddonManager)) - Expect(currentDC.Spec.Configuration[0].LogLevel).To(Equal(libsveltosv1alpha1.LogLevelDebug)) + Expect(currentDC.Spec.Configuration[0].Component).To(Equal(libsveltosv1beta1.ComponentAddonManager)) + Expect(currentDC.Spec.Configuration[0].LogLevel).To(Equal(libsveltosv1beta1.LogLevelDebug)) - Expect(loglevel.UpdateDebuggingConfiguration(context.TODO(), libsveltosv1alpha1.LogLevelInfo, - string(libsveltosv1alpha1.ComponentAddonManager))).To(Succeed()) + Expect(loglevel.UpdateDebuggingConfiguration(context.TODO(), libsveltosv1beta1.LogLevelInfo, + string(libsveltosv1beta1.ComponentAddonManager))).To(Succeed()) currentDC, err = k8sAccess.GetDebuggingConfiguration(context.TODO()) Expect(err).To(BeNil()) Expect(currentDC).ToNot(BeNil()) Expect(currentDC.Spec.Configuration).ToNot(BeNil()) Expect(len(currentDC.Spec.Configuration)).To(Equal(1)) - Expect(currentDC.Spec.Configuration[0].Component).To(Equal(libsveltosv1alpha1.ComponentAddonManager)) - Expect(currentDC.Spec.Configuration[0].LogLevel).To(Equal(libsveltosv1alpha1.LogLevelInfo)) + Expect(currentDC.Spec.Configuration[0].Component).To(Equal(libsveltosv1beta1.ComponentAddonManager)) + Expect(currentDC.Spec.Configuration[0].LogLevel).To(Equal(libsveltosv1beta1.LogLevelInfo)) }) }) diff --git a/internal/commands/loglevel/show_test.go b/internal/commands/loglevel/show_test.go index 191aea25..7cb04af4 100644 --- a/internal/commands/loglevel/show_test.go +++ b/internal/commands/loglevel/show_test.go @@ -29,7 +29,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/commands/loglevel" "github.com/projectsveltos/sveltosctl/internal/utils" ) @@ -37,8 +37,8 @@ import ( var _ = Describe("Show", func() { It("show displays current log level settings", func() { dc := getDebuggingConfiguration() - dc.Spec.Configuration = []libsveltosv1alpha1.ComponentConfiguration{ - {Component: libsveltosv1alpha1.ComponentClassifier, LogLevel: libsveltosv1alpha1.LogLevelDebug}, + dc.Spec.Configuration = []libsveltosv1beta1.ComponentConfiguration{ + {Component: libsveltosv1beta1.ComponentClassifier, LogLevel: libsveltosv1beta1.LogLevelDebug}, } old := os.Stdout // keep backup of the real stdout @@ -72,8 +72,8 @@ var _ = Describe("Show", func() { lines := strings.Split(buf.String(), "\n") found := false for i := range lines { - if strings.Contains(lines[i], string(libsveltosv1alpha1.ComponentClassifier)) && - strings.Contains(lines[i], string(libsveltosv1alpha1.LogLevelDebug)) { + if strings.Contains(lines[i], string(libsveltosv1beta1.ComponentClassifier)) && + strings.Contains(lines[i], string(libsveltosv1beta1.LogLevelDebug)) { found = true break } diff --git a/internal/commands/loglevel/unset.go b/internal/commands/loglevel/unset.go index 235ab5e6..b8a2cad2 100644 --- a/internal/commands/loglevel/unset.go +++ b/internal/commands/loglevel/unset.go @@ -23,7 +23,7 @@ import ( docopt "github.com/docopt/docopt-go" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" ) func unsetDebuggingConfiguration(ctx context.Context, component string) error { @@ -33,7 +33,7 @@ func unsetDebuggingConfiguration(ctx context.Context, component string) error { } found := false - spec := make([]libsveltosv1alpha1.ComponentConfiguration, 0) + spec := make([]libsveltosv1beta1.ComponentConfiguration, 0) for _, c := range cc { if string(c.component) == component { @@ -41,7 +41,7 @@ func unsetDebuggingConfiguration(ctx context.Context, component string) error { continue } else { spec = append(spec, - libsveltosv1alpha1.ComponentConfiguration{ + libsveltosv1beta1.ComponentConfiguration{ Component: c.component, LogLevel: c.logSeverity, }, diff --git a/internal/commands/loglevel/unset_test.go b/internal/commands/loglevel/unset_test.go index 6b42bf76..19d12d4c 100644 --- a/internal/commands/loglevel/unset_test.go +++ b/internal/commands/loglevel/unset_test.go @@ -24,7 +24,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/commands/loglevel" "github.com/projectsveltos/sveltosctl/internal/utils" ) @@ -32,9 +32,9 @@ import ( var _ = Describe("Unset", func() { It("unset removes log level settings", func() { dc := getDebuggingConfiguration() - dc.Spec.Configuration = []libsveltosv1alpha1.ComponentConfiguration{ - {Component: libsveltosv1alpha1.ComponentClassifier, LogLevel: libsveltosv1alpha1.LogLevelInfo}, - {Component: libsveltosv1alpha1.ComponentAddonManager, LogLevel: libsveltosv1alpha1.LogLevelInfo}, + dc.Spec.Configuration = []libsveltosv1beta1.ComponentConfiguration{ + {Component: libsveltosv1beta1.ComponentClassifier, LogLevel: libsveltosv1beta1.LogLevelInfo}, + {Component: libsveltosv1beta1.ComponentAddonManager, LogLevel: libsveltosv1beta1.LogLevelInfo}, } initObjects := []client.Object{dc} @@ -45,7 +45,7 @@ var _ = Describe("Unset", func() { utils.InitalizeManagementClusterAcces(scheme, nil, nil, c) - Expect(loglevel.UnsetDebuggingConfiguration(context.TODO(), string(libsveltosv1alpha1.ComponentClassifier))).To(Succeed()) + Expect(loglevel.UnsetDebuggingConfiguration(context.TODO(), string(libsveltosv1beta1.ComponentClassifier))).To(Succeed()) k8sAccess := utils.GetAccessInstance() @@ -54,8 +54,8 @@ var _ = Describe("Unset", func() { Expect(currentDC).ToNot(BeNil()) Expect(currentDC.Spec.Configuration).ToNot(BeNil()) Expect(len(currentDC.Spec.Configuration)).To(Equal(1)) - Expect(currentDC.Spec.Configuration[0].Component).To(Equal(libsveltosv1alpha1.ComponentAddonManager)) - Expect(currentDC.Spec.Configuration[0].LogLevel).To(Equal(libsveltosv1alpha1.LogLevelInfo)) + Expect(currentDC.Spec.Configuration[0].Component).To(Equal(libsveltosv1beta1.ComponentAddonManager)) + Expect(currentDC.Spec.Configuration[0].LogLevel).To(Equal(libsveltosv1beta1.LogLevelInfo)) }) }) diff --git a/internal/commands/loglevel/utils.go b/internal/commands/loglevel/utils.go index 9c697906..3058208c 100644 --- a/internal/commands/loglevel/utils.go +++ b/internal/commands/loglevel/utils.go @@ -23,13 +23,13 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/utils" ) type componentConfiguration struct { - component libsveltosv1alpha1.Component - logSeverity libsveltosv1alpha1.LogLevel + component libsveltosv1beta1.Component + logSeverity libsveltosv1beta1.LogLevel } // byComponent sorts componentConfiguration by name. @@ -69,7 +69,7 @@ func collectLogLevelConfiguration(ctx context.Context) ([]*componentConfiguratio func updateLogLevelConfiguration( ctx context.Context, - spec []libsveltosv1alpha1.ComponentConfiguration, + spec []libsveltosv1beta1.ComponentConfiguration, ) error { instance := utils.GetAccessInstance() @@ -77,7 +77,7 @@ func updateLogLevelConfiguration( dc, err := instance.GetDebuggingConfiguration(ctx) if err != nil { if apierrors.IsNotFound(err) { - dc = &libsveltosv1alpha1.DebuggingConfiguration{ + dc = &libsveltosv1beta1.DebuggingConfiguration{ ObjectMeta: metav1.ObjectMeta{ Name: "default", }, @@ -87,7 +87,7 @@ func updateLogLevelConfiguration( } } - dc.Spec = libsveltosv1alpha1.DebuggingConfigurationSpec{ + dc.Spec = libsveltosv1beta1.DebuggingConfigurationSpec{ Configuration: spec, } diff --git a/internal/commands/onboard/cluster.go b/internal/commands/onboard/cluster.go index 0f94744d..76db60a8 100644 --- a/internal/commands/onboard/cluster.go +++ b/internal/commands/onboard/cluster.go @@ -34,7 +34,7 @@ import ( "k8s.io/client-go/tools/clientcmd" ctrl "sigs.k8s.io/controller-runtime" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" logs "github.com/projectsveltos/libsveltos/lib/logsettings" "github.com/projectsveltos/sveltosctl/internal/commands/generate" "github.com/projectsveltos/sveltosctl/internal/utils" @@ -72,7 +72,7 @@ func patchSveltosCluster(ctx context.Context, clusterNamespace, clusterName stri instance := utils.GetAccessInstance() - currentSveltosCluster := &libsveltosv1alpha1.SveltosCluster{} + currentSveltosCluster := &libsveltosv1beta1.SveltosCluster{} err := instance.GetResource(ctx, types.NamespacedName{Namespace: clusterNamespace, Name: clusterName}, currentSveltosCluster) if err != nil { @@ -82,7 +82,7 @@ func patchSveltosCluster(ctx context.Context, clusterNamespace, clusterName stri currentSveltosCluster.Name = clusterName currentSveltosCluster.Labels = labels if renew { - currentSveltosCluster.Spec.TokenRequestRenewalOption = &libsveltosv1alpha1.TokenRequestRenewalOption{ + currentSveltosCluster.Spec.TokenRequestRenewalOption = &libsveltosv1beta1.TokenRequestRenewalOption{ RenewTokenRequestInterval: metav1.Duration{Duration: 24 * time.Hour}, } } diff --git a/internal/commands/onboard/cluster_test.go b/internal/commands/onboard/cluster_test.go index 5496ae26..267f8cb7 100644 --- a/internal/commands/onboard/cluster_test.go +++ b/internal/commands/onboard/cluster_test.go @@ -29,7 +29,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/utils" "github.com/projectsveltos/sveltosctl/internal/commands/onboard" @@ -61,7 +61,7 @@ var _ = Describe("OnboardCluster", func() { instance := utils.GetAccessInstance() - sveltosCluster := &libsveltosv1alpha1.SveltosCluster{} + sveltosCluster := &libsveltosv1beta1.SveltosCluster{} err = instance.GetResource(context.TODO(), types.NamespacedName{Namespace: clusterNamespace, Name: clusterName}, sveltosCluster) Expect(err).To(BeNil()) diff --git a/internal/commands/reconciler_utils.go b/internal/commands/reconciler_utils.go index 264195ff..567c68b8 100644 --- a/internal/commands/reconciler_utils.go +++ b/internal/commands/reconciler_utils.go @@ -44,12 +44,12 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" "github.com/projectsveltos/libsveltos/lib/crd" "github.com/projectsveltos/libsveltos/lib/logsettings" logs "github.com/projectsveltos/libsveltos/lib/logsettings" libsveltosset "github.com/projectsveltos/libsveltos/lib/set" - utilsv1alpha1 "github.com/projectsveltos/sveltosctl/api/v1alpha1" + utilsv1beta1 "github.com/projectsveltos/sveltosctl/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/collector" "github.com/projectsveltos/sveltosctl/internal/utils" ) @@ -69,7 +69,7 @@ type collection interface { getStartingDeadlineSeconds() *int64 - setLastRunStatus(utilsv1alpha1.CollectionStatus) + setLastRunStatus(utilsv1beta1.CollectionStatus) setFailureMessage(string) } @@ -89,14 +89,14 @@ var ( techsupportMap map[corev1.ObjectReference]*libsveltosset.Set // key: techsupport; value techsupport's Selector - techsupports map[corev1.ObjectReference]libsveltosv1alpha1.Selector + techsupports map[corev1.ObjectReference]libsveltosv1beta1.Selector ) func watchResources(ctx context.Context, logger logr.Logger) error { mux = sync.Mutex{} clusterMap = make(map[corev1.ObjectReference]*libsveltosset.Set) techsupportMap = make(map[corev1.ObjectReference]*libsveltosset.Set) - techsupports = make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector) + techsupports = make(map[corev1.ObjectReference]libsveltosv1beta1.Selector) scheme, _ := utils.GetScheme() mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ @@ -145,9 +145,9 @@ func startSnapshotReconciler(ctx context.Context, mgr manager.Manager, logger lo return err } - sourceSnapshot := source.Kind[*utilsv1alpha1.Snapshot]( + sourceSnapshot := source.Kind[*utilsv1beta1.Snapshot]( mgr.GetCache(), - &utilsv1alpha1.Snapshot{}, + &utilsv1beta1.Snapshot{}, handler.TypedEnqueueRequestsFromMapFunc(handlerSnapshotMapFun), SnapshotPredicate{Logger: mgr.GetLogger().WithValues("predicate", "clusterpredicate")}, ) @@ -182,9 +182,9 @@ func startTechsupportReconciler(ctx context.Context, mgr manager.Manager, logger return nil, err } - sourceTechsupport := source.Kind[*utilsv1alpha1.Techsupport]( + sourceTechsupport := source.Kind[*utilsv1beta1.Techsupport]( mgr.GetCache(), - &utilsv1alpha1.Techsupport{}, + &utilsv1beta1.Techsupport{}, handler.TypedEnqueueRequestsFromMapFunc(handlerTechsupportMapFun), TechsupportPredicate{Logger: mgr.GetLogger().WithValues("predicate", "techsupportpredicate")}, ) @@ -193,9 +193,9 @@ func startTechsupportReconciler(ctx context.Context, mgr manager.Manager, logger return nil, err } - sourceSveltosCluster := source.Kind[*libsveltosv1alpha1.SveltosCluster]( + sourceSveltosCluster := source.Kind[*libsveltosv1beta1.SveltosCluster]( mgr.GetCache(), - &libsveltosv1alpha1.SveltosCluster{}, + &libsveltosv1beta1.SveltosCluster{}, handler.TypedEnqueueRequestsFromMapFunc(requeueTechsupportForSveltosCluster), SveltosClusterPredicate{Logger: mgr.GetLogger().WithValues("predicate", "sveltosclusterpredicate")}, ) @@ -312,11 +312,11 @@ func addFinalizer(ctx context.Context, instance client.Object, finalizer string) types.NamespacedName{Name: instance.GetName()}, instance) } -func handlerSnapshotMapFun(ctx context.Context, snapshot *utilsv1alpha1.Snapshot) []reconcile.Request { +func handlerSnapshotMapFun(ctx context.Context, snapshot *utilsv1beta1.Snapshot) []reconcile.Request { return handlerMapFun(snapshot) } -func handlerTechsupportMapFun(ctx context.Context, techsupport *utilsv1alpha1.Techsupport) []reconcile.Request { +func handlerTechsupportMapFun(ctx context.Context, techsupport *utilsv1beta1.Techsupport) []reconcile.Request { return handlerMapFun(techsupport) } @@ -340,16 +340,16 @@ func handlerMapFun(o client.Object) []reconcile.Request { } func updateStatus(result collector.Result, collectionInstance collection) { - var status utilsv1alpha1.CollectionStatus + var status utilsv1beta1.CollectionStatus var message string switch result.ResultStatus { case collector.Collected: - status = utilsv1alpha1.CollectionStatusCollected + status = utilsv1beta1.CollectionStatusCollected case collector.InProgress: - status = utilsv1alpha1.CollectionStatusInProgress + status = utilsv1beta1.CollectionStatusInProgress case collector.Failed: - status = utilsv1alpha1.CollectionStatusFailed + status = utilsv1beta1.CollectionStatusFailed message = result.Err.Error() case collector.Unavailable: return @@ -359,9 +359,9 @@ func updateStatus(result collector.Result, collectionInstance collection) { collectionInstance.setFailureMessage(message) } -func isCollectionInProgress(lastRunStatus *utilsv1alpha1.CollectionStatus) bool { +func isCollectionInProgress(lastRunStatus *utilsv1beta1.CollectionStatus) bool { return lastRunStatus != nil && - *lastRunStatus == utilsv1alpha1.CollectionStatusInProgress + *lastRunStatus == utilsv1beta1.CollectionStatusInProgress } func removeQueuedJobsAndFinalizer(c *collector.Collector, instance client.Object, collectionType collector.CollectionType, @@ -404,7 +404,7 @@ type SnapshotPredicate struct { Logger logr.Logger } -func (p SnapshotPredicate) Create(obj event.TypedCreateEvent[*utilsv1alpha1.Snapshot]) bool { +func (p SnapshotPredicate) Create(obj event.TypedCreateEvent[*utilsv1beta1.Snapshot]) bool { o := obj.Object p.Logger.Info(fmt.Sprintf("Create kind: %s Info: %s/%s", o.GetObjectKind().GroupVersionKind().Kind, @@ -412,11 +412,11 @@ func (p SnapshotPredicate) Create(obj event.TypedCreateEvent[*utilsv1alpha1.Snap return true } -func (p SnapshotPredicate) Update(obj event.TypedUpdateEvent[*utilsv1alpha1.Snapshot]) bool { +func (p SnapshotPredicate) Update(obj event.TypedUpdateEvent[*utilsv1beta1.Snapshot]) bool { return updateSnaphotPredicate(obj.ObjectNew, obj.ObjectOld) } -func (p SnapshotPredicate) Delete(obj event.TypedDeleteEvent[*utilsv1alpha1.Snapshot]) bool { +func (p SnapshotPredicate) Delete(obj event.TypedDeleteEvent[*utilsv1beta1.Snapshot]) bool { o := obj.Object p.Logger.Info(fmt.Sprintf("Delete kind: %s Info: %s/%s", o.GetObjectKind().GroupVersionKind().Kind, @@ -424,7 +424,7 @@ func (p SnapshotPredicate) Delete(obj event.TypedDeleteEvent[*utilsv1alpha1.Snap return true } -func (p SnapshotPredicate) Generic(obj event.TypedGenericEvent[*utilsv1alpha1.Snapshot]) bool { +func (p SnapshotPredicate) Generic(obj event.TypedGenericEvent[*utilsv1beta1.Snapshot]) bool { return false } @@ -432,7 +432,7 @@ type TechsupportPredicate struct { Logger logr.Logger } -func (p TechsupportPredicate) Create(obj event.TypedCreateEvent[*utilsv1alpha1.Techsupport]) bool { +func (p TechsupportPredicate) Create(obj event.TypedCreateEvent[*utilsv1beta1.Techsupport]) bool { o := obj.Object p.Logger.Info(fmt.Sprintf("Create kind: %s Info: %s/%s", o.GetObjectKind().GroupVersionKind().Kind, @@ -440,11 +440,11 @@ func (p TechsupportPredicate) Create(obj event.TypedCreateEvent[*utilsv1alpha1.T return true } -func (p TechsupportPredicate) Update(obj event.TypedUpdateEvent[*utilsv1alpha1.Techsupport]) bool { +func (p TechsupportPredicate) Update(obj event.TypedUpdateEvent[*utilsv1beta1.Techsupport]) bool { return updateTechsupportPredicate(obj.ObjectNew, obj.ObjectOld) } -func (p TechsupportPredicate) Delete(obj event.TypedDeleteEvent[*utilsv1alpha1.Techsupport]) bool { +func (p TechsupportPredicate) Delete(obj event.TypedDeleteEvent[*utilsv1beta1.Techsupport]) bool { o := obj.Object p.Logger.Info(fmt.Sprintf("Delete kind: %s Info: %s/%s", o.GetObjectKind().GroupVersionKind().Kind, @@ -452,7 +452,7 @@ func (p TechsupportPredicate) Delete(obj event.TypedDeleteEvent[*utilsv1alpha1.T return true } -func (p TechsupportPredicate) Generic(obj event.TypedGenericEvent[*utilsv1alpha1.Techsupport]) bool { +func (p TechsupportPredicate) Generic(obj event.TypedGenericEvent[*utilsv1beta1.Techsupport]) bool { return false } diff --git a/internal/commands/show/addons.go b/internal/commands/show/addons.go index cfa1fd33..0c2db463 100644 --- a/internal/commands/show/addons.go +++ b/internal/commands/show/addons.go @@ -27,7 +27,7 @@ import ( "github.com/go-logr/logr" "github.com/olekukonko/tablewriter" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" logs "github.com/projectsveltos/libsveltos/lib/logsettings" "github.com/projectsveltos/sveltosctl/internal/utils" ) diff --git a/internal/commands/show/addons_test.go b/internal/commands/show/addons_test.go index 20670321..31213563 100644 --- a/internal/commands/show/addons_test.go +++ b/internal/commands/show/addons_test.go @@ -33,7 +33,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/commands/show" "github.com/projectsveltos/sveltosctl/internal/utils" ) diff --git a/internal/commands/show/admin_rbacs.go b/internal/commands/show/admin_rbacs.go index aa99ac18..461cd50a 100644 --- a/internal/commands/show/admin_rbacs.go +++ b/internal/commands/show/admin_rbacs.go @@ -32,7 +32,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" logs "github.com/projectsveltos/libsveltos/lib/logsettings" libsveltosutils "github.com/projectsveltos/libsveltos/lib/utils" "github.com/projectsveltos/sveltosctl/internal/utils" @@ -93,10 +93,10 @@ func displayAdminRbacs(ctx context.Context, return nil } -func createRoleRequestsPerClusterMap(roleRequests *libsveltosv1alpha1.RoleRequestList, - logger logr.Logger) map[corev1.ObjectReference][]*libsveltosv1alpha1.RoleRequest { +func createRoleRequestsPerClusterMap(roleRequests *libsveltosv1beta1.RoleRequestList, + logger logr.Logger) map[corev1.ObjectReference][]*libsveltosv1beta1.RoleRequest { - clusterMap := make(map[corev1.ObjectReference][]*libsveltosv1alpha1.RoleRequest) + clusterMap := make(map[corev1.ObjectReference][]*libsveltosv1beta1.RoleRequest) for i := range roleRequests.Items { rr := &roleRequests.Items[i] @@ -106,15 +106,15 @@ func createRoleRequestsPerClusterMap(roleRequests *libsveltosv1alpha1.RoleReques return clusterMap } -func parseMatchihgCluster(rr *libsveltosv1alpha1.RoleRequest, - clusterMap map[corev1.ObjectReference][]*libsveltosv1alpha1.RoleRequest, logger logr.Logger, -) map[corev1.ObjectReference][]*libsveltosv1alpha1.RoleRequest { +func parseMatchihgCluster(rr *libsveltosv1beta1.RoleRequest, + clusterMap map[corev1.ObjectReference][]*libsveltosv1beta1.RoleRequest, logger logr.Logger, +) map[corev1.ObjectReference][]*libsveltosv1beta1.RoleRequest { logger = logger.WithValues("rolerequest", rr.Name) logger.V(logs.LogDebug).Info("parsing matching clusters for roleRequets") for i := range rr.Status.MatchingClusterRefs { if _, ok := clusterMap[rr.Status.MatchingClusterRefs[i]]; !ok { - clusterMap[rr.Status.MatchingClusterRefs[i]] = make([]*libsveltosv1alpha1.RoleRequest, 0) + clusterMap[rr.Status.MatchingClusterRefs[i]] = make([]*libsveltosv1beta1.RoleRequest, 0) } clusterMap[rr.Status.MatchingClusterRefs[i]] = append(clusterMap[rr.Status.MatchingClusterRefs[i]], rr) } @@ -122,7 +122,7 @@ func parseMatchihgCluster(rr *libsveltosv1alpha1.RoleRequest, } func parseCluster(ctx context.Context, cluster *corev1.ObjectReference, - roleRequests []*libsveltosv1alpha1.RoleRequest, + roleRequests []*libsveltosv1beta1.RoleRequest, passedNamespace, passedCluster, passedServiceAccountNamespace, passedServiceAccountName string, table *tablewriter.Table, logger logr.Logger) error { @@ -142,7 +142,7 @@ func parseCluster(ctx context.Context, cluster *corev1.ObjectReference, return nil } -func shouldParseRoleRequest(roleRequest *libsveltosv1alpha1.RoleRequest, +func shouldParseRoleRequest(roleRequest *libsveltosv1beta1.RoleRequest, passedServiceAccountNamespace, passedServiceAccountName string) bool { if passedServiceAccountNamespace != "" { @@ -160,7 +160,7 @@ func shouldParseRoleRequest(roleRequest *libsveltosv1alpha1.RoleRequest, return true } -func parseRoleRequest(ctx context.Context, roleRequest *libsveltosv1alpha1.RoleRequest, +func parseRoleRequest(ctx context.Context, roleRequest *libsveltosv1beta1.RoleRequest, clusterNamespace, clusterName, clusterKind, passedServiceAccountNamespace, passedServiceAccountName string, table *tablewriter.Table, logger logr.Logger) error { @@ -183,7 +183,7 @@ func parseRoleRequest(ctx context.Context, roleRequest *libsveltosv1alpha1.RoleR func parseReferencedResource(ctx context.Context, clusterNamespace, clusterName, clusterKind, serviceAccountNamespace, serviceAccountName string, - resource libsveltosv1alpha1.PolicyRef, table *tablewriter.Table, logger logr.Logger) error { + resource libsveltosv1beta1.PolicyRef, table *tablewriter.Table, logger logr.Logger) error { // fetch resource content, err := collectResourceContent(ctx, resource, logger) @@ -264,14 +264,14 @@ func processClusterRole(u *unstructured.Unstructured, return nil } -func collectResourceContent(ctx context.Context, resource libsveltosv1alpha1.PolicyRef, logger logr.Logger, +func collectResourceContent(ctx context.Context, resource libsveltosv1beta1.PolicyRef, logger logr.Logger, ) ([]*unstructured.Unstructured, error) { logger = logger.WithValues("kind", resource.Kind, "resource", fmt.Sprintf("%s/%s", resource.Namespace, resource.Name)) logger.V(logs.LogDebug).Info("collect resource") instance := utils.GetAccessInstance() - if resource.Kind == string(libsveltosv1alpha1.ConfigMapReferencedResourceKind) { + if resource.Kind == string(libsveltosv1beta1.ConfigMapReferencedResourceKind) { configMap := &corev1.ConfigMap{} err := instance.GetResource(ctx, types.NamespacedName{Namespace: resource.Namespace, Name: resource.Name}, configMap) diff --git a/internal/commands/show/admin_rbacs_test.go b/internal/commands/show/admin_rbacs_test.go index 75e8aa64..41dd7dd9 100644 --- a/internal/commands/show/admin_rbacs_test.go +++ b/internal/commands/show/admin_rbacs_test.go @@ -33,7 +33,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/klog/v2/textlogger" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/commands/show" "github.com/projectsveltos/sveltosctl/internal/utils" ) @@ -85,8 +85,8 @@ var _ = Describe("Admin RBACs", func() { clusterName := randomString() matchingCluster := []corev1.ObjectReference{ { - Kind: libsveltosv1alpha1.SveltosClusterKind, - APIVersion: libsveltosv1alpha1.GroupVersion.String(), + Kind: libsveltosv1beta1.SveltosClusterKind, + APIVersion: libsveltosv1beta1.GroupVersion.String(), Namespace: clusterNamespace, Name: clusterName, }, @@ -125,7 +125,7 @@ var _ = Describe("Admin RBACs", func() { +--------------------------------------+-------------+-----------+------------+------------+----------------+----------------+ */ - clusterInfo := fmt.Sprintf("%s:%s/%s", libsveltosv1alpha1.SveltosClusterKind, clusterNamespace, clusterName) + clusterInfo := fmt.Sprintf("%s:%s/%s", libsveltosv1beta1.SveltosClusterKind, clusterNamespace, clusterName) lines := strings.Split(buf.String(), "\n") clusterRoleView, clusterRoleModify, roleView := false, false, false for i := range lines { @@ -152,33 +152,33 @@ var _ = Describe("Admin RBACs", func() { func getRoleRequest(matchingClusters []corev1.ObjectReference, configMaps []corev1.ConfigMap, secrets []corev1.Secret, - serviceAccountNamespace, serviceAccountName string) *libsveltosv1alpha1.RoleRequest { + serviceAccountNamespace, serviceAccountName string) *libsveltosv1beta1.RoleRequest { - roleRequest := libsveltosv1alpha1.RoleRequest{ + roleRequest := libsveltosv1beta1.RoleRequest{ ObjectMeta: metav1.ObjectMeta{ Name: randomString(), }, - Spec: libsveltosv1alpha1.RoleRequestSpec{ - RoleRefs: make([]libsveltosv1alpha1.PolicyRef, 0), + Spec: libsveltosv1beta1.RoleRequestSpec{ + RoleRefs: make([]libsveltosv1beta1.PolicyRef, 0), ServiceAccountNamespace: serviceAccountNamespace, ServiceAccountName: serviceAccountName, }, - Status: libsveltosv1alpha1.RoleRequestStatus{ + Status: libsveltosv1beta1.RoleRequestStatus{ MatchingClusterRefs: matchingClusters, }, } for i := range configMaps { - roleRequest.Spec.RoleRefs = append(roleRequest.Spec.RoleRefs, libsveltosv1alpha1.PolicyRef{ - Kind: string(libsveltosv1alpha1.ConfigMapReferencedResourceKind), + roleRequest.Spec.RoleRefs = append(roleRequest.Spec.RoleRefs, libsveltosv1beta1.PolicyRef{ + Kind: string(libsveltosv1beta1.ConfigMapReferencedResourceKind), Namespace: configMaps[i].Namespace, Name: configMaps[i].Name, }) } for i := range secrets { - roleRequest.Spec.RoleRefs = append(roleRequest.Spec.RoleRefs, libsveltosv1alpha1.PolicyRef{ - Kind: string(libsveltosv1alpha1.SecretReferencedResourceKind), + roleRequest.Spec.RoleRefs = append(roleRequest.Spec.RoleRefs, libsveltosv1beta1.PolicyRef{ + Kind: string(libsveltosv1beta1.SecretReferencedResourceKind), Namespace: secrets[i].Namespace, Name: secrets[i].Name, }) diff --git a/internal/commands/show/dryrun.go b/internal/commands/show/dryrun.go index 08b6f06c..4a17b0f1 100644 --- a/internal/commands/show/dryrun.go +++ b/internal/commands/show/dryrun.go @@ -28,7 +28,7 @@ import ( "github.com/go-logr/logr" "github.com/olekukonko/tablewriter" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" "github.com/projectsveltos/addon-controller/controllers" logs "github.com/projectsveltos/libsveltos/lib/logsettings" "github.com/projectsveltos/sveltosctl/internal/utils" diff --git a/internal/commands/show/dryrun_test.go b/internal/commands/show/dryrun_test.go index 45344128..f402cc0a 100644 --- a/internal/commands/show/dryrun_test.go +++ b/internal/commands/show/dryrun_test.go @@ -33,7 +33,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" "github.com/projectsveltos/addon-controller/controllers" "github.com/projectsveltos/sveltosctl/internal/commands/show" "github.com/projectsveltos/sveltosctl/internal/utils" diff --git a/internal/commands/show/resources.go b/internal/commands/show/resources.go index 077f700f..da9fece1 100644 --- a/internal/commands/show/resources.go +++ b/internal/commands/show/resources.go @@ -29,7 +29,7 @@ import ( "github.com/olekukonko/tablewriter" "gopkg.in/yaml.v2" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" logs "github.com/projectsveltos/libsveltos/lib/logsettings" libsveltosutils "github.com/projectsveltos/libsveltos/lib/utils" "github.com/projectsveltos/sveltosctl/internal/utils" @@ -107,7 +107,7 @@ func displayResourcesInNamespaces(ctx context.Context, return nil } -func displayResourcesInReport(healthCheckReport *libsveltosv1alpha1.HealthCheckReport, +func displayResourcesInReport(healthCheckReport *libsveltosv1beta1.HealthCheckReport, passedGroup, passedKind, passedNamespace string, full bool, table *tablewriter.Table, logger logr.Logger) error { @@ -134,7 +134,7 @@ func displayResourcesInReport(healthCheckReport *libsveltosv1alpha1.HealthCheckR return nil } -func displayResource(resourceStatus *libsveltosv1alpha1.ResourceStatus, +func displayResource(resourceStatus *libsveltosv1beta1.ResourceStatus, clusterNamespace, clusterName string, table *tablewriter.Table) { clusterInfo := fmt.Sprintf("%s/%s", clusterNamespace, clusterName) @@ -143,7 +143,7 @@ func displayResource(resourceStatus *libsveltosv1alpha1.ResourceStatus, resourceName := resourceStatus.ObjectRef.Name message := resourceStatus.Message - if resourceStatus.HealthStatus != libsveltosv1alpha1.HealthStatusHealthy { + if resourceStatus.HealthStatus != libsveltosv1beta1.HealthStatusHealthy { data := []string{clusterInfo, gvk, resourceNamespace, resourceName, message} table.Rich(data, []tablewriter.Colors{{tablewriter.Bold, tablewriter.FgBlackColor}, {tablewriter.Bold, tablewriter.FgBlackColor}, {tablewriter.Bold, tablewriter.BgRedColor}, @@ -154,7 +154,7 @@ func displayResource(resourceStatus *libsveltosv1alpha1.ResourceStatus, table.Append(genResourceRow(clusterInfo, gvk, resourceNamespace, resourceName, message)) } -func printResource(resourceStatus *libsveltosv1alpha1.ResourceStatus, +func printResource(resourceStatus *libsveltosv1beta1.ResourceStatus, clusterNamespace, clusterName string, logger logr.Logger) error { clusterInfo := fmt.Sprintf("%s/%s", clusterNamespace, clusterName) @@ -179,7 +179,7 @@ func printResource(resourceStatus *libsveltosv1alpha1.ResourceStatus, return err } - if resourceStatus.HealthStatus != libsveltosv1alpha1.HealthStatusHealthy { + if resourceStatus.HealthStatus != libsveltosv1beta1.HealthStatusHealthy { red := color.New(color.FgRed).SprintfFunc() //nolint: forbidigo // printing results to stdout fmt.Println("Cluster: ", red(clusterInfo)) @@ -195,7 +195,7 @@ func printResource(resourceStatus *libsveltosv1alpha1.ResourceStatus, return nil } -func doConsiderResourceStatus(resourceStatus *libsveltosv1alpha1.ResourceStatus, +func doConsiderResourceStatus(resourceStatus *libsveltosv1beta1.ResourceStatus, passedGroup, passedKind, passedNamespace string) bool { if passedGroup != "" { diff --git a/internal/commands/show/resources_test.go b/internal/commands/show/resources_test.go index 93b1efc1..2c490c56 100644 --- a/internal/commands/show/resources_test.go +++ b/internal/commands/show/resources_test.go @@ -34,7 +34,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/commands/show" "github.com/projectsveltos/sveltosctl/internal/utils" ) @@ -43,16 +43,16 @@ var _ = Describe("Resources", func() { It("show resources displays resources from various managed clusters", func() { message := "All replicas 1 are healthy" - hcr := &libsveltosv1alpha1.HealthCheckReport{ + hcr := &libsveltosv1beta1.HealthCheckReport{ ObjectMeta: metav1.ObjectMeta{ Name: randomString(), Namespace: randomString(), }, - Spec: libsveltosv1alpha1.HealthCheckReportSpec{ + Spec: libsveltosv1beta1.HealthCheckReportSpec{ ClusterNamespace: randomString(), ClusterName: randomString(), - ClusterType: libsveltosv1alpha1.ClusterTypeSveltos, - ResourceStatuses: []libsveltosv1alpha1.ResourceStatus{ + ClusterType: libsveltosv1beta1.ClusterTypeSveltos, + ResourceStatuses: []libsveltosv1beta1.ResourceStatus{ { Resource: nil, ObjectRef: corev1.ObjectReference{ @@ -62,7 +62,7 @@ var _ = Describe("Resources", func() { Name: randomString(), }, Message: message, - HealthStatus: libsveltosv1alpha1.HealthStatusHealthy, + HealthStatus: libsveltosv1beta1.HealthStatusHealthy, }, { Resource: nil, @@ -73,7 +73,7 @@ var _ = Describe("Resources", func() { Name: randomString(), }, Message: message, - HealthStatus: libsveltosv1alpha1.HealthStatusHealthy, + HealthStatus: libsveltosv1beta1.HealthStatusHealthy, }, }, }, diff --git a/internal/commands/show/usage.go b/internal/commands/show/usage.go index f51a14ad..74a02a66 100644 --- a/internal/commands/show/usage.go +++ b/internal/commands/show/usage.go @@ -28,8 +28,8 @@ import ( "github.com/olekukonko/tablewriter" corev1 "k8s.io/api/core/v1" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" logs "github.com/projectsveltos/libsveltos/lib/logsettings" "github.com/projectsveltos/sveltosctl/internal/utils" ) @@ -63,12 +63,12 @@ func showUsage(ctx context.Context, kind, passedNamespace, passedName string, lo return err } } - if kind == "" || kind == string(libsveltosv1alpha1.ConfigMapReferencedResourceKind) { + if kind == "" || kind == string(libsveltosv1beta1.ConfigMapReferencedResourceKind) { if err := showUsageForConfigMaps(ctx, passedNamespace, passedName, table, logger); err != nil { return err } } - if kind == "" || kind == string(libsveltosv1alpha1.SecretReferencedResourceKind) { + if kind == "" || kind == string(libsveltosv1beta1.SecretReferencedResourceKind) { if err := showUsageForSecrets(ctx, passedNamespace, passedName, table, logger); err != nil { return err } @@ -175,7 +175,7 @@ func showUsageForConfigMaps(ctx context.Context, passedNamespace, passedName str } for pr := range result { - table.Append(genUsageRow(string(libsveltosv1alpha1.ConfigMapReferencedResourceKind), + table.Append(genUsageRow(string(libsveltosv1beta1.ConfigMapReferencedResourceKind), pr.Namespace, pr.Name, result[pr])) } @@ -213,7 +213,7 @@ func showUsageForSecrets(ctx context.Context, passedNamespace, passedName string } for pr := range result { - table.Append(genUsageRow(string(libsveltosv1alpha1.SecretReferencedResourceKind), + table.Append(genUsageRow(string(libsveltosv1beta1.SecretReferencedResourceKind), pr.Namespace, pr.Name, result[pr])) } @@ -226,7 +226,7 @@ func getConfigMaps(passedNamespace, passedName string, policyRefs []configv1alph configMaps := make([]configv1alpha1.PolicyRef, 0) for i := range policyRefs { pr := &policyRefs[i] - if pr.Kind == string(libsveltosv1alpha1.ConfigMapReferencedResourceKind) { + if pr.Kind == string(libsveltosv1beta1.ConfigMapReferencedResourceKind) { if shouldAddPolicyRef(passedNamespace, passedName, pr) { logger.V(logs.LogDebug).Info(fmt.Sprintf("considering reference configMap %s/%s", pr.Namespace, pr.Name)) @@ -252,7 +252,7 @@ func getSecrets(passedNamespace, passedName string, policyRefs []configv1alpha1. secrets := make([]configv1alpha1.PolicyRef, 0) for i := range policyRefs { pr := &policyRefs[i] - if pr.Kind == string(libsveltosv1alpha1.SecretReferencedResourceKind) { + if pr.Kind == string(libsveltosv1beta1.SecretReferencedResourceKind) { if shouldAddPolicyRef(passedNamespace, passedName, pr) { logger.V(logs.LogDebug).Info(fmt.Sprintf("considering reference secret %s/%s", pr.Namespace, pr.Name)) @@ -346,13 +346,13 @@ Description: kind = passedKind.(string) if kind != configv1alpha1.ClusterProfileKind && kind != configv1alpha1.ProfileKind && - kind != string(libsveltosv1alpha1.ConfigMapReferencedResourceKind) && - kind != string(libsveltosv1alpha1.SecretReferencedResourceKind) { + kind != string(libsveltosv1beta1.ConfigMapReferencedResourceKind) && + kind != string(libsveltosv1beta1.SecretReferencedResourceKind) { return fmt.Errorf("possible values for kind are: %s, %s, %s, %s", configv1alpha1.ClusterProfileKind, configv1alpha1.ProfileKind, - string(libsveltosv1alpha1.ConfigMapReferencedResourceKind), - string(libsveltosv1alpha1.SecretReferencedResourceKind), + string(libsveltosv1beta1.ConfigMapReferencedResourceKind), + string(libsveltosv1beta1.SecretReferencedResourceKind), ) } } diff --git a/internal/commands/show/usage_test.go b/internal/commands/show/usage_test.go index 4c9d9b1c..f7ffb1d5 100644 --- a/internal/commands/show/usage_test.go +++ b/internal/commands/show/usage_test.go @@ -33,8 +33,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/klog/v2/textlogger" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/commands/show" "github.com/projectsveltos/sveltosctl/internal/utils" ) @@ -44,13 +44,13 @@ var _ = Describe("Usage", func() { configMap := configv1alpha1.PolicyRef{ Namespace: randomString(), Name: randomString(), - Kind: string(libsveltosv1alpha1.ConfigMapReferencedResourceKind), + Kind: string(libsveltosv1beta1.ConfigMapReferencedResourceKind), } secret := configv1alpha1.PolicyRef{ Namespace: randomString(), Name: randomString(), - Kind: string(libsveltosv1alpha1.SecretReferencedResourceKind), + Kind: string(libsveltosv1beta1.SecretReferencedResourceKind), } clusterProfile1 := generateClusterProfile() @@ -103,9 +103,9 @@ var _ = Describe("Usage", func() { lines := strings.Split(buf.String(), "\n") verifyClusterProfileUsage(lines, clusterProfile1) verifyClusterProfileUsage(lines, clusterProfile2) - verifyUsage(lines, string(libsveltosv1alpha1.ConfigMapReferencedResourceKind), + verifyUsage(lines, string(libsveltosv1beta1.ConfigMapReferencedResourceKind), configMap.Namespace, configMap.Name, &clusterProfile1.Status.MatchingClusterRefs[0]) - verifyUsage(lines, string(libsveltosv1alpha1.SecretReferencedResourceKind), + verifyUsage(lines, string(libsveltosv1beta1.SecretReferencedResourceKind), secret.Namespace, secret.Name, &clusterProfile2.Status.MatchingClusterRefs[0]) os.Stdout = old }) @@ -139,8 +139,12 @@ func generateClusterProfile() *configv1alpha1.ClusterProfile { Name: randomString(), }, Spec: configv1alpha1.Spec{ - ClusterSelector: libsveltosv1alpha1.Selector("zone:west"), - SyncMode: configv1alpha1.SyncModeContinuous, + ClusterSelector: libsveltosv1beta1.Selector{ + LabelSelector: metav1.LabelSelector{ + MatchLabels: map[string]string{"zone": "west"}, + }, + }, + SyncMode: configv1alpha1.SyncModeContinuous, }, } } diff --git a/internal/commands/show/utils.go b/internal/commands/show/utils.go index 956a2ab4..5b9d573b 100644 --- a/internal/commands/show/utils.go +++ b/internal/commands/show/utils.go @@ -19,7 +19,7 @@ package show import ( corev1 "k8s.io/api/core/v1" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" ) func doConsiderNamespace(ns *corev1.Namespace, passedNamespace string) bool { diff --git a/internal/commands/show/utils_test.go b/internal/commands/show/utils_test.go index 93ee6c9f..22b85787 100644 --- a/internal/commands/show/utils_test.go +++ b/internal/commands/show/utils_test.go @@ -30,7 +30,7 @@ import ( "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/controller-runtime/pkg/client" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/utils" ) diff --git a/internal/commands/snapshot/diff.go b/internal/commands/snapshot/diff.go index 6dcf3cef..e9209b4a 100644 --- a/internal/commands/snapshot/diff.go +++ b/internal/commands/snapshot/diff.go @@ -38,10 +38,10 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/klog/v2/textlogger" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" logs "github.com/projectsveltos/libsveltos/lib/logsettings" - utilsv1alpha1 "github.com/projectsveltos/sveltosctl/api/v1alpha1" + utilsv1beta1 "github.com/projectsveltos/sveltosctl/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/collector" "github.com/projectsveltos/sveltosctl/internal/utils" ) @@ -99,7 +99,7 @@ func listSnapshotDiffs(ctx context.Context, snapshotName, fromSample, toSample, // Get the directory containing the collected snapshots for Snapshot instance snapshotName instance := utils.GetAccessInstance() - snapshotInstance := &utilsv1alpha1.Snapshot{} + snapshotInstance := &utilsv1beta1.Snapshot{} err := instance.GetResource(ctx, types.NamespacedName{Name: snapshotName}, snapshotInstance) if err != nil { return err @@ -135,12 +135,12 @@ func listSnapshotDiffs(ctx context.Context, snapshotName, fromSample, toSample, return err } - err = listDiff(fromFolder, toFolder, libsveltosv1alpha1.ClassifierKind, rawDiff, logger) + err = listDiff(fromFolder, toFolder, libsveltosv1beta1.ClassifierKind, rawDiff, logger) if err != nil { return err } - err = listDiff(fromFolder, toFolder, libsveltosv1alpha1.RoleRequestKind, rawDiff, logger) + err = listDiff(fromFolder, toFolder, libsveltosv1beta1.RoleRequestKind, rawDiff, logger) if err != nil { return err } @@ -701,7 +701,7 @@ func getResourceFromResourceOwner(folder string, resource *configv1alpha1.Resour } var data map[string]string - if owner.DeepCopy().GroupVersionKind().Kind == string(libsveltosv1alpha1.ConfigMapReferencedResourceKind) { + if owner.DeepCopy().GroupVersionKind().Kind == string(libsveltosv1beta1.ConfigMapReferencedResourceKind) { var configMap corev1.ConfigMap err = runtime.DefaultUnstructuredConverter.FromUnstructured(owner.UnstructuredContent(), &configMap) if err != nil { diff --git a/internal/commands/snapshot/diff_test.go b/internal/commands/snapshot/diff_test.go index ab8ce9d6..7bedfc95 100644 --- a/internal/commands/snapshot/diff_test.go +++ b/internal/commands/snapshot/diff_test.go @@ -39,9 +39,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" - utilsv1alpha1 "github.com/projectsveltos/sveltosctl/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" + utilsv1beta1 "github.com/projectsveltos/sveltosctl/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/collector" "github.com/projectsveltos/sveltosctl/internal/commands/snapshot" "github.com/projectsveltos/sveltosctl/internal/utils" @@ -52,11 +52,11 @@ var _ = Describe("Snapshot Diff", func() { }) It("snapshot diff displays all diff between two snapshot collections", func() { - snapshotInstance := &utilsv1alpha1.Snapshot{ + snapshotInstance := &utilsv1beta1.Snapshot{ ObjectMeta: metav1.ObjectMeta{ Name: randomString(), }, - Spec: utilsv1alpha1.SnapshotSpec{ + Spec: utilsv1beta1.SnapshotSpec{ Storage: randomString(), }, } @@ -143,11 +143,11 @@ var _ = Describe("Snapshot Diff", func() { }) It("listdiff displays all diff between Classifiers/RoleRequests", func() { - snapshotInstance := &utilsv1alpha1.Snapshot{ + snapshotInstance := &utilsv1beta1.Snapshot{ ObjectMeta: metav1.ObjectMeta{ Name: randomString(), }, - Spec: utilsv1alpha1.SnapshotSpec{ + Spec: utilsv1beta1.SnapshotSpec{ Storage: randomString(), }, } @@ -163,36 +163,40 @@ var _ = Describe("Snapshot Diff", func() { Expect(os.Mkdir(tmpDir, os.ModePerm)).To(Succeed()) classifierName := randomString() - classifier := &libsveltosv1alpha1.Classifier{ + classifier := &libsveltosv1beta1.Classifier{ ObjectMeta: metav1.ObjectMeta{ Name: classifierName, }, - Spec: libsveltosv1alpha1.ClassifierSpec{ - ClassifierLabels: []libsveltosv1alpha1.ClassifierLabel{ + Spec: libsveltosv1beta1.ClassifierSpec{ + ClassifierLabels: []libsveltosv1beta1.ClassifierLabel{ {Key: randomString(), Value: randomString()}, }, }, } Expect(addTypeInformationToObject(classifier)).To(Succeed()) - roleRequest := &libsveltosv1alpha1.RoleRequest{ + roleRequest := &libsveltosv1beta1.RoleRequest{ ObjectMeta: metav1.ObjectMeta{ Name: classifierName, }, - Spec: libsveltosv1alpha1.RoleRequestSpec{ + Spec: libsveltosv1beta1.RoleRequestSpec{ ServiceAccountNamespace: randomString(), ServiceAccountName: randomString(), - ClusterSelector: libsveltosv1alpha1.Selector("zone:west"), + ClusterSelector: libsveltosv1beta1.Selector{ + LabelSelector: metav1.LabelSelector{ + MatchLabels: map[string]string{"zone": "west"}, + }, + }, }, } Expect(addTypeInformationToObject(roleRequest)).To(Succeed()) - classifierDeleted := &libsveltosv1alpha1.Classifier{ + classifierDeleted := &libsveltosv1beta1.Classifier{ ObjectMeta: metav1.ObjectMeta{ Name: randomString(), }, - Spec: libsveltosv1alpha1.ClassifierSpec{ - ClassifierLabels: []libsveltosv1alpha1.ClassifierLabel{ + Spec: libsveltosv1beta1.ClassifierSpec{ + ClassifierLabels: []libsveltosv1beta1.ClassifierLabel{ {Key: randomString(), Value: randomString()}, }, }, @@ -205,13 +209,13 @@ var _ = Describe("Snapshot Diff", func() { time.Sleep(2 * time.Second) // wait so to simulate a snapshot at a different time classifier.Spec.ClassifierLabels = - append(classifier.Spec.ClassifierLabels, libsveltosv1alpha1.ClassifierLabel{Key: randomString(), Value: randomString()}) - classifierAdded := &libsveltosv1alpha1.Classifier{ + append(classifier.Spec.ClassifierLabels, libsveltosv1beta1.ClassifierLabel{Key: randomString(), Value: randomString()}) + classifierAdded := &libsveltosv1beta1.Classifier{ ObjectMeta: metav1.ObjectMeta{ Name: randomString(), }, - Spec: libsveltosv1alpha1.ClassifierSpec{ - ClassifierLabels: []libsveltosv1alpha1.ClassifierLabel{ + Spec: libsveltosv1beta1.ClassifierSpec{ + ClassifierLabels: []libsveltosv1beta1.ClassifierLabel{ {Key: randomString(), Value: randomString()}, }, }, @@ -242,7 +246,7 @@ var _ = Describe("Snapshot Diff", func() { fromFolder := filepath.Join(*artifactFolder, timeOne) toFolder := filepath.Join(*artifactFolder, timeTwo) - err = snapshot.ListDiff(fromFolder, toFolder, libsveltosv1alpha1.ClassifierKind, false, + err = snapshot.ListDiff(fromFolder, toFolder, libsveltosv1beta1.ClassifierKind, false, textlogger.NewLogger(textlogger.NewConfig(textlogger.Verbosity(1)))) Expect(err).To(BeNil()) @@ -286,7 +290,7 @@ var _ = Describe("Snapshot Diff", func() { r, w, _ = os.Pipe() os.Stdout = w - err = snapshot.ListDiff(fromFolder, toFolder, libsveltosv1alpha1.RoleRequestKind, false, + err = snapshot.ListDiff(fromFolder, toFolder, libsveltosv1beta1.RoleRequestKind, false, textlogger.NewLogger(textlogger.NewConfig(textlogger.Verbosity(1)))) Expect(err).To(BeNil()) @@ -438,7 +442,7 @@ var _ = Describe("Snapshot Diff", func() { Name: clusterRole.GetName(), LastAppliedTime: &metav1.Time{Time: time.Now()}, Owner: corev1.ObjectReference{ - Kind: string(libsveltosv1alpha1.ConfigMapReferencedResourceKind), + Kind: string(libsveltosv1beta1.ConfigMapReferencedResourceKind), Name: oldConfigMap.Name, Namespace: oldConfigMap.Namespace, }, @@ -558,7 +562,7 @@ var _ = Describe("Snapshot Diff", func() { Group: clusterRoleGroup, Kind: clusterRoleKind, Owner: corev1.ObjectReference{ - Kind: string(libsveltosv1alpha1.ConfigMapReferencedResourceKind), + Kind: string(libsveltosv1beta1.ConfigMapReferencedResourceKind), Name: configMap.Name, Namespace: configMap.Namespace, }, diff --git a/internal/commands/snapshot/list.go b/internal/commands/snapshot/list.go index 813d71f7..78832000 100644 --- a/internal/commands/snapshot/list.go +++ b/internal/commands/snapshot/list.go @@ -31,7 +31,7 @@ import ( "github.com/projectsveltos/sveltosctl/internal/collector" "github.com/projectsveltos/sveltosctl/internal/utils" - utilsv1alpha1 "github.com/projectsveltos/sveltosctl/api/v1alpha1" + utilsv1beta1 "github.com/projectsveltos/sveltosctl/api/v1beta1" ) var ( @@ -46,7 +46,7 @@ var ( } ) -func doConsiderSnapshot(snaphostInstance *utilsv1alpha1.Snapshot, passedSnapshot string) bool { +func doConsiderSnapshot(snaphostInstance *utilsv1beta1.Snapshot, passedSnapshot string) bool { if passedSnapshot == "" { return true } @@ -70,7 +70,7 @@ func listSnapshots(ctx context.Context, passedSnapshotName string, logger logr.L func displaySnapshots(ctx context.Context, passedSnapshotName string, table *tablewriter.Table, logger logr.Logger) error { - snapshotList := &utilsv1alpha1.SnapshotList{} + snapshotList := &utilsv1beta1.SnapshotList{} logger.V(logs.LogDebug).Info("List all Snapshot instances") instance := utils.GetAccessInstance() err := instance.ListResources(ctx, snapshotList) @@ -89,7 +89,7 @@ func displaySnapshots(ctx context.Context, passedSnapshotName string, return nil } -func displaySnapshot(snapshotInstance *utilsv1alpha1.Snapshot, +func displaySnapshot(snapshotInstance *utilsv1beta1.Snapshot, table *tablewriter.Table, logger logr.Logger) error { logger.V(logs.LogDebug).Info(fmt.Sprintf("Considering Snapshot instance %s", snapshotInstance.Name)) diff --git a/internal/commands/snapshot/list_test.go b/internal/commands/snapshot/list_test.go index c59c74a6..ed02d180 100644 --- a/internal/commands/snapshot/list_test.go +++ b/internal/commands/snapshot/list_test.go @@ -32,7 +32,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - utilsv1alpha1 "github.com/projectsveltos/sveltosctl/api/v1alpha1" + utilsv1beta1 "github.com/projectsveltos/sveltosctl/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/collector" "github.com/projectsveltos/sveltosctl/internal/commands/snapshot" "github.com/projectsveltos/sveltosctl/internal/utils" @@ -43,11 +43,11 @@ var _ = Describe("Snapshot List", func() { }) It("snapshot list displays all snapshots collected per Snapshot instance", func() { - snapshotInstance := &utilsv1alpha1.Snapshot{ + snapshotInstance := &utilsv1beta1.Snapshot{ ObjectMeta: metav1.ObjectMeta{ Name: randomString(), }, - Spec: utilsv1alpha1.SnapshotSpec{ + Spec: utilsv1beta1.SnapshotSpec{ Storage: randomString(), }, } diff --git a/internal/commands/snapshot/rollback.go b/internal/commands/snapshot/rollback.go index 62a5b5b6..82e1eb8e 100644 --- a/internal/commands/snapshot/rollback.go +++ b/internal/commands/snapshot/rollback.go @@ -34,10 +34,10 @@ import ( "k8s.io/klog/v2/textlogger" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" logs "github.com/projectsveltos/libsveltos/lib/logsettings" - utilsv1alpha1 "github.com/projectsveltos/sveltosctl/api/v1alpha1" + utilsv1beta1 "github.com/projectsveltos/sveltosctl/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/collector" "github.com/projectsveltos/sveltosctl/internal/utils" ) @@ -51,7 +51,7 @@ func rollbackConfiguration(ctx context.Context, // Get the directory containing the collected snapshots for Snapshot instance snapshotName instance := utils.GetAccessInstance() - snapshotInstance := &utilsv1alpha1.Snapshot{} + snapshotInstance := &utilsv1beta1.Snapshot{} err := instance.GetResource(ctx, types.NamespacedName{Name: snapshotName}, snapshotInstance) if err != nil { return err @@ -188,7 +188,7 @@ func getAndRollbackCAPIClusters(ctx context.Context, folder, passedNamespace, pa for ns := range clusterMap { if passedNamespace == "" || ns == passedNamespace { logger.V(logs.LogDebug).Info(fmt.Sprintf("rollback Clusters in namespace %s", ns)) - err = rollbackClusters(ctx, clusterMap[ns], passedCluster, libsveltosv1alpha1.ClusterTypeCapi, logger) + err = rollbackClusters(ctx, clusterMap[ns], passedCluster, libsveltosv1beta1.ClusterTypeCapi, logger) if err != nil { return err } @@ -200,7 +200,7 @@ func getAndRollbackCAPIClusters(ctx context.Context, folder, passedNamespace, pa func getAndRollbackSveltosClusters(ctx context.Context, folder, passedNamespace, passedCluster string, logger logr.Logger) error { snapshotClient := collector.GetClient() - clusterMap, err := snapshotClient.GetNamespacedResources(folder, libsveltosv1alpha1.SveltosClusterKind, logger) + clusterMap, err := snapshotClient.GetNamespacedResources(folder, libsveltosv1beta1.SveltosClusterKind, logger) if err != nil { logger.V(logs.LogDebug).Info(fmt.Sprintf("failed to collect SveltosCluster from folder %s", folder)) return err @@ -209,7 +209,7 @@ func getAndRollbackSveltosClusters(ctx context.Context, folder, passedNamespace, for ns := range clusterMap { if passedNamespace == "" || ns == passedNamespace { logger.V(logs.LogDebug).Info(fmt.Sprintf("rollback Clusters in namespace %s", ns)) - err = rollbackClusters(ctx, clusterMap[ns], passedCluster, libsveltosv1alpha1.ClusterTypeSveltos, logger) + err = rollbackClusters(ctx, clusterMap[ns], passedCluster, libsveltosv1beta1.ClusterTypeSveltos, logger) if err != nil { return err } @@ -276,7 +276,7 @@ func rollbackProfiles(ctx context.Context, resources []*unstructured.Unstructure func getAndRollbackClassifiers(ctx context.Context, folder, passedClassifier string, logger logr.Logger) error { snapshotClient := collector.GetClient() - classifiers, err := snapshotClient.GetClusterResources(folder, libsveltosv1alpha1.ClassifierKind, logger) + classifiers, err := snapshotClient.GetClusterResources(folder, libsveltosv1beta1.ClassifierKind, logger) if err != nil { logger.V(logs.LogDebug).Info(fmt.Sprintf("failed to collect Classifiers from folder %s", folder)) return err @@ -298,7 +298,7 @@ func getAndRollbackClassifiers(ctx context.Context, folder, passedClassifier str func getAndRollbackRoleRequests(ctx context.Context, folder, passedRoleRequest string, logger logr.Logger) error { snapshotClient := collector.GetClient() - roleRequests, err := snapshotClient.GetClusterResources(folder, libsveltosv1alpha1.RoleRequestKind, logger) + roleRequests, err := snapshotClient.GetClusterResources(folder, libsveltosv1beta1.RoleRequestKind, logger) if err != nil { logger.V(logs.LogDebug).Info(fmt.Sprintf("failed to collect RoleRequests from folder %s", folder)) return err @@ -409,7 +409,7 @@ func rollbackSecret(ctx context.Context, resource *unstructured.Unstructured, lo } func rollbackClusters(ctx context.Context, resources []*unstructured.Unstructured, passedCluster string, - clusterType libsveltosv1alpha1.ClusterType, logger logr.Logger) error { + clusterType libsveltosv1beta1.ClusterType, logger logr.Logger) error { for i := range resources { if passedCluster == "" || resources[i].GetName() == passedCluster { @@ -427,9 +427,9 @@ func rollbackClusters(ctx context.Context, resources []*unstructured.Unstructure // rollbackCluster does not nothing if Cluster currently does not exist. // If Cluster currently exists, then it updates Cluster.Labels func rollbackCluster(ctx context.Context, resource *unstructured.Unstructured, - clusterType libsveltosv1alpha1.ClusterType, logger logr.Logger) error { + clusterType libsveltosv1beta1.ClusterType, logger logr.Logger) error { - if clusterType == libsveltosv1alpha1.ClusterTypeCapi { + if clusterType == libsveltosv1beta1.ClusterTypeCapi { return rollbackCAPICluster(ctx, resource, logger) } @@ -469,7 +469,7 @@ func rollbackCAPICluster(ctx context.Context, resource *unstructured.Unstructure func rollbackSveltosCluster(ctx context.Context, resource *unstructured.Unstructured, logger logr.Logger) error { instance := utils.GetAccessInstance() - currentCluster := &libsveltosv1alpha1.SveltosCluster{} + currentCluster := &libsveltosv1beta1.SveltosCluster{} err := instance.GetResource(ctx, types.NamespacedName{Namespace: resource.GetNamespace(), Name: resource.GetName()}, currentCluster) @@ -482,7 +482,7 @@ func rollbackSveltosCluster(ctx context.Context, resource *unstructured.Unstruct return err } - passedCluster := &libsveltosv1alpha1.SveltosCluster{} + passedCluster := &libsveltosv1beta1.SveltosCluster{} err = runtime.DefaultUnstructuredConverter. FromUnstructured(resource.UnstructuredContent(), passedCluster) if err != nil { @@ -567,7 +567,7 @@ func rollbackProfile(ctx context.Context, resource *unstructured.Unstructured, l func rollbackClassifier(ctx context.Context, resource *unstructured.Unstructured, logger logr.Logger) error { instance := utils.GetAccessInstance() - currentClassifier := &libsveltosv1alpha1.Classifier{} + currentClassifier := &libsveltosv1beta1.Classifier{} err := instance.GetResource(ctx, types.NamespacedName{Name: resource.GetName()}, currentClassifier) if err != nil { @@ -579,7 +579,7 @@ func rollbackClassifier(ctx context.Context, resource *unstructured.Unstructured return err } - passedClassifier := &libsveltosv1alpha1.Classifier{} + passedClassifier := &libsveltosv1beta1.Classifier{} err = runtime.DefaultUnstructuredConverter. FromUnstructured(resource.UnstructuredContent(), passedClassifier) if err != nil { diff --git a/internal/commands/snapshot/rollback_test.go b/internal/commands/snapshot/rollback_test.go index 7c211086..00a9b8ec 100644 --- a/internal/commands/snapshot/rollback_test.go +++ b/internal/commands/snapshot/rollback_test.go @@ -35,8 +35,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/collector" "github.com/projectsveltos/sveltosctl/internal/commands/snapshot" "github.com/projectsveltos/sveltosctl/internal/utils" @@ -74,12 +74,14 @@ metadata: name: %s type: Opaque` - clusterProfileTemplate = `apiVersion: config.projectsveltos.io/v1alpha1 + clusterProfileTemplate = `apiVersion: config.projectsveltos.io/v1beta1 kind: ClusterProfile metadata: name: %s spec: - clusterSelector: env=fv + clusterSelector: + matchLabels: + env: fv policyRefs: - kind: ConfigMap name: featurei9nyv583mu @@ -275,7 +277,7 @@ var _ = Describe("Snapshot Rollback", func() { // Rollback Expect(snapshot.RollbackClusters(context.TODO(), []*unstructured.Unstructured{cluster}, "", - libsveltosv1alpha1.ClusterTypeCapi, + libsveltosv1beta1.ClusterTypeCapi, textlogger.NewLogger(textlogger.NewConfig(textlogger.Verbosity(1))))).To(Succeed()) Expect(instance.GetResource(context.TODO(), diff --git a/internal/commands/snapshot_reconciler.go b/internal/commands/snapshot_reconciler.go index fda3aa20..1f49c570 100644 --- a/internal/commands/snapshot_reconciler.go +++ b/internal/commands/snapshot_reconciler.go @@ -28,7 +28,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" logs "github.com/projectsveltos/libsveltos/lib/logsettings" - utilsv1alpha1 "github.com/projectsveltos/sveltosctl/api/v1alpha1" + utilsv1beta1 "github.com/projectsveltos/sveltosctl/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/collector" "github.com/projectsveltos/sveltosctl/internal/utils" ) @@ -39,7 +39,7 @@ func SnapshotReconciler(ctx context.Context, req reconcile.Request) (reconcile.R accessInstance := utils.GetAccessInstance() - snapshotInstance := &utilsv1alpha1.Snapshot{} + snapshotInstance := &utilsv1beta1.Snapshot{} if err := accessInstance.GetResource(ctx, req.NamespacedName, snapshotInstance); err != nil { logger.Error(err, "unable to fetch Snapshot") return ctrl.Result{}, client.IgnoreNotFound(err) @@ -49,17 +49,17 @@ func SnapshotReconciler(ctx context.Context, req reconcile.Request) (reconcile.R if !snapshotInstance.DeletionTimestamp.IsZero() { return reconcileDelete(ctx, snapshotInstance, collector.Snapshot, snapshotInstance.Spec.Storage, - utilsv1alpha1.SnapshotFinalizer, logger) + utilsv1beta1.SnapshotFinalizer, logger) } return reconcileSnapshotNormal(ctx, snapshotInstance, logger) } -func reconcileSnapshotNormal(ctx context.Context, snapshotInstance *utilsv1alpha1.Snapshot, +func reconcileSnapshotNormal(ctx context.Context, snapshotInstance *utilsv1beta1.Snapshot, logger logr.Logger) (reconcile.Result, error) { logger.V(logs.LogInfo).Info("reconcileSnapshotNormal") - if err := addFinalizer(ctx, snapshotInstance, utilsv1alpha1.SnapshotFinalizer); err != nil { + if err := addFinalizer(ctx, snapshotInstance, utilsv1beta1.SnapshotFinalizer); err != nil { logger.V(logs.LogInfo).Info(fmt.Sprintf("failed to add finalizer: %s", err)) return reconcile.Result{}, err } diff --git a/internal/commands/snapshot_reconciler_utils.go b/internal/commands/snapshot_reconciler_utils.go index 6c523f5f..668167e9 100644 --- a/internal/commands/snapshot_reconciler_utils.go +++ b/internal/commands/snapshot_reconciler_utils.go @@ -30,16 +30,16 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/controller-runtime/pkg/client" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" logs "github.com/projectsveltos/libsveltos/lib/logsettings" - utilsv1alpha1 "github.com/projectsveltos/sveltosctl/api/v1alpha1" + utilsv1beta1 "github.com/projectsveltos/sveltosctl/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/collector" "github.com/projectsveltos/sveltosctl/internal/utils" ) type collectionSnapshot struct { - snapshotInstance *utilsv1alpha1.Snapshot + snapshotInstance *utilsv1beta1.Snapshot } func (c *collectionSnapshot) getCreationTimestamp() *metav1.Time { @@ -70,7 +70,7 @@ func (c *collectionSnapshot) getStartingDeadlineSeconds() *int64 { return c.snapshotInstance.Spec.StartingDeadlineSeconds } -func (c *collectionSnapshot) setLastRunStatus(s utilsv1alpha1.CollectionStatus) { +func (c *collectionSnapshot) setLastRunStatus(s utilsv1beta1.CollectionStatus) { c.snapshotInstance.Status.LastRunStatus = &s } @@ -83,7 +83,7 @@ func collectSnapshot(ctx context.Context, c client.Client, snapshotName string, logger.V(logs.LogInfo).Info("collect snapshot") // Get Snapshot instance - snapshotInstance := &utilsv1alpha1.Snapshot{} + snapshotInstance := &utilsv1beta1.Snapshot{} err := c.Get(ctx, types.NamespacedName{Name: snapshotName}, snapshotInstance) if err != nil { if apierrors.IsNotFound(err) { @@ -317,13 +317,13 @@ func dumpProfiles(collectorClient *collector.Collector, ctx context.Context, fol } func dumpReferencedObjects(collectorClient *collector.Collector, ctx context.Context, - referencedObjects []libsveltosv1alpha1.PolicyRef, folder string, logger logr.Logger) error { + referencedObjects []libsveltosv1beta1.PolicyRef, folder string, logger logr.Logger) error { logger.V(logs.LogDebug).Info("storing ClusterProfiles's referenced resources") var object client.Object for i := range referencedObjects { ref := &referencedObjects[i] - if ref.Kind == string(libsveltosv1alpha1.ConfigMapReferencedResourceKind) { + if ref.Kind == string(libsveltosv1beta1.ConfigMapReferencedResourceKind) { configMap := &corev1.ConfigMap{} err := utils.GetAccessInstance().GetResource(ctx, types.NamespacedName{Namespace: ref.Namespace, Name: ref.Name}, configMap) @@ -397,7 +397,7 @@ func dumpCAPIClusters(collectorClient *collector.Collector, ctx context.Context, func dumpSveltosClusters(collectorClient *collector.Collector, ctx context.Context, folder string, logger logr.Logger) error { logger.V(logs.LogDebug).Info("storing Sveltos Clusters") - clusterList := &libsveltosv1alpha1.SveltosClusterList{} + clusterList := &libsveltosv1beta1.SveltosClusterList{} err := utils.GetAccessInstance().ListResources(ctx, clusterList) if err != nil { return err @@ -426,7 +426,7 @@ func dumpClusters(collectorClient *collector.Collector, ctx context.Context, fol return nil } -func updateSnaphotPredicate(newObject, oldObject *utilsv1alpha1.Snapshot) bool { +func updateSnaphotPredicate(newObject, oldObject *utilsv1beta1.Snapshot) bool { if oldObject == nil || !reflect.DeepEqual(newObject.Spec, oldObject.Spec) { @@ -436,11 +436,11 @@ func updateSnaphotPredicate(newObject, oldObject *utilsv1alpha1.Snapshot) bool { return false } -func convertConfigPolicyRefsToLibsveltosPolicyRefs(input []configv1alpha1.PolicyRef) []libsveltosv1alpha1.PolicyRef { - policyRefs := make([]libsveltosv1alpha1.PolicyRef, len(input)) +func convertConfigPolicyRefsToLibsveltosPolicyRefs(input []configv1alpha1.PolicyRef) []libsveltosv1beta1.PolicyRef { + policyRefs := make([]libsveltosv1beta1.PolicyRef, len(input)) for i := range input { - policyRefs[i] = libsveltosv1alpha1.PolicyRef{ + policyRefs[i] = libsveltosv1beta1.PolicyRef{ Kind: input[i].Kind, Namespace: input[i].Namespace, Name: input[i].Name, diff --git a/internal/commands/techsupport/list.go b/internal/commands/techsupport/list.go index 982108c8..a2c1be50 100644 --- a/internal/commands/techsupport/list.go +++ b/internal/commands/techsupport/list.go @@ -31,7 +31,7 @@ import ( "github.com/projectsveltos/sveltosctl/internal/collector" "github.com/projectsveltos/sveltosctl/internal/utils" - utilsv1alpha1 "github.com/projectsveltos/sveltosctl/api/v1alpha1" + utilsv1beta1 "github.com/projectsveltos/sveltosctl/api/v1beta1" ) var ( @@ -46,7 +46,7 @@ var ( } ) -func doConsiderTechsupport(techsupportInstance *utilsv1alpha1.Techsupport, passedTechsupport string) bool { +func doConsiderTechsupport(techsupportInstance *utilsv1beta1.Techsupport, passedTechsupport string) bool { if passedTechsupport == "" { return true } @@ -70,7 +70,7 @@ func listTechsupports(ctx context.Context, passedTechsupportName string, logger func displayTechsupports(ctx context.Context, passedTechsupportName string, table *tablewriter.Table, logger logr.Logger) error { - techsupportList := &utilsv1alpha1.TechsupportList{} + techsupportList := &utilsv1beta1.TechsupportList{} logger.V(logs.LogDebug).Info("List all Techsupport instances") instance := utils.GetAccessInstance() err := instance.ListResources(ctx, techsupportList) @@ -89,7 +89,7 @@ func displayTechsupports(ctx context.Context, passedTechsupportName string, return nil } -func displayTechsupport(techsupportInstance *utilsv1alpha1.Techsupport, +func displayTechsupport(techsupportInstance *utilsv1beta1.Techsupport, table *tablewriter.Table, logger logr.Logger) error { logger.V(logs.LogDebug).Info(fmt.Sprintf("Considering Techsupport instance %s", techsupportInstance.Name)) diff --git a/internal/commands/techsupport/list_test.go b/internal/commands/techsupport/list_test.go index a82c4466..4aafe99c 100644 --- a/internal/commands/techsupport/list_test.go +++ b/internal/commands/techsupport/list_test.go @@ -32,7 +32,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - utilsv1alpha1 "github.com/projectsveltos/sveltosctl/api/v1alpha1" + utilsv1beta1 "github.com/projectsveltos/sveltosctl/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/collector" "github.com/projectsveltos/sveltosctl/internal/commands/techsupport" "github.com/projectsveltos/sveltosctl/internal/utils" @@ -43,11 +43,11 @@ var _ = Describe("Techsupport List", func() { }) It("techsupport list displays all techsupports collected per Techsupport instance", func() { - techsupportInstance := &utilsv1alpha1.Techsupport{ + techsupportInstance := &utilsv1beta1.Techsupport{ ObjectMeta: metav1.ObjectMeta{ Name: randomString(), }, - Spec: utilsv1alpha1.TechsupportSpec{ + Spec: utilsv1beta1.TechsupportSpec{ Storage: randomString(), }, } diff --git a/internal/commands/techsupport_reconciler.go b/internal/commands/techsupport_reconciler.go index 1a22cf35..09b18dc7 100644 --- a/internal/commands/techsupport_reconciler.go +++ b/internal/commands/techsupport_reconciler.go @@ -24,6 +24,7 @@ import ( "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/klog/v2/textlogger" @@ -33,10 +34,10 @@ import ( "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/reconcile" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" logs "github.com/projectsveltos/libsveltos/lib/logsettings" libsveltosset "github.com/projectsveltos/libsveltos/lib/set" - utilsv1alpha1 "github.com/projectsveltos/sveltosctl/api/v1alpha1" + utilsv1beta1 "github.com/projectsveltos/sveltosctl/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/collector" "github.com/projectsveltos/sveltosctl/internal/utils" ) @@ -47,7 +48,7 @@ func TechsupportReconciler(ctx context.Context, req reconcile.Request) (reconcil accessInstance := utils.GetAccessInstance() - techsupportInstance := &utilsv1alpha1.Techsupport{} + techsupportInstance := &utilsv1beta1.Techsupport{} if err := accessInstance.GetResource(ctx, req.NamespacedName, techsupportInstance); err != nil { logger.Error(err, "unable to fetch Techsupport") return ctrl.Result{}, client.IgnoreNotFound(err) @@ -57,7 +58,7 @@ func TechsupportReconciler(ctx context.Context, req reconcile.Request) (reconcil if !techsupportInstance.DeletionTimestamp.IsZero() { if result, err := reconcileDelete(ctx, techsupportInstance, collector.Techsupport, techsupportInstance.Spec.Storage, - utilsv1alpha1.TechsupportFinalizer, logger); err != nil { + utilsv1beta1.TechsupportFinalizer, logger); err != nil { return result, err } cleanMaps(techsupportInstance) @@ -67,11 +68,11 @@ func TechsupportReconciler(ctx context.Context, req reconcile.Request) (reconcil return reconcileTechsupportNormal(ctx, techsupportInstance, logger) } -func reconcileTechsupportNormal(ctx context.Context, techsupportInstance *utilsv1alpha1.Techsupport, +func reconcileTechsupportNormal(ctx context.Context, techsupportInstance *utilsv1beta1.Techsupport, logger logr.Logger) (reconcile.Result, error) { logger.V(logs.LogInfo).Info("reconcileTechsupportNormal") - if err := addFinalizer(ctx, techsupportInstance, utilsv1alpha1.TechsupportFinalizer); err != nil { + if err := addFinalizer(ctx, techsupportInstance, utilsv1beta1.TechsupportFinalizer); err != nil { logger.V(logs.LogInfo).Info(fmt.Sprintf("failed to add finalizer: %s", err)) return reconcile.Result{}, err } @@ -197,7 +198,7 @@ type SveltosClusterPredicate struct { Logger logr.Logger } -func (p SveltosClusterPredicate) Create(obj event.TypedCreateEvent[*libsveltosv1alpha1.SveltosCluster]) bool { +func (p SveltosClusterPredicate) Create(obj event.TypedCreateEvent[*libsveltosv1beta1.SveltosCluster]) bool { cluster := obj.Object log := p.Logger.WithValues("predicate", "createEvent", "namespace", cluster.Namespace, @@ -216,7 +217,7 @@ func (p SveltosClusterPredicate) Create(obj event.TypedCreateEvent[*libsveltosv1 return false } -func (p SveltosClusterPredicate) Update(obj event.TypedUpdateEvent[*libsveltosv1alpha1.SveltosCluster]) bool { +func (p SveltosClusterPredicate) Update(obj event.TypedUpdateEvent[*libsveltosv1beta1.SveltosCluster]) bool { newCluster := obj.ObjectNew oldCluster := obj.ObjectOld log := p.Logger.WithValues("predicate", "updateEvent", @@ -255,7 +256,7 @@ func (p SveltosClusterPredicate) Update(obj event.TypedUpdateEvent[*libsveltosv1 return false } -func (p SveltosClusterPredicate) Delete(obj event.TypedDeleteEvent[*libsveltosv1alpha1.SveltosCluster]) bool { +func (p SveltosClusterPredicate) Delete(obj event.TypedDeleteEvent[*libsveltosv1beta1.SveltosCluster]) bool { log := p.Logger.WithValues("predicate", "deleteEvent", "namespace", obj.Object.GetNamespace(), "cluster", obj.Object.GetName(), @@ -265,7 +266,7 @@ func (p SveltosClusterPredicate) Delete(obj event.TypedDeleteEvent[*libsveltosv1 return true } -func (p SveltosClusterPredicate) Generic(obj event.TypedGenericEvent[*libsveltosv1alpha1.SveltosCluster]) bool { +func (p SveltosClusterPredicate) Generic(obj event.TypedGenericEvent[*libsveltosv1beta1.SveltosCluster]) bool { log := p.Logger.WithValues("predicate", "genericEvent", "namespace", obj.Object.GetNamespace(), "cluster", obj.Object.GetName(), @@ -275,7 +276,7 @@ func (p SveltosClusterPredicate) Generic(obj event.TypedGenericEvent[*libsveltos return false } -func updateMaps(techsupport *utilsv1alpha1.Techsupport) { +func updateMaps(techsupport *utilsv1beta1.Techsupport) { currentClusters := &libsveltosset.Set{} for i := range techsupport.Status.MatchingClusterRefs { cluster := techsupport.Status.MatchingClusterRefs[i] @@ -311,7 +312,7 @@ func updateMaps(techsupport *utilsv1alpha1.Techsupport) { techsupports[*techsupportInfo] = techsupport.Spec.ClusterSelector } -func cleanMaps(techsupport *utilsv1alpha1.Techsupport) { +func cleanMaps(techsupport *utilsv1beta1.Techsupport) { mux.Lock() defer mux.Unlock() @@ -367,24 +368,24 @@ func getClusterMapForEntry(entry *corev1.ObjectReference) *libsveltosset.Set { } // getMatchingClusters returns all Sveltos/CAPI Clusters currently matching Techsupport.Spec.ClusterSelector -func getMatchingClusters(ctx context.Context, techsupport *utilsv1alpha1.Techsupport, +func getMatchingClusters(ctx context.Context, techsupport *utilsv1beta1.Techsupport, ) ([]corev1.ObjectReference, error) { matching := make([]corev1.ObjectReference, 0) - parsedSelector, err := labels.Parse(string(techsupport.Spec.ClusterSelector)) + clusterSelector, err := metav1.LabelSelectorAsSelector(&techsupport.Spec.ClusterSelector.LabelSelector) if err != nil { return nil, err } - tmpMatching, err := getMatchingCAPIClusters(ctx, parsedSelector) + tmpMatching, err := getMatchingCAPIClusters(ctx, clusterSelector) if err != nil { return nil, err } matching = append(matching, tmpMatching...) - tmpMatching, err = getMatchingSveltosClusters(ctx, parsedSelector) + tmpMatching, err = getMatchingSveltosClusters(ctx, clusterSelector) if err != nil { return nil, err } @@ -429,7 +430,7 @@ func getMatchingCAPIClusters(ctx context.Context, parsedSelector labels.Selector func getMatchingSveltosClusters(ctx context.Context, parsedSelector labels.Selector) ([]corev1.ObjectReference, error) { instance := utils.GetAccessInstance() - clusterList := &libsveltosv1alpha1.SveltosClusterList{} + clusterList := &libsveltosv1beta1.SveltosClusterList{} if err := instance.ListResources(ctx, clusterList); err != nil { return nil, err } diff --git a/internal/commands/techsupport_reconciler_test.go b/internal/commands/techsupport_reconciler_test.go index 523f854c..bee7bcb3 100644 --- a/internal/commands/techsupport_reconciler_test.go +++ b/internal/commands/techsupport_reconciler_test.go @@ -26,7 +26,7 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/controller-runtime/pkg/event" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/commands" ) @@ -36,11 +36,11 @@ const ( var _ = Describe("ClusterProfile Predicates: SvelotsClusterPredicates", func() { var logger logr.Logger - var cluster *libsveltosv1alpha1.SveltosCluster + var cluster *libsveltosv1beta1.SveltosCluster BeforeEach(func() { logger = textlogger.NewLogger(textlogger.NewConfig(textlogger.Verbosity(1))) - cluster = &libsveltosv1alpha1.SveltosCluster{ + cluster = &libsveltosv1beta1.SveltosCluster{ ObjectMeta: metav1.ObjectMeta{ Name: upstreamClusterNamePrefix + randomString(), Namespace: "scpredicates" + randomString(), @@ -53,7 +53,7 @@ var _ = Describe("ClusterProfile Predicates: SvelotsClusterPredicates", func() { cluster.Spec.Paused = false - result := clusterPredicate.Create(event.TypedCreateEvent[*libsveltosv1alpha1.SveltosCluster]{Object: cluster}) + result := clusterPredicate.Create(event.TypedCreateEvent[*libsveltosv1beta1.SveltosCluster]{Object: cluster}) Expect(result).To(BeTrue()) }) It("Create does not reprocess when sveltos Cluster is paused", func() { @@ -62,13 +62,13 @@ var _ = Describe("ClusterProfile Predicates: SvelotsClusterPredicates", func() { cluster.Spec.Paused = true cluster.Annotations = map[string]string{clusterv1.PausedAnnotation: "true"} - result := clusterPredicate.Create(event.TypedCreateEvent[*libsveltosv1alpha1.SveltosCluster]{Object: cluster}) + result := clusterPredicate.Create(event.TypedCreateEvent[*libsveltosv1beta1.SveltosCluster]{Object: cluster}) Expect(result).To(BeFalse()) }) It("Delete does reprocess ", func() { clusterPredicate := commands.SveltosClusterPredicate{Logger: logger} - result := clusterPredicate.Delete(event.TypedDeleteEvent[*libsveltosv1alpha1.SveltosCluster]{Object: cluster}) + result := clusterPredicate.Delete(event.TypedDeleteEvent[*libsveltosv1beta1.SveltosCluster]{Object: cluster}) Expect(result).To(BeTrue()) }) It("Update reprocesses when sveltos Cluster paused changes from true to false", func() { @@ -76,7 +76,7 @@ var _ = Describe("ClusterProfile Predicates: SvelotsClusterPredicates", func() { cluster.Spec.Paused = false - oldCluster := &libsveltosv1alpha1.SveltosCluster{ + oldCluster := &libsveltosv1beta1.SveltosCluster{ ObjectMeta: metav1.ObjectMeta{ Name: cluster.Name, Namespace: cluster.Namespace, @@ -85,7 +85,7 @@ var _ = Describe("ClusterProfile Predicates: SvelotsClusterPredicates", func() { oldCluster.Spec.Paused = true oldCluster.Annotations = map[string]string{clusterv1.PausedAnnotation: "true"} - result := clusterPredicate.Update(event.TypedUpdateEvent[*libsveltosv1alpha1.SveltosCluster]{ + result := clusterPredicate.Update(event.TypedUpdateEvent[*libsveltosv1beta1.SveltosCluster]{ ObjectNew: cluster, ObjectOld: oldCluster}) Expect(result).To(BeTrue()) }) @@ -94,7 +94,7 @@ var _ = Describe("ClusterProfile Predicates: SvelotsClusterPredicates", func() { cluster.Spec.Paused = true cluster.Annotations = map[string]string{clusterv1.PausedAnnotation: "true"} - oldCluster := &libsveltosv1alpha1.SveltosCluster{ + oldCluster := &libsveltosv1beta1.SveltosCluster{ ObjectMeta: metav1.ObjectMeta{ Name: cluster.Name, Namespace: cluster.Namespace, @@ -102,7 +102,7 @@ var _ = Describe("ClusterProfile Predicates: SvelotsClusterPredicates", func() { } oldCluster.Spec.Paused = false - result := clusterPredicate.Update(event.TypedUpdateEvent[*libsveltosv1alpha1.SveltosCluster]{ + result := clusterPredicate.Update(event.TypedUpdateEvent[*libsveltosv1beta1.SveltosCluster]{ ObjectNew: cluster, ObjectOld: oldCluster}) Expect(result).To(BeFalse()) }) @@ -110,7 +110,7 @@ var _ = Describe("ClusterProfile Predicates: SvelotsClusterPredicates", func() { clusterPredicate := commands.SveltosClusterPredicate{Logger: logger} cluster.Spec.Paused = false - oldCluster := &libsveltosv1alpha1.SveltosCluster{ + oldCluster := &libsveltosv1beta1.SveltosCluster{ ObjectMeta: metav1.ObjectMeta{ Name: cluster.Name, Namespace: cluster.Namespace, @@ -118,7 +118,7 @@ var _ = Describe("ClusterProfile Predicates: SvelotsClusterPredicates", func() { } oldCluster.Spec.Paused = false - result := clusterPredicate.Update(event.TypedUpdateEvent[*libsveltosv1alpha1.SveltosCluster]{ + result := clusterPredicate.Update(event.TypedUpdateEvent[*libsveltosv1beta1.SveltosCluster]{ ObjectNew: cluster, ObjectOld: oldCluster}) Expect(result).To(BeFalse()) }) @@ -127,7 +127,7 @@ var _ = Describe("ClusterProfile Predicates: SvelotsClusterPredicates", func() { cluster.Labels = map[string]string{"department": "eng"} - oldCluster := &libsveltosv1alpha1.SveltosCluster{ + oldCluster := &libsveltosv1beta1.SveltosCluster{ ObjectMeta: metav1.ObjectMeta{ Name: cluster.Name, Namespace: cluster.Namespace, @@ -135,7 +135,7 @@ var _ = Describe("ClusterProfile Predicates: SvelotsClusterPredicates", func() { }, } - result := clusterPredicate.Update(event.TypedUpdateEvent[*libsveltosv1alpha1.SveltosCluster]{ + result := clusterPredicate.Update(event.TypedUpdateEvent[*libsveltosv1beta1.SveltosCluster]{ ObjectNew: cluster, ObjectOld: oldCluster}) Expect(result).To(BeTrue()) }) @@ -144,17 +144,17 @@ var _ = Describe("ClusterProfile Predicates: SvelotsClusterPredicates", func() { cluster.Status.Ready = true - oldCluster := &libsveltosv1alpha1.SveltosCluster{ + oldCluster := &libsveltosv1beta1.SveltosCluster{ ObjectMeta: metav1.ObjectMeta{ Name: cluster.Name, Namespace: cluster.Namespace, Labels: map[string]string{}, }, - Status: libsveltosv1alpha1.SveltosClusterStatus{ + Status: libsveltosv1beta1.SveltosClusterStatus{ Ready: false, }, } - result := clusterPredicate.Update(event.TypedUpdateEvent[*libsveltosv1alpha1.SveltosCluster]{ + result := clusterPredicate.Update(event.TypedUpdateEvent[*libsveltosv1beta1.SveltosCluster]{ ObjectNew: cluster, ObjectOld: oldCluster}) Expect(result).To(BeTrue()) }) diff --git a/internal/commands/techsupport_reconciler_utils.go b/internal/commands/techsupport_reconciler_utils.go index a0e66708..a54d78e8 100644 --- a/internal/commands/techsupport_reconciler_utils.go +++ b/internal/commands/techsupport_reconciler_utils.go @@ -42,16 +42,16 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/reconcile" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" "github.com/projectsveltos/libsveltos/lib/clusterproxy" logs "github.com/projectsveltos/libsveltos/lib/logsettings" - utilsv1alpha1 "github.com/projectsveltos/sveltosctl/api/v1alpha1" + utilsv1beta1 "github.com/projectsveltos/sveltosctl/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/collector" "github.com/projectsveltos/sveltosctl/internal/utils" ) type collectionTechsupport struct { - techsupportInstance *utilsv1alpha1.Techsupport + techsupportInstance *utilsv1beta1.Techsupport } func (c *collectionTechsupport) getCreationTimestamp() *metav1.Time { @@ -82,7 +82,7 @@ func (c *collectionTechsupport) getStartingDeadlineSeconds() *int64 { return c.techsupportInstance.Spec.StartingDeadlineSeconds } -func (c *collectionTechsupport) setLastRunStatus(s utilsv1alpha1.CollectionStatus) { +func (c *collectionTechsupport) setLastRunStatus(s utilsv1beta1.CollectionStatus) { c.techsupportInstance.Status.LastRunStatus = &s } @@ -96,7 +96,7 @@ func collectTechsupport(ctx context.Context, c client.Client, techsupportName st logger = logger.WithValues("techsupport", techsupportName) logger.V(logs.LogInfo).Info("collect techsupport") - techsupportInstance := &utilsv1alpha1.Techsupport{} + techsupportInstance := &utilsv1beta1.Techsupport{} err := c.Get(ctx, types.NamespacedName{Name: techsupportName}, techsupportInstance) if err != nil { if apierrors.IsNotFound(err) { @@ -156,7 +156,7 @@ func collectTechsupport(ctx context.Context, c client.Client, techsupportName st return err } -func collectTechsupportForCluster(ctx context.Context, c client.Client, techsupportInstance *utilsv1alpha1.Techsupport, +func collectTechsupportForCluster(ctx context.Context, c client.Client, techsupportInstance *utilsv1beta1.Techsupport, cluster *corev1.ObjectReference, folder string, logger logr.Logger) error { ready, err := clusterproxy.IsClusterReadyToBeConfigured(ctx, c, cluster, logger) @@ -217,7 +217,7 @@ func collectTechsupportForCluster(ctx context.Context, c client.Client, techsupp return err } -func dumpResources(ctx context.Context, remoteRestConfig *rest.Config, resource *utilsv1alpha1.Resource, +func dumpResources(ctx context.Context, remoteRestConfig *rest.Config, resource *utilsv1beta1.Resource, folder string, logger logr.Logger) error { logger = logger.WithValues("gvk", fmt.Sprintf("%s:%s:%s", resource.Group, resource.Version, resource.Kind)) @@ -261,7 +261,7 @@ func dumpResources(ctx context.Context, remoteRestConfig *rest.Config, resource labelFilter += "," } f := resource.LabelFilters[i] - if f.Operation == libsveltosv1alpha1.OperationEqual { + if f.Operation == libsveltosv1beta1.OperationEqual { labelFilter += fmt.Sprintf("%s=%s", f.Key, f.Value) } else { labelFilter += fmt.Sprintf("%s!=%s", f.Key, f.Value) @@ -295,7 +295,7 @@ func dumpResources(ctx context.Context, remoteRestConfig *rest.Config, resource } func collectLogs(ctx context.Context, remoteClientSet *kubernetes.Clientset, remoteClient client.Client, - log *utilsv1alpha1.Log, folder string, logger logr.Logger) error { + log *utilsv1beta1.Log, folder string, logger logr.Logger) error { logger.V(logs.LogInfo).Info("collecting logs") options := client.ListOptions{} @@ -307,7 +307,7 @@ func collectLogs(ctx context.Context, remoteClientSet *kubernetes.Clientset, rem labelFilter += "," } f := log.LabelFilters[i] - if f.Operation == libsveltosv1alpha1.OperationEqual { + if f.Operation == libsveltosv1beta1.OperationEqual { labelFilter += fmt.Sprintf("%s=%s", f.Key, f.Value) } else { labelFilter += fmt.Sprintf("%s!=%s", f.Key, f.Value) @@ -341,7 +341,7 @@ func collectLogs(ctx context.Context, remoteClientSet *kubernetes.Clientset, rem return nil } -func updateTechsupportPredicate(newObject, oldObject *utilsv1alpha1.Techsupport) bool { +func updateTechsupportPredicate(newObject, oldObject *utilsv1beta1.Techsupport) bool { if oldObject == nil || !reflect.DeepEqual(newObject.Spec, oldObject.Spec) { @@ -352,7 +352,7 @@ func updateTechsupportPredicate(newObject, oldObject *utilsv1alpha1.Techsupport) } func requeueTechsupportForSveltosCluster( - ctx context.Context, sveltosCluster *libsveltosv1alpha1.SveltosCluster, + ctx context.Context, sveltosCluster *libsveltosv1beta1.SveltosCluster, ) []reconcile.Request { return requeueTechsupportForACluster(sveltosCluster) @@ -396,12 +396,11 @@ func requeueTechsupportForACluster( // matching the Cluster for k := range techsupports { techsupportSelector := techsupports[k] - parsedSelector, err := labels.Parse(string(techsupportSelector)) + clusterSelector, err := metav1.LabelSelectorAsSelector(&techsupportSelector.LabelSelector) if err != nil { - // When clusterSelector is fixed, Techsupport will be reconciled return requests } - if parsedSelector.Matches(labels.Set(cluster.GetLabels())) { + if clusterSelector.Matches(labels.Set(cluster.GetLabels())) { requests = append(requests, ctrl.Request{ NamespacedName: client.ObjectKey{ Name: k.Name, @@ -416,11 +415,11 @@ func requeueTechsupportForACluster( // getClusterSummaryServiceAccountInfo returns the name of the ServiceAccount // (presenting a tenant admin) that created the ClusterProfile instance owing this // ClusterProfile instance -func getClusterSummaryServiceAccountInfo(techsupport *utilsv1alpha1.Techsupport) (namespace, name string) { +func getClusterSummaryServiceAccountInfo(techsupport *utilsv1beta1.Techsupport) (namespace, name string) { if techsupport.Labels == nil { return "", "" } - return techsupport.Labels[libsveltosv1alpha1.ServiceAccountNamespaceLabel], - techsupport.Labels[libsveltosv1alpha1.ServiceAccountNameLabel] + return techsupport.Labels[libsveltosv1beta1.ServiceAccountNamespaceLabel], + techsupport.Labels[libsveltosv1beta1.ServiceAccountNameLabel] } diff --git a/internal/utils/classifiers.go b/internal/utils/classifiers.go index 10ad0d1d..7fad050c 100644 --- a/internal/utils/classifiers.go +++ b/internal/utils/classifiers.go @@ -21,16 +21,16 @@ import ( "github.com/go-logr/logr" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" logs "github.com/projectsveltos/libsveltos/lib/logsettings" ) // ListClassifiers returns all current Classifiers func (a *k8sAccess) ListClassifiers(ctx context.Context, - logger logr.Logger) (*libsveltosv1alpha1.ClassifierList, error) { + logger logr.Logger) (*libsveltosv1beta1.ClassifierList, error) { logger.V(logs.LogDebug).Info("Get all Classifiers") - classifiers := &libsveltosv1alpha1.ClassifierList{} + classifiers := &libsveltosv1beta1.ClassifierList{} err := a.client.List(ctx, classifiers) return classifiers, err } diff --git a/internal/utils/classifiers_test.go b/internal/utils/classifiers_test.go index f95ff1a1..3fa825ea 100644 --- a/internal/utils/classifiers_test.go +++ b/internal/utils/classifiers_test.go @@ -28,7 +28,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/utils" ) @@ -37,19 +37,19 @@ var _ = Describe("Classifier", func() { initObjects := []client.Object{} for i := 0; i < 10; i++ { - classifier := &libsveltosv1alpha1.Classifier{ + classifier := &libsveltosv1beta1.Classifier{ ObjectMeta: metav1.ObjectMeta{ Name: randomString(), }, - Spec: libsveltosv1alpha1.ClassifierSpec{ - ClassifierLabels: []libsveltosv1alpha1.ClassifierLabel{ + Spec: libsveltosv1beta1.ClassifierSpec{ + ClassifierLabels: []libsveltosv1beta1.ClassifierLabel{ {Key: randomString(), Value: randomString()}, }, - KubernetesVersionConstraints: []libsveltosv1alpha1.KubernetesVersionConstraint{ - {Version: randomString(), Comparison: string(libsveltosv1alpha1.ComparisonEqual)}, + KubernetesVersionConstraints: []libsveltosv1beta1.KubernetesVersionConstraint{ + {Version: randomString(), Comparison: string(libsveltosv1beta1.ComparisonEqual)}, }, - DeployedResourceConstraint: &libsveltosv1alpha1.DeployedResourceConstraint{ - ResourceSelectors: []libsveltosv1alpha1.ResourceSelector{ + DeployedResourceConstraint: &libsveltosv1beta1.DeployedResourceConstraint{ + ResourceSelectors: []libsveltosv1beta1.ResourceSelector{ { Group: randomString(), Version: randomString(), diff --git a/internal/utils/client.go b/internal/utils/client.go index bdde598f..e7543244 100644 --- a/internal/utils/client.go +++ b/internal/utils/client.go @@ -36,11 +36,11 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/controller-runtime/pkg/client" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" - eventv1alpha1 "github.com/projectsveltos/event-manager/api/v1alpha1" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" + eventv1beta1 "github.com/projectsveltos/event-manager/api/v1beta1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" logs "github.com/projectsveltos/libsveltos/lib/logsettings" - utilsv1alpha1 "github.com/projectsveltos/sveltosctl/api/v1alpha1" + utilsv1beta1 "github.com/projectsveltos/sveltosctl/api/v1beta1" ) // k8sAccess is used to access resources in the management cluster. @@ -95,16 +95,16 @@ func addToScheme(scheme *runtime.Scheme) error { if err := configv1alpha1.AddToScheme(scheme); err != nil { return err } - if err := utilsv1alpha1.AddToScheme(scheme); err != nil { + if err := utilsv1beta1.AddToScheme(scheme); err != nil { return err } if err := clusterv1.AddToScheme(scheme); err != nil { return err } - if err := libsveltosv1alpha1.AddToScheme(scheme); err != nil { + if err := libsveltosv1beta1.AddToScheme(scheme); err != nil { return err } - if err := eventv1alpha1.AddToScheme(scheme); err != nil { + if err := eventv1beta1.AddToScheme(scheme); err != nil { return err } if err := rbacv1.AddToScheme(scheme); err != nil { diff --git a/internal/utils/clusterconfigurations.go b/internal/utils/clusterconfigurations.go index e1c3f8a7..39099750 100644 --- a/internal/utils/clusterconfigurations.go +++ b/internal/utils/clusterconfigurations.go @@ -24,7 +24,7 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" logs "github.com/projectsveltos/libsveltos/lib/logsettings" ) diff --git a/internal/utils/clusterconfigurations_test.go b/internal/utils/clusterconfigurations_test.go index 79906c35..afbcd1f2 100644 --- a/internal/utils/clusterconfigurations_test.go +++ b/internal/utils/clusterconfigurations_test.go @@ -30,7 +30,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/utils" ) diff --git a/internal/utils/clusterprofiles.go b/internal/utils/clusterprofiles.go index 06b442c2..bca26824 100644 --- a/internal/utils/clusterprofiles.go +++ b/internal/utils/clusterprofiles.go @@ -21,7 +21,7 @@ import ( "github.com/go-logr/logr" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" logs "github.com/projectsveltos/libsveltos/lib/logsettings" ) diff --git a/internal/utils/clusterprofiles_test.go b/internal/utils/clusterprofiles_test.go index cdb32d9a..fdbc8687 100644 --- a/internal/utils/clusterprofiles_test.go +++ b/internal/utils/clusterprofiles_test.go @@ -28,8 +28,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/utils" ) @@ -43,8 +43,12 @@ var _ = Describe("ClusterProfile", func() { Name: randomString(), }, Spec: configv1alpha1.Spec{ - ClusterSelector: libsveltosv1alpha1.Selector("zone:west"), - SyncMode: configv1alpha1.SyncModeContinuous, + ClusterSelector: libsveltosv1beta1.Selector{ + LabelSelector: metav1.LabelSelector{ + MatchLabels: map[string]string{"zone": "west"}, + }, + }, + SyncMode: configv1alpha1.SyncModeContinuous, }, } initObjects = append(initObjects, clusterProfile) diff --git a/internal/utils/clusterreports.go b/internal/utils/clusterreports.go index 68ffafc7..3796e7d6 100644 --- a/internal/utils/clusterreports.go +++ b/internal/utils/clusterreports.go @@ -23,7 +23,7 @@ import ( "github.com/go-logr/logr" "sigs.k8s.io/controller-runtime/pkg/client" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" logs "github.com/projectsveltos/libsveltos/lib/logsettings" ) diff --git a/internal/utils/clusterreports_test.go b/internal/utils/clusterreports_test.go index be7f223f..a7b37cf7 100644 --- a/internal/utils/clusterreports_test.go +++ b/internal/utils/clusterreports_test.go @@ -28,7 +28,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/utils" ) diff --git a/internal/utils/debuggingconfigurations.go b/internal/utils/debuggingconfigurations.go index 3b2af5d4..c105545d 100644 --- a/internal/utils/debuggingconfigurations.go +++ b/internal/utils/debuggingconfigurations.go @@ -22,7 +22,7 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" "sigs.k8s.io/controller-runtime/pkg/client" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" ) const ( @@ -32,9 +32,9 @@ const ( // GetDebuggingConfiguration gets default DebuggingConfiguration func (a *k8sAccess) GetDebuggingConfiguration( ctx context.Context, -) (*libsveltosv1alpha1.DebuggingConfiguration, error) { +) (*libsveltosv1beta1.DebuggingConfiguration, error) { - req := &libsveltosv1alpha1.DebuggingConfiguration{} + req := &libsveltosv1beta1.DebuggingConfiguration{} reqName := client.ObjectKey{ Name: defaultInstanceName, @@ -51,14 +51,14 @@ func (a *k8sAccess) GetDebuggingConfiguration( // updates it. func (a *k8sAccess) UpdateDebuggingConfiguration( ctx context.Context, - dc *libsveltosv1alpha1.DebuggingConfiguration, + dc *libsveltosv1beta1.DebuggingConfiguration, ) error { reqName := client.ObjectKey{ Name: defaultInstanceName, } - tmp := &libsveltosv1alpha1.DebuggingConfiguration{} + tmp := &libsveltosv1beta1.DebuggingConfiguration{} err := a.client.Get(ctx, reqName, tmp) if err != nil { diff --git a/internal/utils/debuggingconfigurations_test.go b/internal/utils/debuggingconfigurations_test.go index aba4698a..f42c1f01 100644 --- a/internal/utils/debuggingconfigurations_test.go +++ b/internal/utils/debuggingconfigurations_test.go @@ -28,13 +28,13 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/utils" ) var _ = Describe("DebuggingConfigurations", func() { It("GetDebuggingConfiguration returns the default instance", func() { - dc := &libsveltosv1alpha1.DebuggingConfiguration{ + dc := &libsveltosv1beta1.DebuggingConfiguration{ ObjectMeta: metav1.ObjectMeta{ Name: utils.DefaultInstanceName, }, @@ -53,7 +53,7 @@ var _ = Describe("DebuggingConfigurations", func() { }) It("UpdateDebuggingConfiguration updates default DebuggingConfiguration instance", func() { - dc := &libsveltosv1alpha1.DebuggingConfiguration{ + dc := &libsveltosv1beta1.DebuggingConfiguration{ ObjectMeta: metav1.ObjectMeta{ Name: utils.DefaultInstanceName, }, @@ -66,10 +66,10 @@ var _ = Describe("DebuggingConfigurations", func() { k8sAccess := utils.GetK8sAccess(scheme, c) Expect(k8sAccess.UpdateDebuggingConfiguration(context.TODO(), dc)).To(Succeed()) - currentDC := &libsveltosv1alpha1.DebuggingConfiguration{} + currentDC := &libsveltosv1beta1.DebuggingConfiguration{} Expect(c.Get(context.TODO(), types.NamespacedName{Name: utils.DefaultInstanceName}, currentDC)).To(Succeed()) - currentDC.Spec.Configuration = []libsveltosv1alpha1.ComponentConfiguration{ - {Component: libsveltosv1alpha1.ComponentClassifier, LogLevel: libsveltosv1alpha1.LogLevelDebug}, + currentDC.Spec.Configuration = []libsveltosv1beta1.ComponentConfiguration{ + {Component: libsveltosv1beta1.ComponentClassifier, LogLevel: libsveltosv1beta1.LogLevelDebug}, } Expect(k8sAccess.UpdateDebuggingConfiguration(context.TODO(), currentDC)).To(Succeed()) diff --git a/internal/utils/eventsources.go b/internal/utils/eventsources.go index d4909c68..841e2c3f 100644 --- a/internal/utils/eventsources.go +++ b/internal/utils/eventsources.go @@ -21,16 +21,16 @@ import ( "github.com/go-logr/logr" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" logs "github.com/projectsveltos/libsveltos/lib/logsettings" ) // ListEventSources returns all current EventSources func (a *k8sAccess) ListEventSources(ctx context.Context, - logger logr.Logger) (*libsveltosv1alpha1.EventSourceList, error) { + logger logr.Logger) (*libsveltosv1beta1.EventSourceList, error) { logger.V(logs.LogDebug).Info("Get all EventSources") - eventSources := &libsveltosv1alpha1.EventSourceList{} + eventSources := &libsveltosv1beta1.EventSourceList{} err := a.client.List(ctx, eventSources) return eventSources, err } diff --git a/internal/utils/eventsources_test.go b/internal/utils/eventsources_test.go index 2ee599fa..b5409d3d 100644 --- a/internal/utils/eventsources_test.go +++ b/internal/utils/eventsources_test.go @@ -28,7 +28,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/utils" ) @@ -37,12 +37,12 @@ var _ = Describe("EventSource", func() { initObjects := []client.Object{} for i := 0; i < 10; i++ { - es := &libsveltosv1alpha1.EventSource{ + es := &libsveltosv1beta1.EventSource{ ObjectMeta: metav1.ObjectMeta{ Name: randomString(), }, - Spec: libsveltosv1alpha1.EventSourceSpec{ - ResourceSelectors: []libsveltosv1alpha1.ResourceSelector{ + Spec: libsveltosv1beta1.EventSourceSpec{ + ResourceSelectors: []libsveltosv1beta1.ResourceSelector{ { Group: randomString(), Version: randomString(), diff --git a/internal/utils/eventtriggers.go b/internal/utils/eventtriggers.go index 430e20fe..9f6a4cc1 100644 --- a/internal/utils/eventtriggers.go +++ b/internal/utils/eventtriggers.go @@ -21,16 +21,16 @@ import ( "github.com/go-logr/logr" - eventv1alpha1 "github.com/projectsveltos/event-manager/api/v1alpha1" + eventv1beta1 "github.com/projectsveltos/event-manager/api/v1beta1" logs "github.com/projectsveltos/libsveltos/lib/logsettings" ) // ListEventTriggers returns all current EventTriggers func (a *k8sAccess) ListEventTriggers(ctx context.Context, - logger logr.Logger) (*eventv1alpha1.EventTriggerList, error) { + logger logr.Logger) (*eventv1beta1.EventTriggerList, error) { logger.V(logs.LogDebug).Info("Get all EventTriggers") - eventTriggers := &eventv1alpha1.EventTriggerList{} + eventTriggers := &eventv1beta1.EventTriggerList{} err := a.client.List(ctx, eventTriggers) return eventTriggers, err } diff --git a/internal/utils/eventtriggers_test.go b/internal/utils/eventtriggers_test.go index 9430f6c9..8f32df5b 100644 --- a/internal/utils/eventtriggers_test.go +++ b/internal/utils/eventtriggers_test.go @@ -28,8 +28,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - eventv1alpha1 "github.com/projectsveltos/event-manager/api/v1alpha1" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + eventv1beta1 "github.com/projectsveltos/event-manager/api/v1beta1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/utils" ) @@ -38,13 +38,17 @@ var _ = Describe("EventTriggers", func() { initObjects := []client.Object{} for i := 0; i < 10; i++ { - resource := &eventv1alpha1.EventTrigger{ + resource := &eventv1beta1.EventTrigger{ ObjectMeta: metav1.ObjectMeta{ Name: randomString(), }, - Spec: eventv1alpha1.EventTriggerSpec{ - EventSourceName: randomString(), - SourceClusterSelector: libsveltosv1alpha1.Selector(randomString()), + Spec: eventv1beta1.EventTriggerSpec{ + EventSourceName: randomString(), + SourceClusterSelector: libsveltosv1beta1.Selector{ + LabelSelector: metav1.LabelSelector{ + MatchLabels: map[string]string{randomString(): randomString()}, + }, + }, }, } initObjects = append(initObjects, resource) diff --git a/internal/utils/healthcheckreports.go b/internal/utils/healthcheckreports.go index 531b0e39..3cf05acc 100644 --- a/internal/utils/healthcheckreports.go +++ b/internal/utils/healthcheckreports.go @@ -22,13 +22,13 @@ import ( "github.com/go-logr/logr" "sigs.k8s.io/controller-runtime/pkg/client" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" logs "github.com/projectsveltos/libsveltos/lib/logsettings" ) // ListHealthCheckReports returns all current HealthCheckReports func (a *k8sAccess) ListHealthCheckReports(ctx context.Context, namespace string, - logger logr.Logger) (*libsveltosv1alpha1.HealthCheckReportList, error) { + logger logr.Logger) (*libsveltosv1beta1.HealthCheckReportList, error) { logger.V(logs.LogDebug).Info("Get all HealthCheckReports") @@ -39,7 +39,7 @@ func (a *k8sAccess) ListHealthCheckReports(ctx context.Context, namespace string } } - healthCheckReports := &libsveltosv1alpha1.HealthCheckReportList{} + healthCheckReports := &libsveltosv1beta1.HealthCheckReportList{} err := a.client.List(ctx, healthCheckReports, listOptions...) return healthCheckReports, err } diff --git a/internal/utils/healthcheckreports_test.go b/internal/utils/healthcheckreports_test.go index 334b08cc..e9513344 100644 --- a/internal/utils/healthcheckreports_test.go +++ b/internal/utils/healthcheckreports_test.go @@ -28,7 +28,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/utils" ) @@ -37,15 +37,15 @@ var _ = Describe("HealthCheckReports", func() { initObjects := []client.Object{} for i := 0; i < 10; i++ { - hcr := &libsveltosv1alpha1.HealthCheckReport{ + hcr := &libsveltosv1beta1.HealthCheckReport{ ObjectMeta: metav1.ObjectMeta{ Name: randomString(), Namespace: randomString(), }, - Spec: libsveltosv1alpha1.HealthCheckReportSpec{ + Spec: libsveltosv1beta1.HealthCheckReportSpec{ ClusterNamespace: randomString(), ClusterName: randomString(), - ClusterType: libsveltosv1alpha1.ClusterTypeSveltos, + ClusterType: libsveltosv1beta1.ClusterTypeSveltos, HealthCheckName: randomString(), }, } @@ -67,30 +67,30 @@ var _ = Describe("HealthCheckReports", func() { initObjects := []client.Object{} for i := 0; i < 10; i++ { - hcr := &libsveltosv1alpha1.HealthCheckReport{ + hcr := &libsveltosv1beta1.HealthCheckReport{ ObjectMeta: metav1.ObjectMeta{ Name: randomString(), Namespace: randomString(), }, - Spec: libsveltosv1alpha1.HealthCheckReportSpec{ + Spec: libsveltosv1beta1.HealthCheckReportSpec{ ClusterNamespace: randomString(), ClusterName: randomString(), - ClusterType: libsveltosv1alpha1.ClusterTypeSveltos, + ClusterType: libsveltosv1beta1.ClusterTypeSveltos, HealthCheckName: randomString(), }, } initObjects = append(initObjects, hcr) } - hcr := &libsveltosv1alpha1.HealthCheckReport{ + hcr := &libsveltosv1beta1.HealthCheckReport{ ObjectMeta: metav1.ObjectMeta{ Name: randomString(), Namespace: randomString(), }, - Spec: libsveltosv1alpha1.HealthCheckReportSpec{ + Spec: libsveltosv1beta1.HealthCheckReportSpec{ ClusterNamespace: randomString(), ClusterName: randomString(), - ClusterType: libsveltosv1alpha1.ClusterTypeSveltos, + ClusterType: libsveltosv1beta1.ClusterTypeSveltos, HealthCheckName: randomString(), }, } diff --git a/internal/utils/healthchecks.go b/internal/utils/healthchecks.go index a3bfc403..94096834 100644 --- a/internal/utils/healthchecks.go +++ b/internal/utils/healthchecks.go @@ -21,16 +21,16 @@ import ( "github.com/go-logr/logr" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" logs "github.com/projectsveltos/libsveltos/lib/logsettings" ) // ListHealthChecks returns all current HealthChecks func (a *k8sAccess) ListHealthChecks(ctx context.Context, - logger logr.Logger) (*libsveltosv1alpha1.HealthCheckList, error) { + logger logr.Logger) (*libsveltosv1beta1.HealthCheckList, error) { logger.V(logs.LogDebug).Info("Get all HealthChecks") - healthCheck := &libsveltosv1alpha1.HealthCheckList{} + healthCheck := &libsveltosv1beta1.HealthCheckList{} err := a.client.List(ctx, healthCheck) return healthCheck, err } diff --git a/internal/utils/healthchecks_test.go b/internal/utils/healthchecks_test.go index 846a902d..d2bf2c72 100644 --- a/internal/utils/healthchecks_test.go +++ b/internal/utils/healthchecks_test.go @@ -28,7 +28,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/utils" ) @@ -37,12 +37,12 @@ var _ = Describe("HealthCheck", func() { initObjects := []client.Object{} for i := 0; i < 10; i++ { - hc := &libsveltosv1alpha1.HealthCheck{ + hc := &libsveltosv1beta1.HealthCheck{ ObjectMeta: metav1.ObjectMeta{ Name: randomString(), }, - Spec: libsveltosv1alpha1.HealthCheckSpec{ - ResourceSelectors: []libsveltosv1alpha1.ResourceSelector{ + Spec: libsveltosv1beta1.HealthCheckSpec{ + ResourceSelectors: []libsveltosv1beta1.ResourceSelector{ { Group: randomString(), Version: randomString(), diff --git a/internal/utils/profiles.go b/internal/utils/profiles.go index 9899c51e..3795a580 100644 --- a/internal/utils/profiles.go +++ b/internal/utils/profiles.go @@ -21,7 +21,7 @@ import ( "github.com/go-logr/logr" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" logs "github.com/projectsveltos/libsveltos/lib/logsettings" ) diff --git a/internal/utils/profiles_test.go b/internal/utils/profiles_test.go index ca15d826..d1f1fc99 100644 --- a/internal/utils/profiles_test.go +++ b/internal/utils/profiles_test.go @@ -28,8 +28,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1beta1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/utils" ) @@ -43,8 +43,12 @@ var _ = Describe("Profile", func() { Name: randomString(), }, Spec: configv1alpha1.Spec{ - ClusterSelector: libsveltosv1alpha1.Selector("zone:west"), - SyncMode: configv1alpha1.SyncModeContinuous, + ClusterSelector: libsveltosv1beta1.Selector{ + LabelSelector: metav1.LabelSelector{ + MatchLabels: map[string]string{"zone": "west"}, + }, + }, + SyncMode: configv1alpha1.SyncModeContinuous, }, } initObjects = append(initObjects, profile) diff --git a/internal/utils/rolerequests.go b/internal/utils/rolerequests.go index 0c4832b6..15727dc6 100644 --- a/internal/utils/rolerequests.go +++ b/internal/utils/rolerequests.go @@ -21,16 +21,16 @@ import ( "github.com/go-logr/logr" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" logs "github.com/projectsveltos/libsveltos/lib/logsettings" ) // ListRoleRequests returns all current RoleRequests func (a *k8sAccess) ListRoleRequests(ctx context.Context, - logger logr.Logger) (*libsveltosv1alpha1.RoleRequestList, error) { + logger logr.Logger) (*libsveltosv1beta1.RoleRequestList, error) { logger.V(logs.LogDebug).Info("Get all RoleRequests") - roleRequests := &libsveltosv1alpha1.RoleRequestList{} + roleRequests := &libsveltosv1beta1.RoleRequestList{} err := a.client.List(ctx, roleRequests) return roleRequests, err } diff --git a/internal/utils/rolerequests_test.go b/internal/utils/rolerequests_test.go index 1434cde2..9dbb9f8d 100644 --- a/internal/utils/rolerequests_test.go +++ b/internal/utils/rolerequests_test.go @@ -28,7 +28,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1" + libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" "github.com/projectsveltos/sveltosctl/internal/utils" ) @@ -37,14 +37,18 @@ var _ = Describe("RoleRequest", func() { initObjects := []client.Object{} for i := 0; i < 10; i++ { - rr := &libsveltosv1alpha1.RoleRequest{ + rr := &libsveltosv1beta1.RoleRequest{ ObjectMeta: metav1.ObjectMeta{ Name: randomString(), }, - Spec: libsveltosv1alpha1.RoleRequestSpec{ + Spec: libsveltosv1beta1.RoleRequestSpec{ ServiceAccountNamespace: randomString(), ServiceAccountName: randomString(), - ClusterSelector: libsveltosv1alpha1.Selector("zone:east"), + ClusterSelector: libsveltosv1beta1.Selector{ + LabelSelector: metav1.LabelSelector{ + MatchLabels: map[string]string{"zone": "east"}, + }, + }, }, } initObjects = append(initObjects, rr) diff --git a/manifest/manifest.yaml b/manifest/manifest.yaml index b1bc4148..129fef16 100644 --- a/manifest/manifest.yaml +++ b/manifest/manifest.yaml @@ -208,6 +208,89 @@ spec: scope: Cluster versions: - name: v1alpha1 + schema: + openAPIV3Schema: + description: Snapshot is the Schema for the snapshot API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: SnapshotSpec defines the desired state of Snapshot + properties: + schedule: + description: Schedule in Cron format, see https://en.wikipedia.org/wiki/Cron. + type: string + startingDeadlineSeconds: + description: |- + 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. + format: int64 + type: integer + storage: + description: |- + Storage represents directory where snapshots will be stored. + It must be an existing directory. + Snapshots will be stored in this directory in a subdirectory named + with Snapshot instance name. + type: string + successfulSnapshotLimit: + description: |- + The number of successful finished snapshots to retains. + If specified, only SuccessfulSnapshotLimit will be retained. Once such + number is reached, for any new successful snapshots, the oldest one is + deleted. + format: int32 + type: integer + required: + - schedule + - storage + type: object + status: + description: SnapshotStatus defines the observed state of Snapshot + properties: + failureMessage: + description: |- + FailureMessage provides more information about the error, if + any occurred + type: string + lastRunStatus: + description: Status indicates what happened to last snapshot collection. + enum: + - Collected + - InProgress + - Failed + type: string + lastRunTime: + description: Information when was the last time a snapshot was successfully + scheduled. + format: date-time + type: string + nextScheduleTime: + description: Information when next snapshot is scheduled + format: date-time + type: string + type: object + type: object + served: true + storage: false + subresources: + status: {} + - name: v1beta1 schema: openAPIV3Schema: description: Snapshot is the Schema for the snapshot API @@ -295,9 +378,20 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: + cert-manager.io/inject-ca-from: projectsveltos/projectsveltos-serving-cert controller-gen.kubebuilder.io/version: v0.15.0 name: techsupports.utils.projectsveltos.io spec: + conversion: + strategy: Webhook + webhook: + clientConfig: + service: + name: webhook-service + namespace: projectsveltos + path: /convert + conversionReviewVersions: + - v1 group: utils.projectsveltos.io names: kind: Techsupport @@ -498,6 +592,296 @@ spec: will affect numerous schemas. Don't make new APIs embed an underspecified API type they do not control. + Instead of using this type, create a locally provided and used type that is well-focused on your reference. + For example, ServiceReferences for admission registration: https://github.com/kubernetes/api/blob/release-1.17/admissionregistration/v1/types.go#L533 . + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: |- + If referring to a piece of an object instead of an entire object, this string + should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container within a pod, this would take on a value like: + "spec.containers{name}" (where "name" refers to the name of the container that triggered + the event) or if no container name is specified "spec.containers[2]" (container with + index 2 in this pod). This syntax is chosen only to have some well-defined way of + referencing a part of an object. + TODO: this design is not final and this field is subject to change in the future. + type: string + kind: + description: |- + Kind of the referent. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + namespace: + description: |- + Namespace of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ + type: string + resourceVersion: + description: |- + Specific resourceVersion to which this reference is made, if any. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency + type: string + uid: + description: |- + UID of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids + type: string + type: object + x-kubernetes-map-type: atomic + type: array + nextScheduleTime: + description: Information when next snapshot is scheduled + format: date-time + type: string + type: object + type: object + served: true + storage: false + subresources: + status: {} + - name: v1beta1 + schema: + openAPIV3Schema: + description: Techsupport is the Schema for the snapshot API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: TechsupportSpec defines the desired state of Techsupport + properties: + clusterSelector: + description: ClusterSelector identifies clusters to collect techsupport + from. + properties: + matchExpressions: + description: matchExpressions is a list of label selector requirements. + The requirements are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key that the selector applies + to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + logs: + description: Logs indicates what pods' log to collect + items: + description: LogFilter allows to select which logs to collect + properties: + labelFilters: + description: LabelFilters allows to filter pods based on current + labels. + items: + properties: + key: + description: Key is the label key + type: string + operation: + description: Operation is the comparison operation + enum: + - Equal + - Different + type: string + value: + description: Value is the label value + type: string + required: + - key + - operation + - value + type: object + type: array + namespace: + description: Namespace of the pods deployed in the Cluster. + type: string + sinceSeconds: + description: |- + 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. + If this value is in the future, no logs will be returned. Only one of sinceSeconds or sinceTime may be specified. + format: int64 + type: integer + type: object + type: array + resources: + description: Resources indicates what resorces to collect + items: + description: Resource indicates the type of resources to collect. + properties: + group: + description: Group of the resource deployed in the Cluster. + type: string + kind: + description: Kind of the resource deployed in the Cluster. + minLength: 1 + type: string + labelFilters: + description: LabelFilters allows to filter resources based on + current labels. + items: + properties: + key: + description: Key is the label key + type: string + operation: + description: Operation is the comparison operation + enum: + - Equal + - Different + type: string + value: + description: Value is the label value + type: string + required: + - key + - operation + - value + type: object + type: array + namespace: + description: |- + Namespace of the resource deployed in the Cluster. + Empty for resources scoped at cluster level. + type: string + version: + description: Version of the resource deployed in the Cluster. + type: string + required: + - group + - kind + - version + type: object + type: array + schedule: + description: Schedule in Cron format, see https://en.wikipedia.org/wiki/Cron. + type: string + startingDeadlineSeconds: + description: |- + 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. + format: int64 + type: integer + storage: + description: |- + Storage represents directory where techsupports will be stored. + It must be an existing directory. + Techsupports will be stored in this directory in a subdirectory named + with Techsupport instance name. + type: string + successfulTechsupportLimit: + description: |- + The number of successful finished techsupport to retains. + If specified, only SuccessfulTechsupportLimit will be retained. Once such + number is reached, for any new successful snapshots, the oldest one is + deleted. + format: int32 + type: integer + tar: + default: false + description: If set denerates a tar file with all collected logs/resources + type: boolean + required: + - clusterSelector + - schedule + - storage + type: object + status: + description: TechsupportStatus defines the observed state of Techsupport + properties: + failureMessage: + description: |- + FailureMessage provides more information about the error, if + any occurred + type: string + lastRunStatus: + description: Status indicates what happened to last techsupport collection. + enum: + - Collected + - InProgress + - Failed + type: string + lastRunTime: + description: Information when was the last time a snapshot was successfully + scheduled. + format: date-time + type: string + machingClusters: + description: |- + MatchingClusterRefs reference all the clusters currently matching + Techsupport + items: + description: |- + ObjectReference contains enough information to let you inspect or modify the referred object. + --- + New uses of this type are discouraged because of difficulty describing its usage when embedded in APIs. + 1. Ignored fields. It includes many fields which are not generally honored. For instance, ResourceVersion and FieldPath are both very rarely valid in actual usage. + 2. Invalid usage help. It is impossible to add specific help for individual usage. In most embedded usages, there are particular + restrictions like, "must refer only to types A and B" or "UID not honored" or "name must be restricted". + Those cannot be well described when embedded. + 3. Inconsistent validation. Because the usages are different, the validation rules are different by usage, which makes it hard for users to predict what will happen. + 4. The fields are both imprecise and overly precise. Kind is not a precise mapping to a URL. This can produce ambiguity + during interpretation and require a REST mapping. In most cases, the dependency is on the group,resource tuple + and the version of the actual struct is irrelevant. + 5. We cannot easily change it. Because this type is embedded in many locations, updates to this type + will affect numerous schemas. Don't make new APIs embed an underspecified API type they do not control. + + Instead of using this type, create a locally provided and used type that is well-focused on your reference. For example, ServiceReferences for admission registration: https://github.com/kubernetes/api/blob/release-1.17/admissionregistration/v1/types.go#L533 . properties: