-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add `antctl get bgppolicy` agent command to get effective BGP policy applied on the Node. Add `antctl get bgpserver` agent command to get configuration of BGP server running on the Node. For #6209 Signed-off-by: Kumar Atish <kumar.atish@broadcom.com>
- Loading branch information
Showing
17 changed files
with
300 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2024 Antrea Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License 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 bgppolicy | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"reflect" | ||
|
||
"k8s.io/klog/v2" | ||
|
||
"antrea.io/antrea/pkg/agent/apis" | ||
"antrea.io/antrea/pkg/agent/querier" | ||
) | ||
|
||
// HandleFunc returns the function which can handle queries issued by the bgppolicy command. | ||
func HandleFunc(aq querier.AgentQuerier) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
bgpPolicyInfoQuerier := aq.GetBGPPolicyInfoQuerier() | ||
if reflect.ValueOf(bgpPolicyInfoQuerier).IsNil() { | ||
// The error message must match the "FOO is not enabled" pattern to pass antctl e2e tests. | ||
http.Error(w, "bgp is not enabled", http.StatusServiceUnavailable) | ||
return | ||
} | ||
|
||
bgpPolicyName, routerID, localASN, listenPort := bgpPolicyInfoQuerier.GetBGPPolicyInfo() | ||
bgpPolicyResp := apis.BGPPolicyResponse{ | ||
BGPPolicyName: bgpPolicyName, | ||
RouterID: routerID, | ||
LocalASN: localASN, | ||
ListenPort: listenPort, | ||
} | ||
|
||
err := json.NewEncoder(w).Encode(bgpPolicyResp) | ||
if err != nil { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
klog.Errorf("Error when encoding BGPPolicyResp to json: %v", err) | ||
} | ||
} | ||
} |
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,55 @@ | ||
// Copyright 2024 Antrea Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License 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 bgpserver | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"reflect" | ||
|
||
"k8s.io/klog/v2" | ||
|
||
"antrea.io/antrea/pkg/agent/apis" | ||
"antrea.io/antrea/pkg/agent/querier" | ||
) | ||
|
||
// HandleFunc returns the function which can handle queries issued by the bgpserver command. | ||
func HandleFunc(aq querier.AgentQuerier) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
bgpPolicyInfoQuerier := aq.GetBGPPolicyInfoQuerier() | ||
if reflect.ValueOf(bgpPolicyInfoQuerier).IsNil() { | ||
// The error message must match the "FOO is not enabled" pattern to pass antctl e2e tests. | ||
http.Error(w, "bgp is not enabled", http.StatusServiceUnavailable) | ||
return | ||
} | ||
|
||
routerID, localASN, listenPort, err := bgpPolicyInfoQuerier.GetBGPServerConfig() | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
bgpServerResp := apis.BGPServerResponse{ | ||
RouterID: routerID, | ||
LocalASN: localASN, | ||
ListenPort: listenPort, | ||
} | ||
|
||
err = json.NewEncoder(w).Encode(bgpServerResp) | ||
if err != nil { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
klog.Errorf("Error when encoding BGPServerResp to json: %v", err) | ||
} | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.