Refactor into RenderAgent and ApplyAgent
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package render
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
@@ -9,7 +8,6 @@ import (
|
||||
rbacv1 "k8s.io/api/rbac/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/serializer/json"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
|
||||
monov1alpha1 "example.com/monok8s/pkg/apis/monok8s/v1alpha1"
|
||||
@@ -17,9 +15,10 @@ import (
|
||||
)
|
||||
|
||||
type ControllerConf struct {
|
||||
Namespace string
|
||||
Image string
|
||||
Labels map[string]string
|
||||
Namespace string
|
||||
Image string
|
||||
ImagePullSecrets []string
|
||||
Labels map[string]string
|
||||
}
|
||||
|
||||
func RenderControllerDeployments(conf ControllerConf) (string, error) {
|
||||
@@ -41,27 +40,7 @@ func RenderControllerDeployments(conf ControllerConf) (string, error) {
|
||||
buildControllerDeployment(conf),
|
||||
}
|
||||
|
||||
s := runtime.NewScheme()
|
||||
_ = corev1.AddToScheme(s)
|
||||
_ = rbacv1.AddToScheme(s)
|
||||
_ = appsv1.AddToScheme(s)
|
||||
|
||||
serializer := json.NewYAMLSerializer(json.DefaultMetaFactory, s, s)
|
||||
|
||||
var buf bytes.Buffer
|
||||
|
||||
for i, obj := range objs {
|
||||
if i > 0 {
|
||||
if _, err := fmt.Fprintln(&buf, "---"); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
if err := serializer.Encode(obj, &buf); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
return buf.String(), nil
|
||||
return renderObjects(objs)
|
||||
}
|
||||
|
||||
func buildControllerServiceAccount(conf ControllerConf) *corev1.ServiceAccount {
|
||||
@@ -191,6 +170,7 @@ func buildControllerDeployment(conf ControllerConf) *appsv1.Deployment {
|
||||
},
|
||||
Spec: corev1.PodSpec{
|
||||
ServiceAccountName: monov1alpha1.ControllerName,
|
||||
ImagePullSecrets: imagePullSecrets(conf.ImagePullSecrets),
|
||||
Containers: []corev1.Container{
|
||||
{
|
||||
Name: "controller",
|
||||
|
||||
Reference in New Issue
Block a user