From ad6d35177ef045553a93a718272807fc3a3ae421 Mon Sep 17 00:00:00 2001 From: Abirdcfly Date: Thu, 29 Dec 2022 13:47:07 +0800 Subject: [PATCH] fix: integration test Signed-off-by: Abirdcfly --- .github/workflows/integration-tests.yaml | 8 ++++- integration/integration.go | 16 ++++++++-- integration/operator.go | 18 ++++++++++- .../operatorrestart_suite_test.go | 7 ++--- main.go | 12 +------ operatorconfig/env.go | 31 +++++++++++++++++++ scripts/go-sec.sh | 6 +--- 7 files changed, 73 insertions(+), 25 deletions(-) create mode 100644 operatorconfig/env.go diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml index b951a54f..fe27226a 100644 --- a/.github/workflows/integration-tests.yaml +++ b/.github/workflows/integration-tests.yaml @@ -71,7 +71,12 @@ jobs: - name: Install Fabric CRDs run: | kubectl kustomize config/crd | kubectl apply -f - - + - name: Add hosts to /etc/hosts + run: | + sudo echo "127.0.0.1 inttestca-ibpca1-ca.vcap.me" | sudo tee -a /etc/hosts + sudo echo "127.0.0.1 inttestca-ibpca2-ca.vcap.me" | sudo tee -a /etc/hosts + sudo echo "127.0.0.1 inttestca-ibpca3-ca.vcap.me" | sudo tee -a /etc/hosts + sudo echo "127.0.0.1 inttestca-interca-ca.vcap.me" | sudo tee -a /etc/hosts - name: Run ${{ matrix.suite }} integration tests run: make integration-tests # run: | @@ -79,3 +84,4 @@ jobs: # make integration-tests env: INT_TEST_NAME: ${{ matrix.suite }} + WEBHOOK_DISABLED: true diff --git a/integration/integration.go b/integration/integration.go index e44aea21..5711c89f 100644 --- a/integration/integration.go +++ b/integration/integration.go @@ -33,6 +33,7 @@ import ( ibpclient "github.com/IBM-Blockchain/fabric-operator/pkg/client" "github.com/IBM-Blockchain/fabric-operator/pkg/command" "github.com/IBM-Blockchain/fabric-operator/pkg/util" + "sigs.k8s.io/controller-runtime/pkg/envtest" corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" @@ -214,6 +215,7 @@ func DeployOperator(ginkgoWriter io.Writer, signal context.Context, cfg *Config, if err != nil { return err } + sa.Namespace = namespace _, err = kclient.CoreV1().ServiceAccounts(namespace).Create(context.TODO(), sa, metav1.CreateOptions{}) if err != nil { return err @@ -224,6 +226,7 @@ func DeployOperator(ginkgoWriter io.Writer, signal context.Context, cfg *Config, if err != nil { return err } + role.Namespace = namespace _, err = kclient.RbacV1().ClusterRoles().Create(context.TODO(), role, metav1.CreateOptions{}) if err != nil { if !k8serrors.IsAlreadyExists(err) { @@ -236,7 +239,7 @@ func DeployOperator(ginkgoWriter io.Writer, signal context.Context, cfg *Config, if err != nil { return err } - + roleBinding.Namespace = namespace roleBinding.Name = fmt.Sprintf("operator-%s", namespace) roleBinding.Subjects[0].Namespace = namespace @@ -282,7 +285,11 @@ func DeployOperator(ginkgoWriter io.Writer, signal context.Context, cfg *Config, if err != nil { return err } - + wh := envtest.WebhookInstallOptions{LocalServingCertDir: "/tmp/k8s-webhook-server/serving-certs"} + err = wh.PrepWithoutInstalling() + if err != nil { + return err + } err = command.OperatorWithSignal(operatorCfg, signal, false, true) if err != nil { return err @@ -488,5 +495,8 @@ func getOperatorCfg() *config.Config { defaultOrdererDef := filepath.Join(defaultDef, "orderer") defaultConsoleDef := filepath.Join(defaultDef, "console") defaultVoteDef := filepath.Join(defaultDef, "vote") - return GetOperatorConfig(defaultConfigs, defaultCADef, defaultPeerDef, defaultOrdererDef, defaultConsoleDef, defaultVoteDef) + defaultOrganizationDef := filepath.Join(defaultDef, "organization") + defaultFederationDef := filepath.Join(defaultDef, "federation") + defaultNetworkDef := filepath.Join(defaultDef, "network") + return GetOperatorConfig(defaultConfigs, defaultCADef, defaultPeerDef, defaultOrdererDef, defaultConsoleDef, defaultVoteDef, defaultOrganizationDef, defaultFederationDef, defaultNetworkDef) } diff --git a/integration/operator.go b/integration/operator.go index bda16258..dd1f0a1d 100644 --- a/integration/operator.go +++ b/integration/operator.go @@ -25,6 +25,9 @@ import ( "path/filepath" config "github.com/IBM-Blockchain/fabric-operator/operatorconfig" + fedinit "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/federation" + netinit "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/network" + orginit "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/organization" "github.com/IBM-Blockchain/fabric-operator/pkg/apis/common" "github.com/IBM-Blockchain/fabric-operator/pkg/apis/deployer" @@ -39,7 +42,7 @@ import ( // GetOperatorConfig returns the operator configuration with the default templating files population // and with default versions set for components. -func GetOperatorConfig(configs, caFiles, peerFiles, ordererFiles, consoleFiles, voteFiles string) *config.Config { +func GetOperatorConfig(configs, caFiles, peerFiles, ordererFiles, consoleFiles, voteFiles, organizationFiles, federationFiles, networkFiles string) *config.Config { ulevel := uzap.NewAtomicLevelAt(2) if os.Getenv("LOG_LEVEL") == "debug" { ulevel = uzap.NewAtomicLevelAt(-1) @@ -108,6 +111,18 @@ func GetOperatorConfig(configs, caFiles, peerFiles, ordererFiles, consoleFiles, RoleBindingFile: filepath.Join(voteFiles, "rolebinding.yaml"), ServiceAccountFile: filepath.Join(voteFiles, "serviceaccount.yaml"), }, + OrganizationInitConfig: &orginit.Config{ + IAMEnabled: os.Getenv("OPERATOR_USER_TYPE") != "sa", + AdminRoleFile: filepath.Join(organizationFiles, "admin_role.yaml"), + ClientRoleFile: filepath.Join(organizationFiles, "client_role.yaml"), + RoleBindingFile: filepath.Join(organizationFiles, "role_binding.yaml"), + ClusterRoleFile: filepath.Join(organizationFiles, "cluster_role.yaml"), + ClusterRoleBindingFile: filepath.Join(organizationFiles, "cluster_role_binding.yaml"), + CAFile: filepath.Join(organizationFiles, "ca.yaml"), + StoragePath: "/tmp/orginit", + }, + FederationInitConfig: &fedinit.Config{}, + NetworkInitConfig: &netinit.Config{}, ConsoleInitConfig: &config.ConsoleConfig{ DeploymentFile: filepath.Join(consoleFiles, "deployment.yaml"), PVCFile: filepath.Join(consoleFiles, "pvc.yaml"), @@ -132,6 +147,7 @@ func GetOperatorConfig(configs, caFiles, peerFiles, ordererFiles, consoleFiles, } setDefaultVersions(cfg) + config.SetOperatorConfigFromEnvironment(operatorCfg) return cfg } diff --git a/integration/operatorrestart/operatorrestart_suite_test.go b/integration/operatorrestart/operatorrestart_suite_test.go index 2a6e537a..9cd05a12 100644 --- a/integration/operatorrestart/operatorrestart_suite_test.go +++ b/integration/operatorrestart/operatorrestart_suite_test.go @@ -29,10 +29,6 @@ import ( "testing" "time" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "github.com/onsi/gomega/gexec" - current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1" "github.com/IBM-Blockchain/fabric-operator/integration" "github.com/IBM-Blockchain/fabric-operator/integration/helper" @@ -42,6 +38,9 @@ import ( baseorderer "github.com/IBM-Blockchain/fabric-operator/pkg/offering/base/orderer" "github.com/IBM-Blockchain/fabric-operator/pkg/util" "github.com/IBM-Blockchain/fabric-operator/pkg/util/pointer" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/onsi/gomega/gexec" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" diff --git a/main.go b/main.go index 0477a778..38d5c692 100644 --- a/main.go +++ b/main.go @@ -86,7 +86,7 @@ func main() { operatorCfg.Operator.SetDefaults() - setOperatorConfigFromEnvironment(operatorCfg) + config.SetOperatorConfigFromEnvironment(operatorCfg) if err := command.Operator(operatorCfg); err != nil { log.Error(err, "failed to start operator") @@ -241,13 +241,3 @@ func setDefaultVoteDefinitions(cfg *config.Config) { func setDefaultNetworkDefinitions(cfg *config.Config) { cfg.NetworkInitConfig = &netinit.Config{} } - -func setOperatorConfigFromEnvironment(cfg *config.Config) { - if domain := os.Getenv("OPERATOR_INGRESS_DOMAIN"); domain != "" { - cfg.Operator.IngressDomain = domain - } - if iamServer := os.Getenv("OPERATOR_IAM_SERVER"); iamServer != "" { - cfg.Operator.IAM.Enabled = true - cfg.Operator.IAM.Server = iamServer - } -} diff --git a/operatorconfig/env.go b/operatorconfig/env.go new file mode 100644 index 00000000..25cb4cbb --- /dev/null +++ b/operatorconfig/env.go @@ -0,0 +1,31 @@ +/* + * Copyright contributors to the Hyperledger Fabric Operator project + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 operatorconfig + +import "os" + +func SetOperatorConfigFromEnvironment(cfg *Config) { + if domain := os.Getenv("OPERATOR_INGRESS_DOMAIN"); domain != "" { + cfg.Operator.IngressDomain = domain + } + if iamServer := os.Getenv("OPERATOR_IAM_SERVER"); iamServer != "" { + cfg.Operator.IAM.Enabled = true + cfg.Operator.IAM.Server = iamServer + } +} diff --git a/scripts/go-sec.sh b/scripts/go-sec.sh index a7555226..ddcbf549 100755 --- a/scripts/go-sec.sh +++ b/scripts/go-sec.sh @@ -18,10 +18,6 @@ # limitations under the License. # -RELEASE=$(curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/securego/gosec/releases/latest | jq -r .tag_name) - -echo "Latest Gosec release determined to be $RELEASE... Installing..." - curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $(go env GOPATH)/bin $RELEASE -gosec ./... \ No newline at end of file +gosec ./...