Skip to content

Commit

Permalink
Merge pull request #369 from dell/bugfix-1567-standalone-mode
Browse files Browse the repository at this point in the history
Set StandAlone proxy mode as default and remove configmap option
  • Loading branch information
suryagupta4 authored Dec 5, 2024
2 parents 86b9fb4 + e94d19b commit 88c4329
Show file tree
Hide file tree
Showing 98 changed files with 5,241 additions and 940 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ push: docker

# Run unit tests and skip the BDD tests
unit-test: golint check
( cd service; go clean -cache; CGO_ENABLED=0 GO111MODULE=on go test -skip TestGoDog -v -coverprofile=c.out ./... )
( cd service; go clean -cache; CGO_ENABLED=0 GO111MODULE=on go test -v -coverprofile=c.out ./... )

# Run BDD tests. Need to be root to run as tests require some system access, need to fix
bdd-test: golint check
Expand Down
4 changes: 2 additions & 2 deletions csireverseproxy/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright © 2020 Dell Inc. or its subsidiaries. All Rights Reserved.
# Copyright © 2020-2024 Dell Inc. or its subsidiaries. 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.
Expand All @@ -12,7 +12,7 @@
#
include overrides.mk

coverpackages= revproxy/v2,revproxy/v2/pkg/config,revproxy/v2/pkg/standaloneproxy
coverpackages= revproxy/v2,revproxy/v2/pkg/config,revproxy/v2/pkg/proxy

