Skip to content

Commit

Permalink
Remove files which are not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
rmohr committed May 2, 2019
1 parent d860fde commit 0c9f8ef
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 217 deletions.
3 changes: 0 additions & 3 deletions pkg/virt-api/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ go_library(
srcs = [
"api.go",
"ca-manager.go",
"filesystem.go",
"generated_mock_filesystem.go",
],
importpath = "kubevirt.io/kubevirt/pkg/virt-api",
visibility = ["//visibility:public"],
Expand All @@ -29,7 +27,6 @@ go_library(
"//vendor/github.com/emicklei/go-restful:go_default_library",
"//vendor/github.com/emicklei/go-restful-openapi:go_default_library",
"//vendor/github.com/go-openapi/spec:go_default_library",
"//vendor/github.com/golang/mock/gomock:go_default_library",
"//vendor/github.com/prometheus/client_golang/prometheus/promhttp:go_default_library",
"//vendor/github.com/spf13/pflag:go_default_library",
"//vendor/k8s.io/api/admissionregistration/v1beta1:go_default_library",
Expand Down
29 changes: 3 additions & 26 deletions pkg/virt-api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"fmt"
"io/ioutil"
"net/http"
"path/filepath"
"sync"

"github.com/emicklei/go-restful"
Expand Down Expand Up @@ -112,10 +111,6 @@ type virtAPIApp struct {
signingCertBytes []byte
certBytes []byte
keyBytes []byte
certFile string
keyFile string
caFile string
signingCertFile string
namespace string
tlsConfig *tls.Config
}
Expand Down Expand Up @@ -935,27 +930,9 @@ func (app *virtAPIApp) createSubresourceApiservice() error {
return nil
}

func (app *virtAPIApp) setupTLS(fs Filesystem, caManager ClientCAManager) error {
func (app *virtAPIApp) setupTLS(caManager ClientCAManager) error {

app.keyFile = filepath.Join(app.certsDirectory, "/key.pem")
app.certFile = filepath.Join(app.certsDirectory, "/cert.pem")
app.signingCertFile = filepath.Join(app.certsDirectory, "/signingCert.pem")

// Write the certs to disk
err := fs.WriteFile(app.keyFile, app.keyBytes, 0600)
if err != nil {
return err
}
err = fs.WriteFile(app.certFile, app.certBytes, 0600)
if err != nil {
return err
}
err = fs.WriteFile(app.signingCertFile, app.signingCertBytes, 0600)
if err != nil {
return err
}

certPair, err := tls.LoadX509KeyPair(app.certFile, app.keyFile)
certPair, err := tls.X509KeyPair(app.certBytes, app.keyBytes)
if err != nil {
return fmt.Errorf("some special error: %b", err)
}
Expand Down Expand Up @@ -1011,7 +988,7 @@ func (app *virtAPIApp) startTLS(stopCh <-chan struct{}) error {

caManager := NewClientCAManager(authConfigMapInformer.GetStore())

err := app.setupTLS(IOUtil{}, caManager)
err := app.setupTLS(caManager)
if err != nil {
return err
}
Expand Down
51 changes: 2 additions & 49 deletions pkg/virt-api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ import (
"net/http"
"net/http/httptest"
"os"
"path/filepath"

restful "github.com/emicklei/go-restful"
"github.com/emicklei/go-restful"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -50,15 +49,13 @@ const namespaceKubevirt = "kubevirt"

var _ = Describe("Virt-api", func() {
var app virtAPIApp
var tmpDir, keyFile, certFile, signingCertFile, caFile string
var tmpDir string
var server *ghttp.Server
var backend *httptest.Server
var ctrl *gomock.Controller
var authorizorMock *rest.MockVirtApiAuthorizor
var filesystemMock *MockFilesystem
var expectedValidatingWebhooks *admissionregistrationv1beta1.ValidatingWebhookConfiguration
var expectedMutatingWebhooks *admissionregistrationv1beta1.MutatingWebhookConfiguration
var restrictiveMode os.FileMode
subresourceAggregatedApiName := v1.SubresourceGroupVersion.Version + "." + v1.SubresourceGroupName
log.Log.SetIOWriter(GinkgoWriter)

Expand All @@ -71,11 +68,6 @@ var _ = Describe("Virt-api", func() {
Expect(err).ToNot(HaveOccurred())
app.virtCli, _ = kubecli.GetKubevirtClientFromFlags(server.URL(), "")
app.certsDirectory = tmpDir
keyFile = filepath.Join(app.certsDirectory, "/key.pem")
certFile = filepath.Join(app.certsDirectory, "/cert.pem")
caFile = filepath.Join(app.certsDirectory, "/clientCA.crt")
signingCertFile = filepath.Join(app.certsDirectory, "/signingCert.pem")
restrictiveMode = 0600

config, err := clientcmd.BuildConfigFromFlags(server.URL(), "")
Expect(err).ToNot(HaveOccurred())
Expand All @@ -84,7 +76,6 @@ var _ = Describe("Virt-api", func() {
Expect(err).ToNot(HaveOccurred())
ctrl = gomock.NewController(GinkgoT())
authorizorMock = rest.NewMockVirtApiAuthorizor(ctrl)
filesystemMock = NewMockFilesystem(ctrl)

// Reset go-restful
http.DefaultServeMux = new(http.ServeMux)
Expand Down Expand Up @@ -481,44 +472,6 @@ var _ = Describe("Virt-api", func() {
Expect(err).To(HaveOccurred())
}, 5)

It("should fail setupTLS without any data available at key write error", func() {
filesystemMock.EXPECT().
WriteFile(keyFile, app.keyBytes, restrictiveMode).
Return(errors.New("fake error writing " + caFile))
err := app.setupTLS(filesystemMock, nil)
Expect(err).To(HaveOccurred())
}, 5)

It("should fail setupTLS at keyBytes write error", func() {
filesystemMock.EXPECT().
WriteFile(keyFile, app.keyBytes, restrictiveMode).
Return(errors.New("fake error writing " + keyFile))
err := app.setupTLS(filesystemMock, nil)
Expect(err).To(HaveOccurred())
}, 5)

It("should fail setupTLS at certFile write error", func() {
filesystemMock.EXPECT().
WriteFile(keyFile, app.keyBytes, restrictiveMode)
filesystemMock.EXPECT().
WriteFile(certFile, app.certBytes, restrictiveMode).
Return(errors.New("fake error writing " + certFile))
err := app.setupTLS(filesystemMock, nil)
Expect(err).To(HaveOccurred())
}, 5)

It("should fail setupTLS at signingCertBytes write error", func() {
filesystemMock.EXPECT().
WriteFile(keyFile, app.keyBytes, restrictiveMode)
filesystemMock.EXPECT().
WriteFile(certFile, app.certBytes, restrictiveMode)
filesystemMock.EXPECT().
WriteFile(signingCertFile, app.signingCertBytes, restrictiveMode).
Return(errors.New("fake error writing " + signingCertFile))
err := app.setupTLS(filesystemMock, nil)
Expect(err).To(HaveOccurred())
}, 5)

It("should have default values for flags", func() {
app.AddFlags()
Expect(app.SwaggerUI).To(Equal("third_party/swagger-ui"))
Expand Down
34 changes: 0 additions & 34 deletions pkg/virt-api/filesystem.go

This file was deleted.

105 changes: 0 additions & 105 deletions pkg/virt-api/generated_mock_filesystem.go

This file was deleted.

0 comments on commit 0c9f8ef

Please sign in to comment.