Skip to content

Commit

Permalink
Ping external ip from withing the cluster to verify connectivity
Browse files Browse the repository at this point in the history
In case it fails it will rollback nmstate changes.

Signed-off-by: Quique Llorente <[email protected]>
  • Loading branch information
qinqon committed Oct 4, 2019
1 parent 05f0208 commit fc0e1cf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ push-handler: handler
docker push $(HANDLER_IMAGE)

test/unit: $(GINKGO)
INTERFACES_FILTER="" NODE_NAME=node01 $(GINKGO) $(UNIT_TEST_ARGS) ./pkg/
CONNECTIVITY_CHECK_ENDPOINT="8.8.8.8" INTERFACES_FILTER="" NODE_NAME=node01 $(GINKGO) $(UNIT_TEST_ARGS) ./pkg/

test/e2e: $(OPERATOR_SDK)
$(OPERATOR_SDK) test local ./test/e2e \
Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM fedora:30

RUN sudo dnf install -y nmstate iproute && \
RUN sudo dnf install -y nmstate iproute iputils && \
sudo dnf clean all

# TODO: Delete this line after we update nmstate to include the change
Expand Down
6 changes: 6 additions & 0 deletions deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ spec:
configMapKeyRef:
name: nmstate-config
key: interfaces_filter
- name: CONNECTIVITY_CHECK_ENDPOINT
valueFrom:
configMapKeyRef:
name: nmstate-config
key: connectivity_check_endopoint
volumeMounts:
- name: dbus-socket
mountPath: /run/dbus/system_bus_socket
Expand All @@ -74,3 +79,4 @@ metadata:
data:
node_network_state_refresh_interval: "5"
interfaces_filter: "veth*"
connectivity_check_endopoint: "8.8.8.8"
18 changes: 17 additions & 1 deletion pkg/helper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const nmstateCommand = "nmstatectl"
const vlanFilteringCommand = "vlan-filtering"

var (
interfacesFilterGlob glob.Glob
interfacesFilterGlob glob.Glob
connectivityCheckEndpoint string
)

func init() {
Expand All @@ -31,6 +32,11 @@ func init() {
panic("INTERFACES_FILTER is mandatory")
}
interfacesFilterGlob = glob.MustCompile(interfacesFilter)

connectivityCheckEndpoint, isSet = os.LookupEnv("CONNECTIVITY_CHECK_ENDPOINT")
if !isSet {
panic("CONNECTIVITY_CHECK_ENDPOINT is mandatory")
}
}

func show(arguments ...string) (string, error) {
Expand Down Expand Up @@ -159,6 +165,10 @@ func UpdateCurrentState(client client.Client, nodeNetworkState *nmstatev1alpha1.
return nil
}

func ping(endpoint string) error {
return exec.Command("ping", "-c", "3", endpoint).Run()
}

func ApplyDesiredState(nodeNetworkState *nmstatev1alpha1.NodeNetworkState) (string, error) {
desiredState := string(nodeNetworkState.Spec.DesiredState)
if len(desiredState) == 0 {
Expand Down Expand Up @@ -188,10 +198,16 @@ func ApplyDesiredState(nodeNetworkState *nmstatev1alpha1.NodeNetworkState) (stri
}
}

err = ping(connectivityCheckEndpoint)
if err != nil {
return commandOutput, rollback(fmt.Errorf("error pinging external address after network reconfiguration"))
}

_, err = commit()
if err != nil {
return commandOutput, rollback(err)
}

commandOutput += fmt.Sprintf("setOutput: %s \n", setOutput)
return commandOutput, nil
}
Expand Down

0 comments on commit fc0e1cf

Please sign in to comment.