清理git submodule

当我们本地对git的submodule目录下的文件做了改动时,会发现不论是用git checkout . 还是 git clean -df都无法丢弃修改。使用git status命令查看工作树的状态时会有如下 报错信息git submodule modified content 错误 以hugo为例,当使用hugo server本地预览博客文章时, hugo会修改主题目录的内容。从而出现 git submodule modified content的问题。 1 2 3 4 5 6 7 8 9 10 11 12 ❯ git status 位于分支 main 您的分支领先 'origin/main' 共 1 个提交。 (使用 "git push" 来发布您的本地提交) 尚未暂存以备提交的变更: (使用 "git add <文件>..." 更新要提交的内容) (使用 "git restore <文件>..." 丢弃工作区的改动) (提交或丢弃子模组中未跟踪或修改的内容) 修改: themes/stack (修改的内容) 修改尚未加入提交(使用 "git add" 和/或 "git commit -a") 这个问题挺常见的,Google后使用下面两条命令即可清理submodule: ...

November 16, 2021 · datewu

替换k8s所有证书

客户需要把kubernetes apiserver/etcd/kubelet/kubectl 等所有的证书有效期修改为100年。 很明显这是一个不合理的需求,不过客户说什么就是什么。 于是经几天的调试有了下面的这个 Makefile批量生成所有(FILES变量)的证书。 如果对makefile的语法不熟悉,可以看看Makefile简介 makefile 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 FILES = ca.crt ca.key sa.key sa.pub front-proxy-ca.crt front-proxy-ca.key etcd_ca.crt etcd_ca.key CONFS = admin.conf controller-manager.conf kubelet.conf scheduler.conf SELFS = kubelet.crt.self kubelet.crt.key #KEYs = ca.key front-proxy-ca.key etcd_ca.key sa.key #CAs = ca.crt front-proxy-ca.crt etcd_ca.crt #PUBs = sa.pub ## kubernetes will sign certificate ## automatically, so below ## csr/cert is for test purpose #CSR = apiserver.csr apiserver-kubelet-client.csr CERT_KEYS = apiserver.key apiserver-kubelet-client.key front-proxy-client.key CERTS = apiserver.cert apiserver-kubelet-client.cert front-proxy-client.cert # openssl genrsa -des3 -out rootCA.key 4096 CMD_CREATE_PRIVATE_KEY = openssl genrsa -out $@ 2048 CMD_CREATE_PUBLIC_KEY = openssl rsa -in $< -pubout -out $@ # openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.crt CMD_CREATE_CA = openssl req -x509 -new -nodes -key $< -sha256 -days 36500 -out $@ -subj '/CN=kubernetes' # openssl req -new -key mydomain.com.key -out mydomain.com.csr CMD_CREATE_CSR = openssl req -new -key $< -out $@ -config $(word 2,$^) # openssl x509 -req -in mydomain.com.csr -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out mydomain.com.crt -days 500 -sha256 CMD_SIGN_CERT = openssl x509 -req -in $< -CA $(word 2,$^) -CAkey $(word 3,$^) -CAcreateserial -out $@ -days 36500 -sha256 -extfile $(word 4,$^) -extensions my_extensions # generata self sign certificate CMD_CREATE_CERT = openssl req -x509 -new -nodes -key $< -sha256 -days 36500 -out $@ -subj '/CN=nodeXXX@timestamp1531732165' CMD_MSG = @echo generating $@ ... MASTER_IP := 192.168.1.200 ## REMEMBER CHANGE ME .PHONY: all clean check self_sign rename all: ${FILES} ${CONFS} ${CERT_KEYS} ${CERTS} clean: -rm ${FILES} ${CONFS} ${CERT_KEYS} ${CERTS} self_sign: ${SELFS} check: for f in *.cert *.crt; do echo $$f; openssl x509 -noout -dates -in $$f; echo '==='; done rename: for f in *.cert; do echo $$f; mv $$f $${f%.*}.crt; echo '====='; done %.key: ${CMD_MSG} ${CMD_CREATE_PRIVATE_KEY} %.pub: %.key ${CMD_MSG} ${CMD_CREATE_PUBLIC_KEY} %.self: %.key ${CMD_MSG} ${CMD_CREATE_CERT} %.crt: %.key ${CMD_MSG} ${CMD_CREATE_CA} %.csr: %.key %.csr.cnf ${CMD_MSG} ${CMD_CREATE_CSR} %.cert: %.csr ca.crt ca.key %.csr.cnf #%.cert: %.csr front-proxy-ca.crt front-proxy-ca.key %.csr.cnf ${CMD_MSG} ${CMD_SIGN_CERT} %.conf: %.cert %-conf.sh sh $(word 2,$^) ${MASTER_IP} 上面的Makefile还需要对应的csr和 conffiles。 ...

August 10, 2018 · datewu

Makefile简介

网络上关于 makefile的教程有很多,由于我日常不是写c/c++的, 不常使用makefile,需要用的时候总是要重新Google搜索makefile的语法。 索性整理出来这篇 makefile 教程,备忘。 教程 Makefile简易教程: 基本语法 1 2 3 4 target: dependency1 dependency2 ... [TAB] action1 [TAB] action2 ... 下面的makefile摘抄自GNU Make in Detail for Beginners,这篇入门文章把makefile的语法写的非常透彻。 推荐大家多读几遍 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 ##### makefile for compile C programs # Compiler to use CC = gcc # -g for debug, -O2 for optimise and -Wall additonal messages OPTIONS = -O2 -g -Wall # Directory for header file INCLUDES = -I . # List of objects to be build OBJS = main.o module.o .PHONY: all list clean all: ${OBJS} @echo "Building..." # print "Building..." message ${CC} ${OPTIONS} ${INCLUDES} ${OBJS} -o main_bin %.o: %.c # '%' pattern wildcard matching ${CC} ${OPTIONS} ${INCLUDES} -c %.c list: @echo $(shell ls) # print output of command `ls` clean: @echo Cleaning up... -rm -rf *.0 # '-' prefix for ignoring errors and continue execution -rm main_bin #### makefile for img manage FILES = $(shell find imgs -type f -iname "*.jpg" | sed 's/imgs/thumb/g') CONVERT_CMD = convert -resize "100x100" $< $@ MSG = "\nUpdating thumbnail" $@ all_thumb: ${FILES} thumb/%.jpg: imgs/%.jpg ${MSG} ${CONVERT_CMD} thumb/%.JPG: imgs/%.JPG ${MSG} ${CONVERT_CMD} clean_all: @echo Cleaning up files... -rm -rf thumb/*.{jpg,JPG} 变量 赋值 Simple assignment (:=) We can assign values (RHS) to variables (LHS) with this operator, for example: CC := gcc. With simple assignment (:=), the value is expanded and stored to all occurrences in the Makefile when its first definition is found. ...

July 27, 2018 · datewu