run:
@./run.sh
Expand Down
3 changes: 1 addition & 2 deletions csireverseproxy/deploy/config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
mode: StandAlone
port: 2222
logLevel: debug
logFormat: text
standAloneConfig:
config:
storageArrays:
- storageArrayId: "000000000001"
primaryURL: https://primary-1.unisphe.re:8443
Expand Down
49 changes: 21 additions & 28 deletions csireverseproxy/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
Copyright © 2021-2024 Dell Inc. or its subsidiaries. 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.
Expand Down Expand Up @@ -28,7 +28,7 @@ import (
"revproxy/v2/pkg/common"
"revproxy/v2/pkg/config"
"revproxy/v2/pkg/k8sutils"
"revproxy/v2/pkg/standaloneproxy"
"revproxy/v2/pkg/proxy"
"revproxy/v2/pkg/utils"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -93,17 +93,16 @@ func getServerOpts() ServerOpts {

// Server represents the proxy server
type Server struct {
HTTPServer *http.Server
Mode config.ProxyMode
Port string
CertFile string
KeyFile string
config *config.ProxyConfig
StandAloneProxy *standaloneproxy.StandAloneProxy
SigChan chan os.Signal
WaitGroup sync.WaitGroup
Mutex sync.Mutex
Opts ServerOpts
HTTPServer *http.Server
Port string
CertFile string
KeyFile string
config *config.ProxyConfig
Proxy *proxy.Proxy
SigChan chan os.Signal
WaitGroup sync.WaitGroup
Mutex sync.Mutex
Opts ServerOpts
}

// SetConfig - sets config for the server
Expand Down Expand Up @@ -136,21 +135,19 @@ func (s *Server) Setup(k8sUtils k8sutils.UtilsInterface) error {
s.CertFile = filepath.Join(s.Opts.TLSCertDir, s.Opts.CertFile)
s.KeyFile = filepath.Join(s.Opts.TLSCertDir, s.Opts.KeyFile)
s.Port = proxyConfig.Port
if proxyConfig.Mode == config.StandAlone {
standAloneProxy, err := standaloneproxy.NewStandAloneProxy(*proxyConfig.StandAloneProxyConfig)
if err != nil {
return err
}
s.StandAloneProxy = standAloneProxy
proxy, err := proxy.NewProxy(*proxyConfig)
if err != nil {
return err
}
s.Proxy = proxy
s.SetConfig(proxyConfig)
s.SigChan = make(chan os.Signal, 1)
return nil
}

// GetRevProxy - returns the current active proxy for the server
func (s *Server) GetRevProxy() RevProxy {
return s.StandAloneProxy
return s.Proxy
}

// Start - starts the HTTPS server
Expand Down Expand Up @@ -269,31 +266,27 @@ func (s *Server) EventHandler(k8sUtils k8sutils.UtilsInterface, secret *corev1.S
conf := s.Config().DeepCopy()
log.Infof("New credential/cert update event for the secret(%s)", secret.Name)
hasChanged := false
if conf.Mode != config.StandAlone {
log.Errorf("invalid proxy mode is give")
return
}

found := conf.StandAloneProxyConfig.IsSecretConfiguredForCerts(secret.Name)
found := conf.IsSecretConfiguredForCerts(secret.Name)
if found {
certFileName, err := k8sUtils.GetCertFileFromSecret(secret)
if err != nil {
log.Errorf("failed to get cert file from secret (error: %s). ignoring the config change event", err.Error())
return
}
isUpdated := conf.StandAloneProxyConfig.UpdateCerts(secret.Name, certFileName)
isUpdated := conf.UpdateCerts(secret.Name, certFileName)
if isUpdated {
hasChanged = true
}
}
found = conf.StandAloneProxyConfig.IsSecretConfiguredForArrays(secret.Name)
found = conf.IsSecretConfiguredForArrays(secret.Name)
if found {
creds, err := k8sUtils.GetCredentialsFromSecret(secret)
if err != nil {
log.Errorf("failed to get credentials from secret (error: %s). ignoring the config change event", err.Error())
return
}
isUpdated := conf.StandAloneProxyConfig.UpdateCreds(secret.Name, creds)
isUpdated := conf.UpdateCreds(secret.Name, creds)
if isUpdated {
hasChanged = true
}
Expand Down
51 changes: 25 additions & 26 deletions csireverseproxy/main_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
Copyright © 2021-2024 Dell Inc. or its subsidiaries. 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.
Expand Down Expand Up @@ -76,21 +76,21 @@ const (
)

var (
standAloneServer *Server
server *Server
primaryMockServer, backupMockServer *mockServer
httpClient *http.Client
)

func startTestServer() error {
if standAloneServer != nil {
if server != nil {
return nil
}
k8sUtils := k8smock.Init()
serverOpts := getServerOpts()
serverOpts.ConfigDir = common.TempConfigDir
// Create test standAlone proxy config and start the standAlone server
// Create test proxy config and start the server
serverOpts.ConfigFileName = tmpSAConfigFile
err := createTempConfig("StandAlone")
err := createTempConfig()
if err != nil {
return err
}
Expand All @@ -106,7 +106,7 @@ func startTestServer() error {
if err != nil {
return err
}
standAloneServer, err = startServer(k8sUtils, serverOpts)
server, err = startServer(k8sUtils, serverOpts)
return err
}

Expand Down Expand Up @@ -202,8 +202,8 @@ func stopServers() {
if backupMockServer != nil {
backupMockServer.server.Close()
}
if standAloneServer != nil {
standAloneServer.SigChan <- syscall.SIGHUP
if server != nil {
server.SigChan <- syscall.SIGHUP
}
}

Expand All @@ -230,22 +230,21 @@ func writeYAMLConfig(val interface{}, fileName, fileDir string) error {
return ioutil.WriteFile(filepath, file, 0o777)
}

func createTempConfig(mode string) error {
func createTempConfig() error {
proxyConfigMap, err := readYAMLConfig(common.TestConfigFileName, common.TestConfigDir)
if err != nil {
log.Fatalf("Failed to read sample config file. (%s)", err.Error())
return err
}
// set proxy mode for respective server
proxyConfigMap.Mode = config.ProxyMode(mode)

filename := tmpSAConfigFile
proxyConfigMap.Port = "8080"
// Create a ManagementServerConfig
tempMgmtServerConfig := createTempManagementServers()
proxyConfigMap.StandAloneConfig.ManagementServerConfig = tempMgmtServerConfig
proxyConfigMap.Config.ManagementServerConfig = tempMgmtServerConfig
// Create a StorageArrayConfig
tempStorageArrayConfig := createTempStorageArrays()
proxyConfigMap.StandAloneConfig.StorageArrayConfig = tempStorageArrayConfig
proxyConfigMap.Config.StorageArrayConfig = tempStorageArrayConfig
err = writeYAMLConfig(proxyConfigMap, filename, common.TempConfigDir)
if err != nil {
log.Fatalf("Failed to create a temporary config file. (%s)", err.Error())
Expand Down Expand Up @@ -347,7 +346,7 @@ func TestServer_EventHandler(t *testing.T) {

func TestServer_SAEventHandler(t *testing.T) {
k8sUtils := k8smock.Init()
oldProxySecret := standAloneServer.config.StandAloneProxyConfig.GetStorageArray(storageArrayID)[0].ProxyCredentialSecrets[proxySecretName]
oldProxySecret := server.config.GetStorageArray(storageArrayID)[0].ProxyCredentialSecrets[proxySecretName]
newSecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: proxySecretName,
Expand All @@ -359,8 +358,8 @@ func TestServer_SAEventHandler(t *testing.T) {
},
Type: "Generic",
}
standAloneServer.EventHandler(k8sUtils, newSecret)
newProxySecret := standAloneServer.config.StandAloneProxyConfig.GetStorageArray(storageArrayID)[0].ProxyCredentialSecrets[proxySecretName]
server.EventHandler(k8sUtils, newSecret)
newProxySecret := server.config.GetStorageArray(storageArrayID)[0].ProxyCredentialSecrets[proxySecretName]
if reflect.DeepEqual(oldProxySecret, newProxySecret) {
t.Errorf("cert file should change after update")
} else {
Expand All @@ -377,8 +376,8 @@ func TestServer_SAEventHandler(t *testing.T) {
},
Type: "Generic",
}
standAloneServer.EventHandler(k8sUtils, newSecret)
oldProxySecret = standAloneServer.config.StandAloneProxyConfig.GetStorageArray(storageArrayID)[0].ProxyCredentialSecrets[proxySecretName]
server.EventHandler(k8sUtils, newSecret)
oldProxySecret = server.config.GetStorageArray(storageArrayID)[0].ProxyCredentialSecrets[proxySecretName]
if reflect.DeepEqual(oldProxySecret, newProxySecret) {
t.Errorf("cert file should change after update")
} else {
Expand All @@ -389,7 +388,7 @@ func TestServer_SAEventHandler(t *testing.T) {
func TestSAHTTPRequest(t *testing.T) {
// make a request for version
path := utils.Prefix + "/version"
resp, err := doHTTPRequest(standAloneServer.Port, path)
resp, err := doHTTPRequest(server.Port, path)
if err != nil {
t.Error(err.Error())
return
Expand All @@ -398,7 +397,7 @@ func TestSAHTTPRequest(t *testing.T) {

// make a request for symmterix
path = utils.Prefix + "/91/system/symmetrix"
resp, err = doHTTPRequest(standAloneServer.Port, path)
resp, err = doHTTPRequest(server.Port, path)
if err != nil {
t.Error(err.Error())
return
Expand All @@ -407,7 +406,7 @@ func TestSAHTTPRequest(t *testing.T) {

// make a request for capabilities
path = utils.Prefix + "/91/replication/capabilities/symmetrix"
resp, err = doHTTPRequest(standAloneServer.Port, path)
resp, err = doHTTPRequest(server.Port, path)
if err != nil {
t.Error(err.Error())
return
Expand All @@ -416,7 +415,7 @@ func TestSAHTTPRequest(t *testing.T) {

// make a request to endpoint for ServeReverseProxy
path = utils.Prefix + "/91/sloprovisioning/symmetrix/" + storageArrayID
resp, err = doHTTPRequest(standAloneServer.Port, path)
resp, err = doHTTPRequest(server.Port, path)
if err != nil {
t.Error(err.Error())
return
Expand All @@ -425,7 +424,7 @@ func TestSAHTTPRequest(t *testing.T) {

// make a request to ServeVolume
path = utils.Prefix + "/91/sloprovisioning/symmetrix/" + storageArrayID + "/volume"
resp, err = doHTTPRequest(standAloneServer.Port, path)
resp, err = doHTTPRequest(server.Port, path)
if err != nil {
t.Error(err.Error())
return
Expand All @@ -435,7 +434,7 @@ func TestSAHTTPRequest(t *testing.T) {
// make a request to ServeIterator
id := "00000000-1111-2abc-def3-44gh55ij66kl_0"
path = utils.Prefix + "/common/Iterator/" + id + "/page"
resp, err = doHTTPRequest(standAloneServer.Port, path)
resp, err = doHTTPRequest(server.Port, path)
if err != nil {
t.Error(err.Error())
return
Expand All @@ -444,15 +443,15 @@ func TestSAHTTPRequest(t *testing.T) {

// make a request for performance
path = utils.Prefix + "/performance/Array/keys"
resp, err = doHTTPRequest(standAloneServer.Port, path)
resp, err = doHTTPRequest(server.Port, path)
if err != nil {
t.Error(err.Error())
return
}
fmt.Printf("RESPONSE_BODY: %s\n", resp)

path = utils.PrivatePrefix + "/91/sloprovisioning/symmetrix/" + storageArrayID
resp, err = doHTTPRequest(standAloneServer.Port, path)
resp, err = doHTTPRequest(server.Port, path)
log.Info("test info is there")
if err != nil {
t.Error(err.Error())
Expand Down
2 changes: 1 addition & 1 deletion csireverseproxy/manifests/revproxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ spec:
- name: X_CSI_REVPROXY_TLS_CERT_DIR
value: /app/tls
- name: X_CSI_REVPROXY_WATCH_NAMESPACE
value: powermax #Change this to the namespace where proxy will be installed
value: powermax # Change this to the namespace where proxy will be installed

Check warning on line 76 in csireverseproxy/manifests/revproxy.yaml

View workflow job for this annotation

GitHub Actions / Golang Validation / Yaml Lint

76:31 [comments] too few spaces before comment
volumeMounts:
- name: configmap-volume
mountPath: /etc/config/configmap
Expand Down
Loading

0 comments on commit 88c4329

Please sign in to comment.