func validateTask(taskSpec api.TaskSpec) error { if err := validateResourceRequirements(taskSpec.Resources); err != nil { return err } if err := validateRestartPolicy(taskSpec.Restart); err != nil { return err } if taskSpec.GetRuntime() == nil { return grpc.Errorf(codes.InvalidArgument, "TaskSpec: missing runtime") } _, ok := taskSpec.GetRuntime().(*api.TaskSpec_Container) if !ok { return grpc.Errorf(codes.Unimplemented, "RuntimeSpec: unimplemented runtime in service spec") } container := taskSpec.GetContainer() if container == nil { return grpc.Errorf(codes.InvalidArgument, "ContainerSpec: missing in service spec") } if container.Image == "" { return grpc.Errorf(codes.InvalidArgument, "ContainerSpec: image reference must be provided") } if _, _, err := reference.Parse(container.Image); err != nil { return grpc.Errorf(codes.InvalidArgument, "ContainerSpec: %q is not a valid repository/tag", container.Image) } return nil }
func validateTask(taskSpec api.TaskSpec) error { if err := validateResourceRequirements(taskSpec.Resources); err != nil { return err } if err := validateRestartPolicy(taskSpec.Restart); err != nil { return err } if err := validatePlacement(taskSpec.Placement); err != nil { return err } if taskSpec.GetRuntime() == nil { return grpc.Errorf(codes.InvalidArgument, "TaskSpec: missing runtime") } _, ok := taskSpec.GetRuntime().(*api.TaskSpec_Container) if !ok { return grpc.Errorf(codes.Unimplemented, "RuntimeSpec: unimplemented runtime in service spec") } if err := validateContainerSpec(taskSpec.GetContainer()); err != nil { return err } return nil }
func validateTask(taskSpec api.TaskSpec) error { if err := validateResourceRequirements(taskSpec.Resources); err != nil { return err } if err := validateRestartPolicy(taskSpec.Restart); err != nil { return err } if err := validatePlacement(taskSpec.Placement); err != nil { return err } if taskSpec.GetRuntime() == nil { return grpc.Errorf(codes.InvalidArgument, "TaskSpec: missing runtime") } _, ok := taskSpec.GetRuntime().(*api.TaskSpec_Container) if !ok { return grpc.Errorf(codes.Unimplemented, "RuntimeSpec: unimplemented runtime in service spec") } container := taskSpec.GetContainer() if container == nil { return grpc.Errorf(codes.InvalidArgument, "ContainerSpec: missing in service spec") } if container.Image == "" { return grpc.Errorf(codes.InvalidArgument, "ContainerSpec: image reference must be provided") } if _, err := reference.ParseNamed(container.Image); err != nil { return grpc.Errorf(codes.InvalidArgument, "ContainerSpec: %q is not a valid repository/tag", container.Image) } mountMap := make(map[string]bool) for _, mount := range container.Mounts { if _, exists := mountMap[mount.Target]; exists { return grpc.Errorf(codes.InvalidArgument, "ContainerSpec: duplicate mount point: %s", mount.Target) } mountMap[mount.Target] = true } return nil }