cmd/kgctl: add output options for showconf
This commit adds several output options to the `showconf` command of the `kgctl` binary: * `--as-peer`: this can be used to generate a peer configuration, which can be used to configure the selected resource as a peer of another WireGuard interface * `--output`: this can be used to select the desired output format of the peer resource, available options are: WireGuard, YAML, and JSON.
This commit is contained in:
@@ -31,7 +31,7 @@ var (
|
||||
const GroupName = "kilo.squat.ai"
|
||||
|
||||
// SchemeGroupVersion is the group version used to register these objects.
|
||||
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"}
|
||||
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: Version}
|
||||
|
||||
// Resource takes an unqualified resource and returns a Group-qualified GroupResource.
|
||||
func Resource(resource string) schema.GroupResource {
|
||||
|
@@ -21,15 +21,23 @@ import (
|
||||
"net"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
)
|
||||
|
||||
const (
|
||||
// Version is the version of this API.
|
||||
Version = "v1alpha1"
|
||||
// PeerKind is the API kind for the peer resource.
|
||||
PeerKind = "Peer"
|
||||
// PeerPlural is the plural name for the peer resource.
|
||||
PeerPlural = "peers"
|
||||
)
|
||||
|
||||
var (
|
||||
// PeerGVK is the GroupVersionKind for Peers.
|
||||
PeerGVK = schema.GroupVersionKind{Group: GroupName, Version: Version, Kind: PeerKind}
|
||||
)
|
||||
|
||||
// PeerShortNames are convenient shortnames for the peer resource.
|
||||
var PeerShortNames = []string{"peer"}
|
||||
|
||||
|
@@ -338,6 +338,25 @@ func (t *Topology) Conf() *wireguard.Conf {
|
||||
return c
|
||||
}
|
||||
|
||||
// AsPeer generates the WireGuard peer configuration for the local location of the given Topology.
|
||||
// This configuration can be used to configure this location as a peer of another WireGuard interface.
|
||||
func (t *Topology) AsPeer() *wireguard.Peer {
|
||||
for _, s := range t.segments {
|
||||
if s.location != t.location {
|
||||
continue
|
||||
}
|
||||
return &wireguard.Peer{
|
||||
AllowedIPs: s.allowedIPs,
|
||||
Endpoint: &wireguard.Endpoint{
|
||||
IP: s.endpoint,
|
||||
Port: uint32(t.port),
|
||||
},
|
||||
PublicKey: s.key,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PeerConf generates a WireGuard configuration file for a given peer in a Topology.
|
||||
func (t *Topology) PeerConf(name string) *wireguard.Conf {
|
||||
c := &wireguard.Conf{}
|
||||
|
Reference in New Issue
Block a user