GithubHelp home page GithubHelp logo

advanced-kubernetes-operator's Introduction

《Kubernetes Operator开发进阶》示例代码

《Kubernetes Operator开发进阶》将在2022年12月由机械工业出版社出版。

本仓库包含书中的3个演示项目代码:

  • 第二章 Application Operator Demo
  • 第四章 client-go 使用示例
  • 第七章 Application Operator

advanced-kubernetes-operator's People

Contributors

daniel-hutao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

advanced-kubernetes-operator's Issues

4.2.1 in-cluster-configuration Dockerfile problem

我的集群是1.23.0版本

使用作者的Dockerfile发现了一些问题:
FROM busybox
COPY ./in-cluster /in-cluster
USER 65532:65532
ENTRYPOINT /in-cluster

执行kubectl run in-cluster -i --image=docker.io/in-cluster:v0.0.1 --restart=Never --overrides='{"spec": {"imagePullSecrets": [{"name": "image-pull-secret"}]}}'会报错:

pod default/in-cluster terminated (Error)

单从image的size上来说,busybox更小。不过busybox默认的libc实现是uClibc,而我们通常运行环境使用的libc实现都是glibc,因此我们要么选择静态编译程序,要么使用busybox:glibc镜像作为base image。

所以我把Dockerfile改为:
FROM busybox:glibc
WORKDIR /
COPY in-cluster .
ENTRYPOINT ["./in-cluster"]
就可以正常执行程序了。

第七章 application资源的yaml怎么写

书籍150页。 代码逻辑写完,执行make install后,可以查询到crd,但是查询不到application资源,应该是需要编写application资源的yaml文件,然后创建。yaml不知道咋写,各位大佬支援下呢,谢谢!

  1. 查询到applications的crd
$ kubectl get crd applications.apps.tanlay.com 
NAME                           CREATED AT
applications.apps.tanlay.com   2023-01-29T12:57:45
  1. 查询applications资源
$ kubectl get application
No resources found in default namespace.
  1. 编写application资源的yaml文件
apiVersion: apps.tanlay.com/v1
kind: Application
metadata:
  name: application-sample
spec:
  # TODO(user): Add fields here
  deployment:
    ...
  service:
    ...

7.4.5 过滤调谐事件Owns-Service部分代码写错了吧,UpdateFunc部分应该是Service对象,不是Application吧

UpdateFunc部分应该是Service对象,不是Application吧

Owns(&corev1.Service{}, builder.WithPredicates(predicate.Funcs{
			...
			UpdateFunc: func(event event.UpdateEvent) bool {
				if event.ObjectNew.GetResourceVersion() == event.ObjectOld.GetResourceVersion() {
					return false
				}
				if reflect.DeepEqual(event.ObjectNew.(*v1.Application).Spec, event.ObjectOld.(*v1.Application).Spec) {
					return false
				}
				return true
			},
		})).
Owns(&corev1.Service{}, builder.WithPredicates(predicate.Funcs{
			...
			UpdateFunc: func(event event.UpdateEvent) bool {
				if event.ObjectNew.GetResourceVersion() == event.ObjectOld.GetResourceVersion() {
					return false
				}
				if reflect.DeepEqual(event.ObjectNew.(*corev1.Service).Spec, event.ObjectOld.(*corev1.Service).Spec) {
					return false
				}
				return true
			},
		})).

2.5.7 执行make run失败

/data/gomod/pkg/mod/sigs.k8s.io/[email protected]/pkg/log/deleg.go:79:12: undefined: logr.WithCallDepth
/data/gomod/pkg/mod/sigs.k8s.io/[email protected]/pkg/log/deleg.go:163:2: cannot use res (type *DelegatingLogger) as type logr.Logger in return argument
/data/gomod/pkg/mod/sigs.k8s.io/[email protected]/pkg/log/deleg.go:179:2: cannot use res (type *DelegatingLogger) as type logr.Logger in return argument

image

【勘误-P38】PodTemplateSpec字段添加报错

我的代码:

// CoffeeSpec defines the desired state of Coffee
type CoffeeSpec struct {
	// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
	// Important: Run "make" to regenerate code after modifying this file
	Replicas int32                  `json:"replicas,omitempty"`
	Template corev1.PodTemplateSpec `json:"template,omitempty"`
}

我的环境

  • Intel macos
  • golang 1.19
  • kubebuilder 3.9.0

错误

* spec.validation.openAPIV3Schema.properties[spec].properties[template].properties[spec].properties[volumes].items.properties[ephemeral].properties[volumeClaimTemplate].properties[spec].properties[resources].properties[claims].items.x-kubernetes-map-type: Invalid value: "null": must be atomic as item of a list with x-kubernetes-list-type=set
* spec.validation.openAPIV3Schema.properties[spec].properties[template].properties[spec].properties[ephemeralContainers].items.properties[resources].properties[claims].items.x-kubernetes-map-type: Invalid value: "null": must be atomic as item of a list with x-kubernetes-list-type=set
* spec.validation.openAPIV3Schema.properties[spec].properties[template].properties[spec].properties[containers].items.properties[resources].properties[claims].items.x-kubernetes-map-type: Invalid value: "null": must be atomic as item of a list with x-kubernetes-list-type=set
* spec.validation.openAPIV3Schema.properties[spec].properties[template].properties[spec].properties[initContainers].items.properties[resources].properties[claims].items.x-kubernetes-map-type: Invalid value: "null": must be atomic as item of a list with x-kubernetes-list-type=set
make: *** [install] Error 1
```

7.6.2节 多版本部署,v2版本创建yaml报错, v1创建正常

报错如下:

$ kubectl apply -f config/samples/apps_v2_application.yaml 
Error from server: error when retrieving current configuration of:
Resource: "apps.tanlay.com/v2, Resource=applications", GroupVersionKind: "apps.tanlay.com/v2, Kind=Application"
Name: "nginx-sample", Namespace: "default"
from server for: "config/samples/apps_v2_application.yaml": conversion webhook for apps.tanlay.com/v1, Kind=Application failed: the server could not find the requested resource

api/v2/application_types.go文件

// 只修改了ApplicationSpec结构体的Deployment字段为Workflow,其他和v1版本一致,
// 只在v1版本增加了持久化 //+kubebuilder:storageversion
type ApplicationSpec struct {
	// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
	// Important: Run "make" to regenerate code after modifying this file

	Workflow v1.DeploymentTemplate `json:"workflow,omitempty"`
	Service  v1.ServiceTemplate    `json:"service,omitempty"`
}

what's meaning of "adppsv1 links" in controller

	dappsv1 "github.com/daniel-hutao/application-operator/api/v1"

this links is error, when run "make run", it will be run "go get github.com/daniel-hutao/application-operator/api/v1"
How do I understand the api of this ”dappsv1“

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.