diff --git a/k8s/cmd/commands/deploy/deploy_vineyard_deployment.go b/k8s/cmd/commands/deploy/deploy_vineyard_deployment.go index 948a1772..a05a43df 100644 --- a/k8s/cmd/commands/deploy/deploy_vineyard_deployment.go +++ b/k8s/cmd/commands/deploy/deploy_vineyard_deployment.go @@ -105,9 +105,9 @@ func GetVineyardDeploymentObjectsFromTemplate() ([]*unstructured.Unstructured, e return etcdConfig }, "toYaml": func(v interface{}) string { - bs, error := yaml.Marshal(v) - if error != nil { - log.Error(error, "failed to marshal object %v to yaml", v) + bs, err := yaml.Marshal(v) + if err != nil { + log.Error(err, "failed to marshal object %v to yaml", v) return "" } return string(bs) diff --git a/k8s/cmd/commands/deploy/deploy_vineyard_deployment_test.go b/k8s/cmd/commands/deploy/deploy_vineyard_deployment_test.go index 571f2742..7d737f0f 100644 --- a/k8s/cmd/commands/deploy/deploy_vineyard_deployment_test.go +++ b/k8s/cmd/commands/deploy/deploy_vineyard_deployment_test.go @@ -403,6 +403,7 @@ func TestGetVineyardDeploymentObjectsFromTemplate_third(t *testing.T) { "limits": nil, "requests": nil, }, + "securityContext": map[string]interface{}{}, "command": []interface{}{ "/bin/bash", "-c", diff --git a/k8s/cmd/commands/inject/inject.go b/k8s/cmd/commands/inject/inject.go index 14ba077c..03f79f97 100644 --- a/k8s/cmd/commands/inject/inject.go +++ b/k8s/cmd/commands/inject/inject.go @@ -240,6 +240,7 @@ var ( resources: limits: null requests: null + securityContext: {} volumeMounts: - mountPath: /var/run name: vineyard-socket @@ -487,9 +488,9 @@ func GetManifestFromTemplate(workload string) (OutputManifests, error) { return etcdConfig }, "toYaml": func(v interface{}) string { - bs, error := yaml.Marshal(v) - if error != nil { - log.Error(error, "failed to marshal object %v to yaml", v) + bs, err := yaml.Marshal(v) + if err != nil { + log.Error(err, "failed to marshal object %v to yaml", v) return "" } return string(bs) diff --git a/k8s/cmd/commands/inject/inject_test.go b/k8s/cmd/commands/inject/inject_test.go index 08762204..b7b56d7d 100644 --- a/k8s/cmd/commands/inject/inject_test.go +++ b/k8s/cmd/commands/inject/inject_test.go @@ -246,6 +246,7 @@ spec: resources: limits: null requests: null + securityContext: {} volumeMounts: - mountPath: /var/run name: vineyard-socket @@ -303,6 +304,7 @@ spec: resources: limits: null requests: null + securityContext: {} volumeMounts: - mountPath: /var/run name: vineyard-socket diff --git a/k8s/cmd/commands/util/template_test.go b/k8s/cmd/commands/util/template_test.go index b0800e28..517e043a 100644 --- a/k8s/cmd/commands/util/template_test.go +++ b/k8s/cmd/commands/util/template_test.go @@ -18,6 +18,7 @@ package util import ( _ "embed" "reflect" + "strings" "testing" "time" @@ -25,6 +26,7 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "sigs.k8s.io/yaml" "github.com/v6d-io/v6d/k8s/apis/k8s/v1alpha1" "github.com/v6d-io/v6d/k8s/cmd/commands/flags" @@ -57,6 +59,18 @@ func Test_RenderManifestAsObj(t *testing.T) { "getEtcdConfig": func() k8s.EtcdConfig { return etcdConfig }, + "toYaml": func(v interface{}) string { + bs, err := yaml.Marshal(v) + if err != nil { + t.Error(err, "failed to marshal object %v to yaml", v) + return "" + } + return string(bs) + }, + "indent": func(spaces int, s string) string { + prefix := strings.Repeat(" ", spaces) + return prefix + strings.Replace(s, "\n", "\n"+prefix, -1) + }, }, }, want: &unstructured.Unstructured{ @@ -152,6 +166,18 @@ func TestBuildObjsFromEtcdManifests(t *testing.T) { "getEtcdConfig": func() k8s.EtcdConfig { return etcdConfig }, + "toYaml": func(v interface{}) string { + bs, err := yaml.Marshal(v) + if err != nil { + t.Error(err, "failed to marshal object %v to yaml", v) + return "" + } + return string(bs) + }, + "indent": func(spaces int, s string) string { + prefix := strings.Repeat(" ", spaces) + return prefix + strings.Replace(s, "\n", "\n"+prefix, -1) + }, } vineyardd := value name := vineyardd.Name @@ -215,6 +241,18 @@ func TestBuildObjsFromVineyarddManifests(t *testing.T) { "getEtcdConfig": func() k8s.EtcdConfig { return etcdConfig }, + "toYaml": func(v interface{}) string { + bs, err := yaml.Marshal(v) + if err != nil { + t.Error(err, "failed to marshal object %v to yaml", v) + return "" + } + return string(bs) + }, + "indent": func(spaces int, s string) string { + prefix := strings.Repeat(" ", spaces) + return prefix + strings.Replace(s, "\n", "\n"+prefix, -1) + }, } objs, err := BuildObjsFromVineyarddManifests(files, value, tmplFunc) @@ -271,6 +309,18 @@ func TestBuildObjsFromManifests(t *testing.T) { "getBackupConfig": func() k8s.BackupConfig { return backupCfg }, + "toYaml": func(v interface{}) string { + bs, err := yaml.Marshal(v) + if err != nil { + t.Error(err, "failed to marshal object %v to yaml", v) + return "" + } + return string(bs) + }, + "indent": func(spaces int, s string) string { + prefix := strings.Repeat(" ", spaces) + return prefix + strings.Replace(s, "\n", "\n"+prefix, -1) + }, } objs, err := BuildObjsFromManifests(templateName, backup, tmplFunc) diff --git a/k8s/controllers/k8s/sidecar_controller.go b/k8s/controllers/k8s/sidecar_controller.go index c2035a38..0333d308 100644 --- a/k8s/controllers/k8s/sidecar_controller.go +++ b/k8s/controllers/k8s/sidecar_controller.go @@ -70,9 +70,9 @@ func (r *SidecarReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct TmplFunc: map[string]interface{}{ "getEtcdConfig": nil, "toYaml": func(v interface{}) string { - bs, error := yaml.Marshal(v) - if error != nil { - logger.Error(error, "failed to marshal object %v to yaml", v) + bs, err := yaml.Marshal(v) + if err != nil { + logger.Error(err, "failed to marshal object %v to yaml", v) return "" } return string(bs) diff --git a/k8s/controllers/k8s/vineyardd_controller.go b/k8s/controllers/k8s/vineyardd_controller.go index 7abca9d7..bb935662 100644 --- a/k8s/controllers/k8s/vineyardd_controller.go +++ b/k8s/controllers/k8s/vineyardd_controller.go @@ -91,9 +91,9 @@ func (r *VineyarddReconciler) Reconcile( return q.String() }, "toYaml": func(v interface{}) string { - bs, error := yaml.Marshal(v) - if error != nil { - logger.Error(error, "failed to marshal object %v to yaml", v) + bs, err := yaml.Marshal(v) + if err != nil { + logger.Error(err, "failed to marshal object %v to yaml", v) return "" } return string(bs) diff --git a/python/vineyard/core/client.py b/python/vineyard/core/client.py index 86b035c7..10a4ffb3 100644 --- a/python/vineyard/core/client.py +++ b/python/vineyard/core/client.py @@ -530,7 +530,7 @@ def _fetch_object(self, object_id: ObjectID) -> Object: meta = self.get_meta(object_id) if self.has_ipc_client(): - if meta.instance_id == self._ipc_client.instance_id: + if meta.instance_id == self._ipc_client.instance_id or meta.isglobal: return self._ipc_client.get_object(object_id, fetch=False) else: warnings.warn(