Skip to content

Commit

Permalink
Optimize makefile (fluid-cloudnative#1343)
Browse files Browse the repository at this point in the history
* Make makefile readable, To #38934091

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

* Make makefile readable, To #38934091

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

* Make makefile readable, To #38934091

Signed-off-by: cheyang <[email protected]>
  • Loading branch information
cheyang authored Jan 6, 2022
1 parent ab54f1e commit 916c9fb
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 28 deletions.
38 changes: 35 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,36 @@ GIT_SHA=$(shell git rev-parse --short HEAD || echo "HEAD")
GIT_VERSION=${VERSION}-${GIT_SHA}
PACKAGE=github.com/fluid-cloudnative/fluid

# Build binaries
BINARY_BUILD := dataset-controller-build
BINARY_BUILD += alluxioruntime-controller-build
BINARY_BUILD += jindoruntime-controller-build
BINARY_BUILD += juicefsruntime-controller-build
BINARY_BUILD += csi-build
BINARY_BUILD += webhook-build

# Build docker images
DOCKER_BUILD := docker-build-dataset-controller
DOCKER_BUILD += docker-build-alluxioruntime-controller
DOCKER_BUILD += docker-build-jindoruntime-controller
DOCKER_BUILD += docker-build-goosefsruntime-controller
DOCKER_BUILD += docker-build-csi
DOCKER_BUILD += docker-build-init-users
DOCKER_BUILD += docker-build-webhook
DOCKER_BUILD += docker-build-goosefsruntime-controller
DOCKER_BUILD += docker-build-juicefsruntime-controller

# Push docker images
DOCKER_PUSH := docker-push-dataset-controller
DOCKER_PUSH += docker-push-alluxioruntime-controller
DOCKER_PUSH += docker-push-jindoruntime-controller
DOCKER_PUSH += docker-push-jindoruntime-controller
DOCKER_PUSH += docker-push-csi
DOCKER_PUSH += docker-push-init-users
DOCKER_PUSH += docker-push-webhook
DOCKER_PUSH += docker-push-goosefsruntime-controller
DOCKER_PUSH += docker-push-juicefsruntime-controller

override LDFLAGS += \
-X ${PACKAGE}.version=${VERSION} \
-X ${PACKAGE}.buildDate=${BUILD_DATE} \
Expand All @@ -53,7 +83,7 @@ unit-test: generate fmt vet

# Build binary

build: dataset-controller-build alluxioruntime-controller-build jindoruntime-controller-build juicefsruntime-controller-build csi-build webhook-build
build: ${BINARY_BUILD}

csi-build: generate fmt vet
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=${GO_MODULE} go build -o bin/fluid-csi -ldflags '${LDFLAGS}' cmd/csi/main.go
Expand Down Expand Up @@ -176,8 +206,10 @@ docker-push-init-users: docker-build-init-users
docker-push-webhook: docker-build-webhook
docker push ${WEBHOOK_IMG}:${GIT_VERSION}

docker-build-all: docker-build-dataset-controller docker-build-alluxioruntime-controller docker-build-jindoruntime-controller docker-build-goosefsruntime-controller docker-build-csi docker-build-init-users docker-build-webhook docker-build-goosefsruntime-controller docker-build-juicefsruntime-controller
docker-push-all: docker-push-dataset-controller docker-push-alluxioruntime-controller docker-push-jindoruntime-controller docker-push-jindoruntime-controller docker-push-csi docker-push-init-users docker-push-webhook docker-push-goosefsruntime-controller docker-push-juicefsruntime-controller


docker-build-all: ${DOCKER_BUILD}
docker-push-all: ${DOCKER_PUSH}

# find or download controller-gen
# download controller-gen if necessary
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (
WebhookServiceName = "fluid-pod-admission-webhook"
WebhookSchedulePodPath = "mutate-fluid-io-v1alpha1-schedulepod"

CertSecretName = "fluid-webhook-certs"
CertSecretName = "fluid-webhook-certs"
)

// AdmissionHandler wrappers admission.Handler, but adding client-go capablities
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/kubeclient/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var (
restConfig *restclient.Config
log logr.Logger = ctrl.Log.WithName("kubeclient")
kubeconfigPath = "~/.kube/config"
mutex =&sync.Mutex{}
mutex = &sync.Mutex{}
)

// ExecOptions passed to ExecWithOptions
Expand Down
13 changes: 6 additions & 7 deletions pkg/utils/kubeclient/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func TestCreateSecret(t *testing.T) {

fakeClient := fake.NewFakeClientWithScheme(testScheme, mockSecret1)
testCases := map[string]struct {
mockSecret *v1.Secret
notFound bool
mockSecret *v1.Secret
notFound bool
}{
"Case 1: create new secret": {
mockSecret: &v1.Secret{
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestCreateSecret(t *testing.T) {
}
}
gotSecret, err := GetSecret(fakeClient, item.mockSecret.Name, item.mockSecret.Namespace)
if err != nil{
if err != nil {
t.Errorf("%s check failure, want not found error, but got %v", caseName, err)
} else {
if gotSecret == nil {
Expand All @@ -152,7 +152,6 @@ func TestCreateSecret(t *testing.T) {
}
}


func TestUpdateSecret(t *testing.T) {

mockSecret1 := &v1.Secret{
Expand All @@ -167,8 +166,8 @@ func TestUpdateSecret(t *testing.T) {

fakeClient := fake.NewFakeClientWithScheme(testScheme, mockSecret1)
testCases := map[string]struct {
mockSecret *v1.Secret
notFound bool
mockSecret *v1.Secret
notFound bool
}{
"Case 1: update new secret": {
mockSecret: &v1.Secret{
Expand Down Expand Up @@ -217,7 +216,7 @@ func TestUpdateSecret(t *testing.T) {
}
}
gotSecret, err := GetSecret(fakeClient, item.mockSecret.Name, item.mockSecret.Namespace)
if err != nil{
if err != nil {
t.Errorf("%s check failure, want not found error, but got %v", caseName, err)
} else {
if gotSecret == nil {
Expand Down
12 changes: 6 additions & 6 deletions pkg/utils/webhook/writer/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,31 @@ func WriteCertsToDir(dir string, certs *generator.Artifacts) error {

// write or overwrite the cert for ca
filename := path.Join(dir, CAKeyName)
if err := ioutil.WriteFile(filename, certs.CAKey, 0600); err != nil{
if err := ioutil.WriteFile(filename, certs.CAKey, 0600); err != nil {
return err
}
filename = path.Join(dir, CACertName)
if err := ioutil.WriteFile(filename, certs.CACert, 0600); err != nil{
if err := ioutil.WriteFile(filename, certs.CACert, 0600); err != nil {
return err
}

// write or overwrite the certs for serverName
filename = path.Join(dir, ServerCertName)
if err := ioutil.WriteFile(filename, certs.Cert, 0600); err != nil{
if err := ioutil.WriteFile(filename, certs.Cert, 0600); err != nil {
return err
}
filename = path.Join(dir, ServerKeyName)
if err := ioutil.WriteFile(filename, certs.Key, 0600); err != nil{
if err := ioutil.WriteFile(filename, certs.Key, 0600); err != nil {
return err
}

// write or overwrite the certs for serverName2
filename = path.Join(dir, ServerCertName2)
if err := ioutil.WriteFile(filename, certs.Cert, 0600); err != nil{
if err := ioutil.WriteFile(filename, certs.Cert, 0600); err != nil {
return err
}
filename = path.Join(dir, ServerKeyName2)
if err := ioutil.WriteFile(filename, certs.Key, 0600); err != nil{
if err := ioutil.WriteFile(filename, certs.Key, 0600); err != nil {
return err
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/webhook/certificate_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func (c *CertificateBuilder) BuildAndSyncCABundle(svcName, webhookName, cerPath
func (c *CertificateBuilder) genCA(ns, svc, certPath string) (*generator.Artifacts, error) {

certWriter, err := writer.NewSecretCertWriter(writer.SecretCertWriterOptions{
Client: c.Client,
Secret: &types.NamespacedName{Namespace: ns, Name: common.CertSecretName},
Client: c.Client,
Secret: &types.NamespacedName{Namespace: ns, Name: common.CertSecretName},
})
if err != nil {
return nil, fmt.Errorf("failed to new certWriter: %v", err)
Expand Down
15 changes: 7 additions & 8 deletions pkg/webhook/certificate_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func TestGenCA(t *testing.T) {

for index, item := range testCases {
certs, err := cb.genCA(item.ns, item.svc, item.certPath)
if err != nil && !item.canMkDir{
if err != nil && !item.canMkDir {
continue
}
gotLen := len(certs.CACert)
Expand All @@ -210,29 +210,28 @@ func TestGenCA(t *testing.T) {
}
}


}

func TestPatchCABundle(t *testing.T) {
var mockWebhookName = "mockWebhookName"
testCases := map[string]struct {
ca []byte
ca []byte
webhookName string
}{
"test case 1": {
ca: []byte{1, 2, 3},
ca: []byte{1, 2, 3},
webhookName: "mockWebhookName",
},
"test case 2": {
ca: []byte{2, 3, 4},
ca: []byte{2, 3, 4},
webhookName: "mockWebhookName",
},
"test case 3": {
ca: []byte{3, 4, 5},
ca: []byte{3, 4, 5},
webhookName: "mockWebhookName",
},
"test case 4": {
ca: []byte{4, 5, 6},
ca: []byte{4, 5, 6},
webhookName: "WebhookName",
},
}
Expand Down Expand Up @@ -270,7 +269,7 @@ func TestPatchCABundle(t *testing.T) {
cb := NewCertificateBuilder(client, log)
err := cb.PatchCABundle(item.webhookName, item.ca)
if err != nil {
if utils.IgnoreNotFound(err)!= nil{
if utils.IgnoreNotFound(err) != nil {
t.Errorf("%s cannot paas because fail to patch MutatingWebhookConfiguration", index)
} else {
continue
Expand Down

0 comments on commit 916c9fb

Please sign in to comment.