Skip to content

Commit

Permalink
assert acm ready with crd
Browse files Browse the repository at this point in the history
Signed-off-by: myan <[email protected]>

fix the test

Signed-off-by: myan <[email protected]>

fix it

Signed-off-by: myan <[email protected]>

fix the it

Signed-off-by: myan <[email protected]>

fix the panic

Signed-off-by: myan <[email protected]>

fix it

Signed-off-by: myan <[email protected]>

inventory e2e

Signed-off-by: myan <[email protected]>

resolve the conflict of it

Signed-off-by: myan <[email protected]>

config dir

Signed-off-by: myan <[email protected]>

invenotry cert

Signed-off-by: myan <[email protected]>
  • Loading branch information
yanmxa committed Nov 14, 2024
1 parent 4fc5c1f commit cfc332f
Show file tree
Hide file tree
Showing 26 changed files with 499 additions and 794 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ jobs:
go-version: ${{ env.GO_VERSION }}
- name: install ginkgo
run: go install github.com/onsi/ginkgo/v2/[email protected]
- name: Test E2E
- name: SET E2E
run: |
make kessel-e2e-setup
13 changes: 12 additions & 1 deletion operator/pkg/certificates/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"time"

routev1 "github.com/openshift/api/route/v1"
operatorconstants "github.com/stolostron/multicluster-global-hub/operator/pkg/constants"
"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -72,8 +73,9 @@ func CreateInventoryCerts(
if err != nil {
return err
}
ips := getIps(mgh)
err = createCertSecret(c, scheme, mgh, serverCrtUpdated, serverCerts, mgh.Namespace,
true, serverCertificateCN, nil, hosts, nil)
true, serverCertificateCN, nil, hosts, ips)
if err != nil {
return err
}
Expand Down Expand Up @@ -471,3 +473,12 @@ func getHosts(ctx context.Context, c client.Client, namespace string) ([]string,

return []string{found.Spec.Host}, nil
}

func getIps(mgh *v1alpha4.MulticlusterGlobalHub) []net.IP {
kindClusterIP := mgh.Annotations[operatorconstants.KinDClusterIPKey]
if len(kindClusterIP) > 0 {
return []net.IP{net.IP(kindClusterIP)}
}

return nil
}
10 changes: 5 additions & 5 deletions operator/pkg/config/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ const (
)

const (
CONDITION_TYPE_ACM_READY = "ACMReady"
CONDITION_REASON_ACM_READY = "ACMReady"
CONDITION_REASON_ACM_NOT_READY = "ACMNotReady"
CONDITION_MESSAGE_ACM_READY = "The mch is running"
CONDITION_MESSAGE_ACM_NOT_READY = "The mch is not running, waiting for mch running"
CONDITION_TYPE_ACM_RESOURCE_READY = "ACMResourceReady"
CONDITION_REASON_ACM_RESOURCE_READY = "ACMResourceReady"
CONDITION_REASON_ACM_RESOURCE_NOT_READY = "ACMResourceNotReady"
CONDITION_MESSAGE_ACM_RESOURCE_READY = "The ACM Resources is ready"
CONDITION_MESSAGE_ACM_RESOURCE_NOT_READY = "The ACM Resources is not ready, waiting for installing"
)

