diff --git a/cli/cmd/csr.go b/cli/cmd/csr.go index 7e3b66fd..3d50eb88 100644 --- a/cli/cmd/csr.go +++ b/cli/cmd/csr.go @@ -134,10 +134,7 @@ func (crt *certificateV1) signRequest() error { if err := waitForResource(webhookName, crt.kubeClient, crt.timeout, func(name string, client kubernetes.Interface) bool { _, err := client.CertificatesV1().CertificateSigningRequests().Get(context.TODO(), name, metav1.GetOptions{}) - if err != nil { - return false - } - return true + return err == nil }); err != nil { return err } @@ -153,6 +150,9 @@ func (crt *certificateV1) signRequest() error { }) _, err = crt.kubeClient.CertificatesV1().CertificateSigningRequests().UpdateApproval(context.TODO(), webhookName, certReturn, metav1.UpdateOptions{}) + if err != nil { + return err + } return waitForResource(webhookName, crt.kubeClient, crt.timeout, func(name string, client kubernetes.Interface) bool { csr, err := client.CertificatesV1().CertificateSigningRequests().Get(context.TODO(), webhookName, metav1.GetOptions{}) @@ -219,7 +219,7 @@ func createCSR(privKey *rsa.PrivateKey) (*pem.Block, error) { // to check if a resource has been created and can be used func waitForResource(name string, kubeClient kubernetes.Interface, timeout int, resourceCheck func(string, kubernetes.Interface) bool) error { for i := 0; i < timeout; i++ { - if ok := resourceCheck(name, kubeClient); ok == true { + if resourceCheck(name, kubeClient) { return nil } time.Sleep(1 * time.Second) diff --git a/cli/cmd/install.go b/cli/cmd/install.go index 3d34bb05..8b646fe7 100644 --- a/cli/cmd/install.go +++ b/cli/cmd/install.go @@ -175,9 +175,7 @@ func cliInstall(options *installOptions) error { return errorAndCleanup(err, options.kubeClient) } - for _, val := range injectorValues { - stringValues = append(stringValues, val) - } + stringValues = append(stringValues, injectorValues...) stringValues = append(stringValues, fmt.Sprintf("marbleInjector.resourceKey=%s", resourceKey)) } @@ -247,7 +245,7 @@ func getRepo(name string, url string, settings *cli.EnvSettings) error { } if _, err := r.DownloadIndexFile(); err != nil { - return errors.New("Chart repository cannot be reached") + return errors.New("chart repository cannot be reached") } f.Update(c) diff --git a/cli/cmd/install_test.go b/cli/cmd/install_test.go index 5ae46e23..4cdb8154 100644 --- a/cli/cmd/install_test.go +++ b/cli/cmd/install_test.go @@ -161,6 +161,7 @@ func TestErrorAndCleanup(t *testing.T) { require.NoError(err) _, err = testClient.CertificatesV1().CertificateSigningRequests().Get(context.TODO(), webhookName, metav1.GetOptions{}) + require.NoError(err) err = errorAndCleanup(testError, testClient) assert.Equal(testError, err) diff --git a/cli/cmd/manifestGet.go b/cli/cmd/manifestGet.go index d02c9177..a6d6965a 100644 --- a/cli/cmd/manifestGet.go +++ b/cli/cmd/manifestGet.go @@ -60,7 +60,7 @@ func cliManifestGet(host string, cert []*pem.Block) ([]byte, error) { return nil, err } if resp.Body == nil { - return nil, errors.New("Received empty manifest") + return nil, errors.New("received empty manifest") } defer resp.Body.Close() diff --git a/cli/cmd/manifestUpdate.go b/cli/cmd/manifestUpdate.go index 07196ee2..af9ecc61 100644 --- a/cli/cmd/manifestUpdate.go +++ b/cli/cmd/manifestUpdate.go @@ -66,12 +66,12 @@ func cliManifestUpdate(manifest []byte, host string, clCert tls.Certificate, caC // Set rootCA for connection to coordinator certPool := x509.NewCertPool() if ok := certPool.AppendCertsFromPEM(pem.EncodeToMemory(caCert[len(caCert)-1])); !ok { - return errors.New("Failed to parse certificate") + return errors.New("failed to parse certificate") } // Add intermediate cert if applicable if len(caCert) > 1 { if ok := certPool.AppendCertsFromPEM(pem.EncodeToMemory(caCert[0])); !ok { - return errors.New("Failed to parse certificate") + return errors.New("failed to parse certificate") } } diff --git a/cli/cmd/manifest_test.go b/cli/cmd/manifest_test.go index 30ed281a..b682c714 100644 --- a/cli/cmd/manifest_test.go +++ b/cli/cmd/manifest_test.go @@ -47,7 +47,7 @@ func TestCliManifestGet(t *testing.T) { s.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusInternalServerError) }) - resp, err = cliManifestGet(host, []*pem.Block{cert}) + _, err = cliManifestGet(host, []*pem.Block{cert}) require.Error(err) } diff --git a/cli/cmd/namespaceRemove.go b/cli/cmd/namespaceRemove.go index 0a7aa764..de1e069d 100644 --- a/cli/cmd/namespaceRemove.go +++ b/cli/cmd/namespaceRemove.go @@ -62,7 +62,7 @@ func cliNameSpaceRemove(namespace string, kubeClient kubernetes.Interface) error return fmt.Errorf("unexpected value in namespace label: %s", val) } } else { - return fmt.Errorf("Namespace [%s] does not belong to the Marblerun mesh", namespace) + return fmt.Errorf("namespace [%s] does not belong to the Marblerun mesh", namespace) } return nil diff --git a/cli/cmd/precheck.go b/cli/cmd/precheck.go index 74094edd..6acb9a45 100644 --- a/cli/cmd/precheck.go +++ b/cli/cmd/precheck.go @@ -69,24 +69,13 @@ func cliCheckSGXSupport(kubeClient kubernetes.Interface) error { // nodeSupportsSGX checks if a single cluster node supports SGX in some way // Checks for different implementations of SGX device plugins should be put here (e.g. different resource definitions than the one used by Azure/Intel) func nodeSupportsSGX(capacityInfo corev1.ResourceList) bool { - if nodeHasAzureDevPlugin(capacityInfo) { - return true - } - - if nodeHasIntelDevPlugin(capacityInfo) { - return true - } - - return false + return nodeHasAzureDevPlugin(capacityInfo) || nodeHasIntelDevPlugin(capacityInfo) } // nodeHasAzureDevPlugin checks if a node has the Azures SGX device plugin installed func nodeHasAzureDevPlugin(capacityInfo corev1.ResourceList) bool { epcQuant := capacityInfo[azureEpc] - if epcQuant.Value() == 0 { - return false - } - return true + return epcQuant.Value() != 0 } // nodeHasIntelDevPlugin checks if a node has the Intel SGX device plugin installed @@ -94,8 +83,5 @@ func nodeHasIntelDevPlugin(capacityInfo corev1.ResourceList) bool { epcQuant := capacityInfo[intelEpc] enclaveQuant := capacityInfo[intelEnclave] provisionQuant := capacityInfo[intelProvision] - if epcQuant.Value() == 0 || enclaveQuant.Value() == 0 || provisionQuant.Value() == 0 { - return false - } - return true + return !(epcQuant.Value() == 0 || enclaveQuant.Value() == 0 || provisionQuant.Value() == 0) }