Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Packet CCM to v1.0.0 #884

Merged
merged 3 commits into from
Apr 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 58 additions & 24 deletions pkg/templates/externalccm/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package externalccm

import (
"context"
"encoding/json"

"github.com/pkg/errors"

Expand All @@ -33,10 +34,16 @@ import (
"k8s.io/apimachinery/pkg/runtime"
)

type packetCloudSA struct {
APIKey string `json:"apiKey"`
ProjectID string `json:"projectID"`
}

const (
packetImage = "packethost/packet-ccm:v0.0.4"
packetSAName = "cloud-controller-manager"
packetDeploymentName = "packet-cloud-controller-manager"
packetImage = "packethost/packet-ccm:v1.0.0"
packetSAName = "cloud-controller-manager"
packetDeploymentName = "packet-cloud-controller-manager"
packetCloudSASecretName = "packet-cloud-config"
)

func ensurePacket(s *state.State) error {
Expand All @@ -47,10 +54,21 @@ func ensurePacket(s *state.State) error {
ctx := context.Background()
sa := packetServiceAccount()
crole := packetClusterRole()

creds, err := credentials.ProviderCredentials(s.Cluster.CloudProvider.Name, s.CredentialsFilePath)
if err != nil {
return errors.Wrap(err, "failed to fetch credentials")
}
secret, err := packetCloudSASecret(creds)
if err != nil {
return errors.Wrap(err, "failed to generate packet cloud config secret")
}

k8sobjects := []runtime.Object{
sa,
crole,
genClusterRoleBinding("system:cloud-controller-manager", crole, sa),
secret,
}

for _, obj := range k8sobjects {
Expand All @@ -71,6 +89,27 @@ func packetServiceAccount() *corev1.ServiceAccount {
}
}

func packetCloudSASecret(creds map[string]string) (*corev1.Secret, error) {
cloudSA := &packetCloudSA{
APIKey: creds[credentials.PacketAPIKeyMC],
ProjectID: creds[credentials.PacketProjectID],
}
b, err := json.Marshal(cloudSA)
if err != nil {
return nil, errors.Wrap(err, "failed to marshal cloud-sa to json")
}

return &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: packetCloudSASecretName,
Namespace: metav1.NamespaceSystem,
},
Data: map[string][]byte{
"cloud-sa.json": b,
},
}, nil
}

func packetClusterRole() *rbacv1.ClusterRole {
return &rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -180,29 +219,14 @@ func packetDeployment() *appsv1.Deployment {
"--cloud-provider=packet",
"--leader-elect=false",
"--allow-untagged-cloud=true",
"--authentication-skip-lookup=true",
"--provider-config=/etc/cloud-sa/cloud-sa.json",
},
Env: []corev1.EnvVar{
{
Name: "PACKET_AUTH_TOKEN",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: credentials.SecretName,
},
Key: credentials.PacketAPIKeyMC,
},
},
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "PACKET_PROJECT_ID",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: credentials.SecretName,
},
Key: credentials.PacketProjectID,
},
},
Name: "cloud-sa-volume",
ReadOnly: true,
MountPath: "/etc/cloud-sa",
},
},
Resources: corev1.ResourceRequirements{
Expand All @@ -213,6 +237,16 @@ func packetDeployment() *appsv1.Deployment {
},
},
},
Volumes: []corev1.Volume{
{
Name: "cloud-sa-volume",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: packetCloudSASecretName,
},
},
},
},
},
},
},
Expand Down