const (
Expand Down
5 changes: 3 additions & 2 deletions operator/pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ const (
// CommunityCatalogSourceNamespaceKey defines the catalog source namespace.
// It is mainly used for deploying kafka in KinD cluster.
CommunityCatalogSourceNamespaceKey = "global-hub.open-cluster-management.io/catalog-source-namespace"
// KafkaBrokerAdvertisedHostKey defines a broker host which is used for test.
KafkaBrokerAdvertisedHostKey = "global-hub.open-cluster-management.io/kafka-broker-advertised-host"
// KinDClusterIPKey defines a KinD container host which is used for test.
// It will be inject to the server certificates of kafka and inventory
KinDClusterIPKey = "global-hub.open-cluster-management.io/kind-cluster-ip"
// EnableKRaft enables run kafka with kraft
EnableKRaft = "global-hub.open-cluster-management.io/enable-kraft"
)
Expand Down
115 changes: 115 additions & 0 deletions operator/pkg/controllers/acm/resources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
Copyright 2024.
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 acm

import (
"context"

apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/predicate"

"github.com/stolostron/multicluster-global-hub/operator/api/operator/v1alpha4"
"github.com/stolostron/multicluster-global-hub/operator/pkg/config"
"github.com/stolostron/multicluster-global-hub/pkg/logger"
)

var ACMResources = sets.NewString(
"multiclusterhubs.operator.open-cluster-management.io",
"clustermanagers.operator.open-cluster-management.io",
)

var (
log = logger.DefaultZapLogger()
acmResourceControllerStarted = false
)

// +kubebuilder:rbac:groups=apiextensions.k8s.io,resources=customresourcedefinitions,verbs=get;list;watch;update

type ACMResourceController struct {
manager.Manager
Resources map[string]bool
}

func (r *ACMResourceController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
r.Resources[req.Name] = true

if !r.readyToWatchACMResources() {
log.Debugf("ACM Resources is not ready")
return ctrl.Result{}, nil
}

config.SetACMResourceReady(true)
err := config.UpdateCondition(ctx, r.GetClient(), config.GetMGHNamespacedName(),
metav1.Condition{
Type: config.CONDITION_TYPE_ACM_RESOURCE_READY,
Status: config.CONDITION_STATUS_TRUE,
Reason: config.CONDITION_REASON_ACM_RESOURCE_READY,
Message: config.CONDITION_MESSAGE_ACM_RESOURCE_READY,
}, v1alpha4.GlobalHubError)
if err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{}, nil
}

func (r *ACMResourceController) readyToWatchACMResources() bool {
for val := range ACMResources {
if ready := r.Resources[val]; !ready {
return false
}
}
return true
}

func AddACMResourceController(opts config.ControllerOption) error {
if acmResourceControllerStarted {
return nil
}
acmController := &ACMResourceController{
Manager: opts.Manager,
Resources: make(map[string]bool),
}
err := ctrl.NewControllerManagedBy(opts.Manager).Named("acm-controller").
WatchesMetadata(
&apiextensionsv1.CustomResourceDefinition{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool {
return ACMResources.Has(e.Object.GetName())
},
UpdateFunc: func(e event.UpdateEvent) bool {
return false
},
DeleteFunc: func(e event.DeleteEvent) bool {
return false
},
}),
).
Complete(acmController)
if err != nil {
return err
}
acmResourceControllerStarted = true
return nil
}
4 changes: 2 additions & 2 deletions operator/pkg/controllers/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ import (

"github.com/stolostron/multicluster-global-hub/operator/api/operator/v1alpha4"
"github.com/stolostron/multicluster-global-hub/operator/pkg/config"
"github.com/stolostron/multicluster-global-hub/operator/pkg/controllers/acm"
"github.com/stolostron/multicluster-global-hub/operator/pkg/controllers/backup"
"github.com/stolostron/multicluster-global-hub/operator/pkg/controllers/grafana"
"github.com/stolostron/multicluster-global-hub/operator/pkg/controllers/inventory"
globalhubmanager "github.com/stolostron/multicluster-global-hub/operator/pkg/controllers/manager"
"github.com/stolostron/multicluster-global-hub/operator/pkg/controllers/multiclusterhub"
"github.com/stolostron/multicluster-global-hub/operator/pkg/controllers/storage"
"github.com/stolostron/multicluster-global-hub/operator/pkg/controllers/transporter"
"github.com/stolostron/multicluster-global-hub/operator/pkg/controllers/webhook"
Expand All @@ -52,7 +52,7 @@ type Func func(initOption config.ControllerOption) error
// controllerStartFuncList store all the controllers that need started
var controllerStartFuncList = []Func{
// start the multilcusterhub controller to update the ACM status of the mgh
multiclusterhub.AddMulticlusterHubController,
acm.AddACMResourceController,
transporter.StartController,
storage.StartController,
grafana.StartController,
Expand Down
129 changes: 0 additions & 129 deletions operator/pkg/controllers/multiclusterhub/acm.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (k *strimziTransporter) renderKafkaResources(mgh *operatorv1alpha4.Multiclu
topicReplicas = 1
}
// brokerAdvertisedHost is used for test in KinD cluster. we need to use AdvertisedHost to pass tls authn.
brokerAdvertisedHost := mgh.Annotations[operatorconstants.KafkaBrokerAdvertisedHostKey]
brokerAdvertisedHost := mgh.Annotations[operatorconstants.KinDClusterIPKey]

// render the kafka objects
kafkaRenderer, kafkaDeployer := renderer.NewHoHRenderer(manifests), deployer.NewHoHDeployer(k.manager.GetClient())
Expand Down
5 changes: 4 additions & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ e2e-setup: tidy vendor e2e-dep
./test/script/e2e_setup.sh

kessel-e2e-setup:
./test/kessel_e2e/setup/e2e_setup.sh
./test/script/kessel_e2e_setup.sh

kessel-e2e-run: tidy vendor
./test/script/kessel_e2e_run.sh

e2e-cleanup:
./test/script/e2e_cleanup.sh
Expand Down
Loading

0 comments on commit cfc332f

Please sign in to comment.