我在GKE上的Kubernetes中有以下复制控制器:
apiVersion: v1
kind: ReplicationController
metadata:
name: myapp
labels:
app: myapp
spec:
replicas: 2
selector:
app: myapp
deployment: initial
template:
metadata:
labels:
app: myapp
deployment: initial
spec:
containers:
- name: myapp
image: myregistry.com/myapp:5c3dda6b
ports:
- containerPort: 80
imagePullPolicy: Always
imagePullSecrets:
- name: myregistry.com-registry-key
Run Code Online (Sandbox Code Playgroud)
现在,如果我说
kubectl rolling-update myapp --image=us.gcr.io/project-107012/myapp:5c3dda6b
Run Code Online (Sandbox Code Playgroud)
执行滚动更新,但没有重新拉动.为什么?
"kubectl logs"向我展示了一个Kubernetes容器的stderr/stdout.如何获取一组pod的聚合stderr/stdout,最好是由某个复制控制器创建的那些?
我们的Django部署每晚都会检查哪些活动用户仍然可以在LDAP目录中找到.如果找不到它们,我们将它们设置为不活动状态.如果他们下次尝试登录,则会失败.这是我们的代码,它执行此操作:
def synchronize_users_with_ad(sender, **kwargs):
"""Signal listener which synchronises all active users without a usable
password against the LDAP directory. If a user cannot be
found anymore, he or she is set to “inactive”.
"""
ldap_connection = LDAPConnection()
for user in User.objects.filter(is_active=True):
if not user.has_usable_password() and not existing_in_ldap(user):
user.is_active = user.is_staff = user.is_superuser = False
user.save()
user.groups.clear()
user.user_permissions.clear()
maintain.connect(synchronize_users_with_ad)
Run Code Online (Sandbox Code Playgroud)
但如果他们仍然登录,则此会话仍然有效.我们怎样才能立即使它们无效?会话中间件的所有设置都是默认值.
我想将我的GKE集群中的核心数量保持在3以下.如果K8s复制控制器和pod的CPU限制从100m减少到最多50m,这就变得更加可行.否则,K8s吊舱单独占据一个核心的70%.
我决定不增加节点的CPU功率.在我看来,这在概念上是错误的,因为CPU限制被定义为在核心中测量.相反,我做了以下事情:
这是很多工作,可能很脆弱.即将推出的K8版本中的任何进一步更改或GKE配置的更改都可能会破坏它.
那么,有更好的方法吗?
如何在http://kubernetes.io/v1.0/生成Kubernetes文档的PDF版本?或者,我如何获得其文档的打印输出?
我使用Django 1.7迁移,特别是想要用初始数据填充新创建的数据库.因此,我使用数据迁移.它看起来像这样:
def populate_with_initial_data(apps, schema_editor):
User = apps.get_model("auth", "User")
new_user = User.objects.create(username="nobody")
class Migration(migrations.Migration):
...
operations = [
migrations.RunPython(populate_with_initial_data),
]
Run Code Online (Sandbox Code Playgroud)
同时,我希望UserDetails每个新用户都有一个模型实例:
@receiver(signals.post_save, sender=django.contrib.auth.models.User)
def add_user_details(sender, instance, created, **kwargs):
if created:
my_app.UserDetails.objects.create(user=instance)
Run Code Online (Sandbox Code Playgroud)
但是:此信号仅在迁移之外有效.原因是,apps.get_model("auth", "User")与django.contrib.auth.models.User没有发送信号的情况完全不同.如果我尝试手动执行此操作,则会失败:
signals.post_save.send(django.contrib.auth.models.User, instance=julia, created=True)
Run Code Online (Sandbox Code Playgroud)
这失败了,因为那时,信号处理程序尝试使用O2O 创建一个新的 UserDetails指向历史记录 User:
ValueError: Cannot assign "<User: User object>": "UserDetails.user" must be a "User" instance.
Run Code Online (Sandbox Code Playgroud)
游民.
好的,我可以直接调用信号处理程序.但是我必须UserDetails在关键字参数(以及它需要的其他历史类)中传递历史类.此外,UserDetails具有此数据迁移的应用程序不是具有此数据迁移的应用程序,因此这将是一个丑陋的依赖性,很容易破坏,例如,如果UserDetails应用程序被删除INSTALLED_APPS.
那么,这只是一个当前的限制,我必须解决丑陋的代码和FixMe评论?或者有没有办法从数据迁移中发送信号?
您可以在Python文档字符串中指定参数类型,如下所示:
def __init__(self, canvas, segments):
"""Class constructor.
:param canvas: the PDF canvas object
:param segment: The layer segments to be drawn.
:type canvas: `canvas.Canvas`
:type segments: list of str
"""
...
Run Code Online (Sandbox Code Playgroud)
使用Sphinx的autodoc功能,可以生成参数列表,并且每个参数都可以使用其类型进行正确标记.
但是如何使用实例属性执行此操作?像这样的东西
class Path(object):
"""
:ivar edge_indices: The indices within `textured_points` of the places.
:type edge_indices: list of int
"""
Run Code Online (Sandbox Code Playgroud)
不起作用.人们可以在单词之后加上单词类型,:ivar但在这里,它由三个单词组成,因此不起作用.
在组织模式中,我已经定义了一个图形+标题,如下所示:
#+CAPTION: My great figure
#+LABEL: fig:myfigure
[[myfigure.png]]
Run Code Online (Sandbox Code Playgroud)
我怎么写"看图[myfigure]"?我发现了以下语法:
See figure \ref{fig:myfigure}
Run Code Online (Sandbox Code Playgroud)
但这在源文件中看起来很难看.特别是,你不能用它来实际跳转到图中.
如果我使用
git rebase --interactive
Run Code Online (Sandbox Code Playgroud)
我可以说,设置一行"编辑"
git reset HEAD^
git add -p
git commit -m "First part."
git commit -a -m "Second part."
Run Code Online (Sandbox Code Playgroud)
换句话说,我拆分了一个提交.不幸的是,这会为两个新提交创建当前时间戳,这使得历史看起来很有趣.有没有办法让新提交共享它分裂的时间戳?
我尝试合并两个repos,产生一个平坦的(也就是交错的)历史.我按照"历史记录重写:"下的/sf/answers/1038775741/这样做.
要合并的两个分支是"master"和"src/master".然后,我写道:
$ git checkout --orphan new-master
$ git cherry-pick 9d325d6d 3f4c52ba
error: a cherry-pick or revert is already in progress
hint: try "git cherry-pick (--continue | --quit | --abort)"
fatal: cherry-pick failed
$ git cherry-pick 9d325d6d && git cherry-pick 3f4c52ba
[new-master 10f0277] Initial revision.
7 files changed, 194 insertions(+)
create mode 100644 __init__.py
create mode 100644 manage.py
create mode 100644 samples/__init__.py
create mode 100644 samples/models.py
create mode 100644 samples/views.py
create mode 100644 settings.py
create mode 100644 urls.py …Run Code Online (Sandbox Code Playgroud) 考虑以下Go程序:
package main
func main() {
var buffer [100000000]float64
var i int
for i = range buffer {
buffer[i] = float64(i)
}
}
Run Code Online (Sandbox Code Playgroud)
使用"go run test1.go",它可以工作.(除非你的内存太少.)
现在,我简单地扩展这个程序:
package main
func main() {
var buffer [100000000]float64
var i int
var value float64
for i, value = range buffer {
value = value
buffer[i] = float64(i)
}
}
Run Code Online (Sandbox Code Playgroud)
"go run test2.go"产量:
runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow
runtime stack:
runtime.throw(0x473350, 0xe)
/usr/local/go/src/runtime/panic.go:527 +0x90
runtime.newstack()
/usr/local/go/src/runtime/stack1.go:794 +0xb17
runtime.morestack()
/usr/local/go/src/runtime/asm_amd64.s:330 …Run Code Online (Sandbox Code Playgroud) str.partition我通过三种方式在代码中使用 Python :
before, __, after = string.partition(sep)
before = string.partition(sep)[0]
after = string.partition(sep)[2]
Run Code Online (Sandbox Code Playgroud)
虽然我str.partition经常使用,但我一直想知道为什么它返回分隔符。第一行肯定会受益于它不返回分隔符,并且在我看来,第三行也会变得更加直观。
虽然我承认可以用以下命令重新构建字符串
"".join(string.partition(sep))
Run Code Online (Sandbox Code Playgroud)
我没有看到任何用例。
那么,在返回的元组中包含分隔符的理由是什么?