瀏覽代碼

api: Add Templating parameter to SecretSpec and ConfigSpec

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
Aaron Lehmann 8 年之前
父節點
當前提交
c5df7235f6
共有 5 個文件被更改,包括 68 次插入2 次删除
  1. 24 0
      api/swagger.yaml
  2. 4 0
      api/types/swarm/config.go
  3. 4 0
      api/types/swarm/secret.go
  4. 18 1
      daemon/cluster/convert/config.go
  5. 18 1
      daemon/cluster/convert/secret.go

+ 24 - 0
api/swagger.yaml

@@ -3338,6 +3338,18 @@ definitions:
       Driver:
       Driver:
         description: "Name of the secrets driver used to fetch the secret's value from an external secret store"
         description: "Name of the secrets driver used to fetch the secret's value from an external secret store"
         $ref: "#/definitions/Driver"
         $ref: "#/definitions/Driver"
+      Templating:
+        description: "Templating driver, if applicable"
+        type: "object"
+        properties:
+          Name:
+            description: "Name of the templating driver (i.e. 'golang')"
+            type: "string"
+          Options:
+            description: "key/value map of driver specific options."
+            type: "object"
+            additionalProperties:
+              type: "string"
 
 
   Secret:
   Secret:
     type: "object"
     type: "object"
