Skip to content

Commit

Permalink
Merge pull request #41 from replicatedhq/metadata-fallback
Browse files Browse the repository at this point in the history
Use the proxied, portforwarded address
  • Loading branch information
marccampbell authored Sep 8, 2019
2 parents 8562e79 + 60303ed commit e46e719
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/kotsadm/api_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func apiDeployment(namespace string) *appsv1.Deployment {
},
{
Name: "SHIP_API_ADVERTISE_ENDPOINT",
Value: fmt.Sprintf("http://kotsadm-api.%s.svc.cluster.local:3000", namespace),
Value: "http://localhost:8800",
},
{
Name: "S3_ENDPOINT",
Expand Down
26 changes: 26 additions & 0 deletions pkg/kotsadm/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ func getOperatorYAML(namespace string) (map[string][]byte, error) {
}
docs["operator-rolebinding.yaml"] = roleBinding.Bytes()

var serviceAccount bytes.Buffer
if err := s.Encode(operatorServiceAccount(namespace), &serviceAccount); err != nil {
return nil, errors.Wrap(err, "failed to marshal operator service account")
}
docs["operator-serviceaccount.yaml"] = serviceAccount.Bytes()

var deployment bytes.Buffer
if err := s.Encode(operatorDeployment(namespace), &deployment); err != nil {
return nil, errors.Wrap(err, "failed to marshal operator deployment")
Expand Down Expand Up @@ -57,6 +63,10 @@ func ensureOperatorRBAC(namespace string, clientset *kubernetes.Clientset) error
return errors.Wrap(err, "failed to ensure operator role binding")
}

if err := ensureOperatorServiceAccount(namespace, clientset); err != nil {
return errors.Wrap(err, "failed to ensure operator service account")
}

return nil
}

Expand Down Expand Up @@ -92,6 +102,22 @@ func ensureOperatorRoleBinding(namespace string, clientset *kubernetes.Clientset
return nil
}

func ensureOperatorServiceAccount(namespace string, clientset *kubernetes.Clientset) error {
_, err := clientset.CoreV1().ServiceAccounts(namespace).Get("kotsadm-operator-serviceaccount", metav1.GetOptions{})
if err != nil {
if !kuberneteserrors.IsNotFound(err) {
return errors.Wrap(err, "failed to get serviceaccouont")
}

_, err := clientset.CoreV1().ServiceAccounts(namespace).Create(operatorServiceAccount(namespace))
if err != nil {
return errors.Wrap(err, "failed to create serviceaccount")
}
}

return nil
}

func ensureOperatorDeployment(deployOptions DeployOptions, clientset *kubernetes.Clientset) error {
_, err := clientset.AppsV1().Deployments(deployOptions.Namespace).Get("kotsadm-operator", metav1.GetOptions{})
if err != nil {
Expand Down
20 changes: 18 additions & 2 deletions pkg/kotsadm/operator_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func operatorRoleBinding(namespace string) *rbacv1.RoleBinding {
Subjects: []rbacv1.Subject{
{
Kind: "ServiceAccount",
Name: "default",
Name: "kotsadm-operator",
Namespace: namespace,
},
},
Expand All @@ -58,6 +58,21 @@ func operatorRoleBinding(namespace string) *rbacv1.RoleBinding {
return roleBinding
}

func operatorServiceAccount(namespace string) *corev1.ServiceAccount {
serviceAccount := &corev1.ServiceAccount{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "ServiceAccount",
},
ObjectMeta: metav1.ObjectMeta{
Name: "kotsadm-operator",
Namespace: namespace,
},
}

return serviceAccount
}

func operatorDeployment(namespace string) *appsv1.Deployment {
deployment := &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Expand All @@ -81,7 +96,8 @@ func operatorDeployment(namespace string) *appsv1.Deployment {
},
},
Spec: corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyAlways,
ServiceAccountName: "kotsadm-operator",
RestartPolicy: corev1.RestartPolicyAlways,
Containers: []corev1.Container{
{
Image: "kotsadm/kotsadm-operator:alpha",
Expand Down

0 comments on commit e46e719

Please sign in to comment.