Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: integration test #33

Merged
merged 1 commit into from
Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,17 @@ 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: |
# sleep 360 && kubectl --kubeconfig $KUBECONFIG_PATH describe pods --all-namespaces &
# make integration-tests
env:
INT_TEST_NAME: ${{ matrix.suite }}
WEBHOOK_DISABLED: true
16 changes: 13 additions & 3 deletions integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
18 changes: 17 additions & 1 deletion integration/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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"),
Expand All @@ -132,6 +147,7 @@ func GetOperatorConfig(configs, caFiles, peerFiles, ordererFiles, consoleFiles,
}

setDefaultVersions(cfg)
config.SetOperatorConfigFromEnvironment(operatorCfg)
return cfg
}

Expand Down
7 changes: 3 additions & 4 deletions integration/operatorrestart/operatorrestart_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
12 changes: 1 addition & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
}
31 changes: 31 additions & 0 deletions operatorconfig/env.go
Original file line number Diff line number Diff line change
@@ -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
}
}
6 changes: 1 addition & 5 deletions scripts/go-sec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
gosec ./...