@@ -3374,6 +3386,18 @@ definitions:
           Base64-url-safe-encoded ([RFC 4648](https://tools.ietf.org/html/rfc4648#section-3.2))
           Base64-url-safe-encoded ([RFC 4648](https://tools.ietf.org/html/rfc4648#section-3.2))
           config data.
           config data.
         type: "string"
         type: "string"
+      Templating:
+        description: "Templating driver, if applicable"
+        type: "object"
+        properties:
+          Name:
+            description: "Name of the templating driver (i.e. 'golang')"
+            type: "string"
+          Options:
+            description: "key/value map of driver specific options."
+            type: "object"
+            additionalProperties:
+              type: "string"
 
 
   Config:
   Config:
     type: "object"
     type: "object"

+ 4 - 0
api/types/swarm/config.go

@@ -13,6 +13,10 @@ type Config struct {
 type ConfigSpec struct {
 type ConfigSpec struct {
 	Annotations
 	Annotations
 	Data []byte `json:",omitempty"`
 	Data []byte `json:",omitempty"`
+
+	// Templating controls whether and how to evaluate the config payload as
+	// a template. If it is not set, no templating is used.
+	Templating *Driver `json:",omitempty"`
 }
 }
 
 
 // ConfigReferenceFileTarget is a file target in a config reference
 // ConfigReferenceFileTarget is a file target in a config reference

+ 4 - 0
api/types/swarm/secret.go

@@ -14,6 +14,10 @@ type SecretSpec struct {
 	Annotations
 	Annotations
 	Data   []byte  `json:",omitempty"`
 	Data   []byte  `json:",omitempty"`
 	Driver *Driver `json:",omitempty"` // name of the secrets driver used to fetch the secret's value from an external secret store
 	Driver *Driver `json:",omitempty"` // name of the secrets driver used to fetch the secret's value from an external secret store
+
+	// Templating controls whether and how to evaluate the secret payload as
+	// a template. If it is not set, no templating is used.
+	Templating *Driver `json:",omitempty"`
 }
 }
 
 
 // SecretReferenceFileTarget is a file target in a secret reference
 // SecretReferenceFileTarget is a file target in a secret reference

+ 18 - 1
daemon/cluster/convert/config.go

@@ -2,6 +2,7 @@ package convert // import "github.com/docker/docker/daemon/cluster/convert"
 
 
 import (
 import (
 	swarmtypes "github.com/docker/docker/api/types/swarm"
 	swarmtypes "github.com/docker/docker/api/types/swarm"
+	types "github.com/docker/docker/api/types/swarm"
 	swarmapi "github.com/docker/swarmkit/api"
 	swarmapi "github.com/docker/swarmkit/api"
 	gogotypes "github.com/gogo/protobuf/types"
 	gogotypes "github.com/gogo/protobuf/types"
 )
 )
@@ -21,18 +22,34 @@ func ConfigFromGRPC(s *swarmapi.Config) swarmtypes.Config {
 	config.CreatedAt, _ = gogotypes.TimestampFromProto(s.Meta.CreatedAt)
 	config.CreatedAt, _ = gogotypes.TimestampFromProto(s.Meta.CreatedAt)
 	config.UpdatedAt, _ = gogotypes.TimestampFromProto(s.Meta.UpdatedAt)
 	config.UpdatedAt, _ = gogotypes.TimestampFromProto(s.Meta.UpdatedAt)
 
 
+	if s.Spec.Templating != nil {
+		config.Spec.Templating = &types.Driver{
+			Name:    s.Spec.Templating.Name,
+			Options: s.Spec.Templating.Options,
+		}
+	}
+
 	return config
 	return config
 }
 }
 
 
 // ConfigSpecToGRPC converts Config to a grpc Config.
 // ConfigSpecToGRPC converts Config to a grpc Config.
 func ConfigSpecToGRPC(s swarmtypes.ConfigSpec) swarmapi.ConfigSpec {
 func ConfigSpecToGRPC(s swarmtypes.ConfigSpec) swarmapi.ConfigSpec {
-	return swarmapi.ConfigSpec{
+	spec := swarmapi.ConfigSpec{
 		Annotations: swarmapi.Annotations{
 		Annotations: swarmapi.Annotations{
 			Name:   s.Name,
 			Name:   s.Name,
 			Labels: s.Labels,
 			Labels: s.Labels,
 		},
 		},
 		Data: s.Data,
 		Data: s.Data,
 	}
 	}
+
+	if s.Templating != nil {
+		spec.Templating = &swarmapi.Driver{
+			Name:    s.Templating.Name,
+			Options: s.Templating.Options,
+		}
+	}
+
+	return spec
 }
 }
 
 
 // ConfigReferencesFromGRPC converts a slice of grpc ConfigReference to ConfigReference
 // ConfigReferencesFromGRPC converts a slice of grpc ConfigReference to ConfigReference

+ 18 - 1
daemon/cluster/convert/secret.go

@@ -2,6 +2,7 @@ package convert // import "github.com/docker/docker/daemon/cluster/convert"
 
 
 import (
 import (
 	swarmtypes "github.com/docker/docker/api/types/swarm"
 	swarmtypes "github.com/docker/docker/api/types/swarm"
+	types "github.com/docker/docker/api/types/swarm"
 	swarmapi "github.com/docker/swarmkit/api"
 	swarmapi "github.com/docker/swarmkit/api"
 	gogotypes "github.com/gogo/protobuf/types"
 	gogotypes "github.com/gogo/protobuf/types"
 )
 )
@@ -22,12 +23,19 @@ func SecretFromGRPC(s *swarmapi.Secret) swarmtypes.Secret {
 	secret.CreatedAt, _ = gogotypes.TimestampFromProto(s.Meta.CreatedAt)
 	secret.CreatedAt, _ = gogotypes.TimestampFromProto(s.Meta.CreatedAt)
 	secret.UpdatedAt, _ = gogotypes.TimestampFromProto(s.Meta.UpdatedAt)
 	secret.UpdatedAt, _ = gogotypes.TimestampFromProto(s.Meta.UpdatedAt)
 
 
+	if s.Spec.Templating != nil {
+		secret.Spec.Templating = &types.Driver{
+			Name:    s.Spec.Templating.Name,
+			Options: s.Spec.Templating.Options,
+		}
+	}
+
 	return secret
 	return secret
 }
 }
 
 
 // SecretSpecToGRPC converts Secret to a grpc Secret.
 // SecretSpecToGRPC converts Secret to a grpc Secret.
 func SecretSpecToGRPC(s swarmtypes.SecretSpec) swarmapi.SecretSpec {
 func SecretSpecToGRPC(s swarmtypes.SecretSpec) swarmapi.SecretSpec {
-	return swarmapi.SecretSpec{
+	spec := swarmapi.SecretSpec{
 		Annotations: swarmapi.Annotations{
 		Annotations: swarmapi.Annotations{
 			Name:   s.Name,
 			Name:   s.Name,
 			Labels: s.Labels,
 			Labels: s.Labels,
@@ -35,6 +43,15 @@ func SecretSpecToGRPC(s swarmtypes.SecretSpec) swarmapi.SecretSpec {
 		Data:   s.Data,
 		Data:   s.Data,
 		Driver: driverToGRPC(s.Driver),
 		Driver: driverToGRPC(s.Driver),
 	}
 	}
+
+	if s.Templating != nil {
+		spec.Templating = &swarmapi.Driver{
+			Name:    s.Templating.Name,
+			Options: s.Templating.Options,
+		}
+	}
+
+	return spec
 }
 }
 
 
 // SecretReferencesFromGRPC converts a slice of grpc SecretReference to SecretReference
 // SecretReferencesFromGRPC converts a slice of grpc SecretReference to SecretReference