-
Notifications
You must be signed in to change notification settings - Fork 619
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3936 from amogh09/ebs-healthcheck
Add health check feature to EBS CSI Driver
- Loading branch information
Showing
7 changed files
with
182 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//go:build unit | ||
// +build unit | ||
|
||
// Copyright Amazon.com Inc. or its affiliates. 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. A copy of the | ||
// License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0/ | ||
// | ||
// or in the "license" file accompanying this file. This file is distributed | ||
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
// express or implied. See the License for the specific language governing | ||
// permissions and limitations under the License. | ||
|
||
package driver | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/container-storage-interface/spec/lib/go/csi" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// Tests that NodeGetCapabilities returns the node's capabilities | ||
func TestNodeGetCapabilities(t *testing.T) { | ||
node := &nodeService{} | ||
res, err := node.NodeGetCapabilities(context.Background(), &csi.NodeGetCapabilitiesRequest{}) | ||
require.NoError(t, err) | ||
|
||
capTypes := []csi.NodeServiceCapability_RPC_Type{} | ||
for _, cap := range res.Capabilities { | ||
capTypes = append(capTypes, cap.GetRpc().GetType()) | ||
} | ||
|
||
expectedCapTypes := []csi.NodeServiceCapability_RPC_Type{ | ||
csi.NodeServiceCapability_RPC_GET_VOLUME_STATS, | ||
csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME, | ||
} | ||
assert.Equal(t, len(expectedCapTypes), len(capTypes)) | ||
for _, expectedCapType := range expectedCapTypes { | ||
assert.Contains(t, capTypes, expectedCapType) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright Amazon.com Inc. or its affiliates. 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. A copy of the | ||
// License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0/ | ||
// | ||
// or in the "license" file accompanying this file. This file is distributed | ||
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
// express or implied. See the License for the specific language governing | ||
// permissions and limitations under the License. | ||
|
||
// This package contains utilities related to the health of the CSI Driver. | ||
package health | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net" | ||
"time" | ||
|
||
"github.com/aws/amazon-ecs-agent/ecs-agent/daemonimages/csidriver/util" | ||
"github.com/container-storage-interface/spec/lib/go/csi" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
const ( | ||
defaultResponseTimeout = 5 * time.Second | ||
) | ||
|
||
// Checks the health of an already running CSI Driver Server by querying for | ||
// Node Service capabilities. | ||
func CheckHealth(endpoint string) error { | ||
// Parse the endpoint | ||
scheme, endpoint, err := util.ParseEndpointNoRemove(endpoint) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse endpoint: %w", err) | ||
} | ||
|
||
// Connect to the server | ||
dialer := func(ctx context.Context, addr string) (net.Conn, error) { | ||
return net.Dial(scheme, addr) | ||
} | ||
conn, err := grpc.Dial( | ||
endpoint, | ||
grpc.WithTransportCredentials(insecure.NewCredentials()), | ||
grpc.WithContextDialer(dialer), | ||
) | ||
if err != nil { | ||
return fmt.Errorf("failed to connect to the server: %w", err) | ||
} | ||
defer conn.Close() | ||
|
||
// Call the server to fetch node capabilities | ||
client := csi.NewNodeClient(conn) | ||
ctx, cancel := context.WithTimeout(context.Background(), defaultResponseTimeout) | ||
defer cancel() | ||
res, err := client.NodeGetCapabilities(ctx, &csi.NodeGetCapabilitiesRequest{}) | ||
if err != nil { | ||
return fmt.Errorf("failed to get node capabilities: %w", err) | ||
} | ||
klog.Infof("Node capabilities: %s", res.String()) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters