Skip to content

Commit

Permalink
fix staticcheck warnings in cli
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasten committed May 4, 2021
1 parent 8ce9776 commit 58d5514
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 31 deletions.
10 changes: 5 additions & 5 deletions cli/cmd/csr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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{})
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cli/cmd/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/manifestGet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/manifestUpdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/namespaceRemove.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 3 additions & 17 deletions cli/cmd/precheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,33 +69,19 @@ 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
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)
}

0 comments on commit 58d5514

Please sign in to comment.