Change the api group from clusters.etcd.io to operator.etcd.io

Signed-off-by: Benjamin Wang <benjamin.ahrtr@gmail.com>
This commit is contained in:
Benjamin Wang 2024-11-22 15:44:07 +00:00
parent ccbf648130
commit 83bbf0126d
17 changed files with 77 additions and 81 deletions

View File

@ -170,10 +170,10 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
## Tool Versions
KUSTOMIZE_VERSION ?= v5.4.3
KUSTOMIZE_VERSION ?= v5.5.0
CONTROLLER_TOOLS_VERSION ?= v0.16.4
ENVTEST_VERSION ?= release-0.19
GOLANGCI_LINT_VERSION ?= v1.59.1
GOLANGCI_LINT_VERSION ?= v1.61.0
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.

View File

@ -13,7 +13,7 @@ resources:
namespaced: true
controller: true
domain: etcd.io
group: clusters
group: operator
kind: EtcdCluster
path: go.etcd.io/etcd-operator/api/v1alpha1
version: v1alpha1

View File

@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// Package v1alpha1 contains API Schema definitions for the clusters v1alpha1 API group.
// Package v1alpha1 contains API Schema definitions for the operator v1alpha1 API group.
// +kubebuilder:object:generate=true
// +groupName=clusters.etcd.io
// +groupName=operator.etcd.io
package v1alpha1
import (
@ -26,7 +26,7 @@ import (
var (
// GroupVersion is group version used to register these objects.
GroupVersion = schema.GroupVersion{Group: "clusters.etcd.io", Version: "v1alpha1"}
GroupVersion = schema.GroupVersion{Group: "operator.etcd.io", Version: "v1alpha1"}
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

View File

@ -35,7 +35,7 @@ import (
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"
clustersv1alpha1 "go.etcd.io/etcd-operator/api/v1alpha1"
operatorv1alpha1 "go.etcd.io/etcd-operator/api/v1alpha1"
"go.etcd.io/etcd-operator/internal/controller"
// +kubebuilder:scaffold:imports
)
@ -48,7 +48,7 @@ var (
func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(clustersv1alpha1.AddToScheme(scheme))
utilruntime.Must(operatorv1alpha1.AddToScheme(scheme))
// +kubebuilder:scaffold:scheme
}
@ -98,26 +98,24 @@ func main() {
// Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
// More info:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.0/pkg/metrics/server
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.1/pkg/metrics/server
// - https://book.kubebuilder.io/reference/metrics.html
metricsServerOptions := metricsserver.Options{
BindAddress: metricsAddr,
SecureServing: secureMetrics,
// TODO(user): TLSOpts is used to allow configuring the TLS config used for the server. If certificates are
// not provided, self-signed certificates will be generated by default. This option is not recommended for
// production environments as self-signed certificates do not offer the same level of trust and security
// as certificates issued by a trusted Certificate Authority (CA). The primary risk is potentially allowing
// unauthorized access to sensitive metrics data. Consider replacing with CertDir, CertName, and KeyName
// to provide certificates, ensuring the server communicates using trusted and secure certificates.
TLSOpts: tlsOpts,
TLSOpts: tlsOpts,
}
if secureMetrics {
// FilterProvider is used to protect the metrics endpoint with authn/authz.
// These configurations ensure that only authorized users and service accounts
// can access the metrics endpoint. The RBAC are configured in 'config/rbac/kustomization.yaml'. More info:
// https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.0/pkg/metrics/filters#WithAuthenticationAndAuthorization
// https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.1/pkg/metrics/filters#WithAuthenticationAndAuthorization
metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization
// TODO(user): If CertDir, CertName, and KeyName are not specified, controller-runtime will automatically
// generate self-signed certificates for the metrics server. While convenient for development and testing,
// this setup is not recommended for production.
}
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{

View File

@ -4,9 +4,9 @@ kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.4
name: etcdclusters.clusters.etcd.io
name: etcdclusters.operator.etcd.io
spec:
group: clusters.etcd.io
group: operator.etcd.io
names:
kind: EtcdCluster
listKind: EtcdClusterList

View File

@ -2,7 +2,7 @@
# since it depends on service name and namespace that are out of this kustomize package.
# It should be run by config/default
resources:
- bases/clusters.etcd.io_etcdclusters.yaml
- bases/operator.etcd.io_etcdclusters.yaml
# +kubebuilder:scaffold:crdkustomizeresource
patches:
@ -12,11 +12,9 @@ patches:
# [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_etcdclusters.yaml
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
# [WEBHOOK] To enable webhook, uncomment the following section
# the following config is for teaching kustomize how to do kustomization for CRDs.
#configurations:
#- kustomizeconfig.yaml

View File

@ -48,6 +48,41 @@ patches:
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
# Uncomment the following replacements to add the cert-manager CA injection annotations
#replacements:
# - source: # Uncomment the following block if you have any webhook
# kind: Service
# version: v1
# name: webhook-service
# fieldPath: .metadata.name # Name of the service
# targets:
# - select:
# kind: Certificate
# group: cert-manager.io
# version: v1
# fieldPaths:
# - .spec.dnsNames.0
# - .spec.dnsNames.1
# options:
# delimiter: '.'
# index: 0
# create: true
# - source:
# kind: Service
# version: v1
# name: webhook-service
# fieldPath: .metadata.namespace # Namespace of the service
# targets:
# - select:
# kind: Certificate
# group: cert-manager.io
# version: v1
# fieldPaths:
# - .spec.dnsNames.0
# - .spec.dnsNames.1
# options:
# delimiter: '.'
# index: 1
# create: true
#
# - source: # Uncomment the following block if you have a ValidatingWebhook (--programmatic-validation)
# kind: Certificate
# group: cert-manager.io
@ -140,38 +175,3 @@ patches:
# delimiter: '/'
# index: 1
# create: true
#
# - source: # Uncomment the following block if you enable cert-manager
# kind: Service
# version: v1
# name: webhook-service
# fieldPath: .metadata.name # Name of the service
# targets:
# - select:
# kind: Certificate
# group: cert-manager.io
# version: v1
# fieldPaths:
# - .spec.dnsNames.0
# - .spec.dnsNames.1
# options:
# delimiter: '.'
# index: 0
# create: true
# - source:
# kind: Service
# version: v1
# name: webhook-service
# fieldPath: .metadata.namespace # Namespace of the service
# targets:
# - select:
# kind: Certificate
# group: cert-manager.io
# version: v1
# fieldPaths:
# - .spec.dnsNames.0
# - .spec.dnsNames.1
# options:
# delimiter: '.'
# index: 1
# create: true

View File

@ -8,7 +8,7 @@ metadata:
name: etcdcluster-editor-role
rules:
- apiGroups:
- clusters.etcd.io
- operator.etcd.io
resources:
- etcdclusters
verbs:
@ -20,7 +20,7 @@ rules:
- update
- watch
- apiGroups:
- clusters.etcd.io
- operator.etcd.io
resources:
- etcdclusters/status
verbs:

View File

@ -8,7 +8,7 @@ metadata:
name: etcdcluster-viewer-role
rules:
- apiGroups:
- clusters.etcd.io
- operator.etcd.io
resources:
- etcdclusters
verbs:
@ -16,7 +16,7 @@ rules:
- list
- watch
- apiGroups:
- clusters.etcd.io
- operator.etcd.io
resources:
- etcdclusters/status
verbs:

View File

@ -5,7 +5,7 @@ metadata:
name: manager-role
rules:
- apiGroups:
- clusters.etcd.io
- operator.etcd.io
resources:
- etcdclusters
verbs:
@ -17,13 +17,13 @@ rules:
- update
- watch
- apiGroups:
- clusters.etcd.io
- operator.etcd.io
resources:
- etcdclusters/finalizers
verbs:
- update
- apiGroups:
- clusters.etcd.io
- operator.etcd.io
resources:
- etcdclusters/status
verbs:

View File

@ -1,4 +1,4 @@
## Append samples of your project ##
resources:
- clusters_v1alpha1_etcdcluster.yaml
- operator_v1alpha1_etcdcluster.yaml
# +kubebuilder:scaffold:manifestskustomizesamples

View File

@ -1,4 +1,4 @@
apiVersion: clusters.etcd.io/v1alpha1
apiVersion: operator.etcd.io/v1alpha1
kind: EtcdCluster
metadata:
labels:

2
go.mod
View File

@ -7,7 +7,7 @@ require (
github.com/onsi/gomega v1.33.1
k8s.io/apimachinery v0.31.0
k8s.io/client-go v0.31.0
sigs.k8s.io/controller-runtime v0.19.0
sigs.k8s.io/controller-runtime v0.19.1
)
require (

4
go.sum
View File

@ -241,8 +241,8 @@ k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 h1:2770sDpzrjjsAtVhSeUFseziht227YAWYHLGNM8QPwY=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3/go.mod h1:Ve9uj1L+deCXFrPOk1LpFXqTg7LCFzFso6PA48q/XZw=
sigs.k8s.io/controller-runtime v0.19.0 h1:nWVM7aq+Il2ABxwiCizrVDSlmDcshi9llbaFbC0ji/Q=
sigs.k8s.io/controller-runtime v0.19.0/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4=
sigs.k8s.io/controller-runtime v0.19.1 h1:Son+Q40+Be3QWb+niBXAg2vFiYWolDjjRfO8hn/cxOk=
sigs.k8s.io/controller-runtime v0.19.1/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4=

View File

@ -24,7 +24,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
clustersv1alpha1 "go.etcd.io/etcd-operator/api/v1alpha1"
operatorv1alpha1 "go.etcd.io/etcd-operator/api/v1alpha1"
)
// EtcdClusterReconciler reconciles a EtcdCluster object
@ -33,9 +33,9 @@ type EtcdClusterReconciler struct {
Scheme *runtime.Scheme
}
// +kubebuilder:rbac:groups=clusters.etcd.io,resources=etcdclusters,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=clusters.etcd.io,resources=etcdclusters/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=clusters.etcd.io,resources=etcdclusters/finalizers,verbs=update
// +kubebuilder:rbac:groups=operator.etcd.io,resources=etcdclusters,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=operator.etcd.io,resources=etcdclusters/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=operator.etcd.io,resources=etcdclusters/finalizers,verbs=update
// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
@ -45,7 +45,7 @@ type EtcdClusterReconciler struct {
// the user.
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.0/pkg/reconcile
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.1/pkg/reconcile
func (r *EtcdClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
_ = log.FromContext(ctx)
@ -57,7 +57,7 @@ func (r *EtcdClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
// SetupWithManager sets up the controller with the Manager.
func (r *EtcdClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&clustersv1alpha1.EtcdCluster{}).
For(&operatorv1alpha1.EtcdCluster{}).
Named("etcdcluster").
Complete(r)
}

View File

@ -27,7 +27,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clustersv1alpha1 "go.etcd.io/etcd-operator/api/v1alpha1"
operatorv1alpha1 "go.etcd.io/etcd-operator/api/v1alpha1"
)
var _ = Describe("EtcdCluster Controller", func() {
@ -40,13 +40,13 @@ var _ = Describe("EtcdCluster Controller", func() {
Name: resourceName,
Namespace: "default", // TODO(user):Modify as needed
}
etcdcluster := &clustersv1alpha1.EtcdCluster{}
etcdcluster := &operatorv1alpha1.EtcdCluster{}
BeforeEach(func() {
By("creating the custom resource for the Kind EtcdCluster")
err := k8sClient.Get(ctx, typeNamespacedName, etcdcluster)
if err != nil && errors.IsNotFound(err) {
resource := &clustersv1alpha1.EtcdCluster{
resource := &operatorv1alpha1.EtcdCluster{
ObjectMeta: metav1.ObjectMeta{
Name: resourceName,
Namespace: "default",
@ -59,7 +59,7 @@ var _ = Describe("EtcdCluster Controller", func() {
AfterEach(func() {
// TODO(user): Cleanup logic after each test, like removing the resource instance.
resource := &clustersv1alpha1.EtcdCluster{}
resource := &operatorv1alpha1.EtcdCluster{}
err := k8sClient.Get(ctx, typeNamespacedName, resource)
Expect(err).NotTo(HaveOccurred())

View File

@ -33,7 +33,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
clustersv1alpha1 "go.etcd.io/etcd-operator/api/v1alpha1"
operatorv1alpha1 "go.etcd.io/etcd-operator/api/v1alpha1"
// +kubebuilder:scaffold:imports
)
@ -77,7 +77,7 @@ var _ = BeforeSuite(func() {
Expect(err).NotTo(HaveOccurred())
Expect(cfg).NotTo(BeNil())
err = clustersv1alpha1.AddToScheme(scheme.Scheme)
err = operatorv1alpha1.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())
// +kubebuilder:scaffold:scheme