added csr approver
This commit is contained in:
parent
b0e048ba9d
commit
bc750389dc
14 changed files with 852 additions and 310 deletions
130
pkg/pvecloud/instances.go
Normal file
130
pkg/pvecloud/instances.go
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
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 pvecloud
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
cloudprovider "k8s.io/cloud-provider"
|
||||
|
||||
pve "git.giftfish.de/ston1th/pve-go"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
)
|
||||
|
||||
// InstanceType is not implemented
|
||||
const InstanceType = "pveServer"
|
||||
|
||||
type instances struct {
|
||||
client *pve.Client
|
||||
}
|
||||
|
||||
func newInstances(client *pve.Client) *instances {
|
||||
return &instances{client}
|
||||
}
|
||||
|
||||
func (i *instances) NodeAddressesByProviderID(ctx context.Context, providerID string) ([]v1.NodeAddress, error) {
|
||||
server, err := getServerByProviderID(ctx, i.client, providerID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return i.nodeAddresses(ctx, server), nil
|
||||
}
|
||||
|
||||
func (i *instances) NodeAddresses(ctx context.Context, nodeName types.NodeName) ([]v1.NodeAddress, error) {
|
||||
server, err := getServerByName(ctx, i.client, string(nodeName))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
server, err = getServerByProviderID(ctx, i.client, server.K8sID())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return i.nodeAddresses(ctx, server), nil
|
||||
}
|
||||
|
||||
func (i *instances) InstanceID(ctx context.Context, nodeName types.NodeName) (string, error) {
|
||||
ref, err := getServerRefByName(ctx, i.client, string(nodeName))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return strings.TrimPrefix(ref.K8sID(), scheme), nil
|
||||
}
|
||||
|
||||
func (i *instances) InstanceType(ctx context.Context, nodeName types.NodeName) (string, error) {
|
||||
return InstanceType, nil
|
||||
}
|
||||
|
||||
func (i *instances) InstanceTypeByProviderID(ctx context.Context, providerID string) (string, error) {
|
||||
return InstanceType, nil
|
||||
}
|
||||
|
||||
func (i *instances) AddSSHKeyToAllInstances(ctx context.Context, user string, keyData []byte) error {
|
||||
return cloudprovider.NotImplemented
|
||||
}
|
||||
|
||||
func (i *instances) CurrentNodeName(ctx context.Context, hostname string) (types.NodeName, error) {
|
||||
return types.NodeName(hostname), nil
|
||||
}
|
||||
|
||||
func (i *instances) InstanceExistsByProviderID(ctx context.Context, providerID string) (exists bool, err error) {
|
||||
server, err := getServerByProviderID(ctx, i.client, providerID)
|
||||
if err != nil && err != cloudprovider.InstanceNotFound {
|
||||
return
|
||||
}
|
||||
err = nil
|
||||
exists = server != nil
|
||||
return
|
||||
}
|
||||
|
||||
func (i *instances) InstanceShutdownByProviderID(ctx context.Context, providerID string) (isOff bool, err error) {
|
||||
server, err := getServerByProviderID(ctx, i.client, providerID)
|
||||
if err != nil && err != cloudprovider.InstanceNotFound {
|
||||
return
|
||||
}
|
||||
err = nil
|
||||
isOff = server != nil && server.Status == pve.ServerStatusStopped
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
// TODO
|
||||
func (i *instances) InstanceMetadataByProviderID(ctx context.Context, providerID string) (*cloudprovider.InstanceMetadata, error) {
|
||||
addrs, err := i.NodeAddressesByProviderID(ctx, providerID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &cloudprovider.InstanceMetadata{
|
||||
ProviderID: providerID,
|
||||
NodeAddresses: addrs,
|
||||
}, nil
|
||||
}
|
||||
*/
|
||||
|
||||
func (i *instances) nodeAddresses(ctx context.Context, srv *pve.Server) []v1.NodeAddress {
|
||||
var internalIP string
|
||||
ipc := srv.IPConfig.Get(0)
|
||||
if ipc != nil {
|
||||
ip, _, err := net.ParseCIDR(ipc.IPv4CIDR)
|
||||
if err == nil {
|
||||
internalIP = ip.String()
|
||||
}
|
||||
}
|
||||
addrs := []v1.NodeAddress{
|
||||
{Type: v1.NodeHostName, Address: srv.Name},
|
||||
{Type: v1.NodeInternalIP, Address: internalIP},
|
||||
}
|
||||
return addrs
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue