Skip to content

Commit

Permalink
删除vendor 修复Envbug
Browse files Browse the repository at this point in the history
  • Loading branch information
qingmu-io committed Apr 9, 2020
1 parent 6fc116a commit 2e9039d
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 452 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ jobs:
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker login -u ${{ secrets.ALI_DOCKER_USERNAME }} -p ${{ secrets.ALI_DOCKER_PASSWORD }} ${{secrets.ALI_REGISTRY}}
docker push freemanliu/spring-boot-operator-controller:${{ steps.create_release.outputs.tag }}
docker push registry.cn-shanghai.aliyuncs.com/qingmuio/spring-boot-operator-controller:${{ steps.create_release.outputs.tag }}
docker tag freemanliu/spring-boot-operator-controller:${{ steps.create_release.outputs.tag }} freemanliu/spring-boot-operator-controller:latest
docker push freemanliu/spring-boot-operator-controller:latest
docker push registry.cn-shanghai.aliyuncs.com/qingmuio/spring-boot-operator-controller:${{ steps.create_release.outputs.tag }}
docker tag registry.cn-shanghai.aliyuncs.com/qingmuio/spring-boot-operator-controller:${{ steps.create_release.outputs.tag }} registry.cn-shanghai.aliyuncs.com/qingmuio/spring-boot-operator-controller:latest
docker push registry.cn-shanghai.aliyuncs.com/qingmuio/spring-boot-operator-controller:latest
32 changes: 1 addition & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,4 @@
# spring-boot-operator
快速体验
```shell script
kubectl apply -f https://raw.githubusercontent.com/goudai/spring-boot-operator/master/manifests/deployment.yaml
```
对于拉取Docker.io很慢的同学可以使用阿里云镜像仓库
```shell script
kubectl apply -f https://raw.githubusercontent.com/goudai/spring-boot-operator/master/manifests/deployment_ali.yaml
```

等待启动完成
```shell script
kubectl get po -A | grep spring-boot-operator
```
编写第一个 spring-boot demo
Demo Github地址:https://github.com/goudai/operator-demo

```yaml
apiVersion: springboot.qingmu.io/v1alpha1
kind: SpringBootApplication
metadata:
name: operator-demo
namespace: default
spec:
springBoot:
version: v1.0.0
replicas: 1
```
部署
```shell script
kubectl apply -f https://raw.githubusercontent.com/goudai/spring-boot-operator/master/manifests/demo1.yaml
```
文档 [https://qingmu.io/2020/04/08/Spring-Boot-Operator-User-Guide/](https://qingmu.io/2020/04/08/Spring-Boot-Operator-User-Guide/)


15 changes: 10 additions & 5 deletions api/v1alpha1/springbootapplication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,18 @@ func (s *SpringBoot) Check(Name string) (*SpringBoot, error) {
if s.Env == nil {
s.Env = []v1.EnvVar{}
}
envStringMap := make(map[string]string)
for _, v := range s.Env {
envStringMap[v.Name] = v.Value
}
if len(config.Env) > 0 {

for k, v := range config.Env {
s.Env = append(s.Env, v1.EnvVar{
Name: k,
Value: v,
})
if _, ok := envStringMap[k]; !ok {
s.Env = append(s.Env, v1.EnvVar{
Name: k,
Value: v,
})
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions config/samples/springboot_v1alpha1_springbootapplication.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ spec:
imagePullSecrets: #可以不设置 如果你使用的都是公开仓库的话, 私有仓库请设置该值,
- aliyun-docker-registry-secret
env: #可以不设置 环境变量
- name: EUREKA_SERVERS
value: http://eureka1:8761/eureka/,http://eureka2:8761/eureka/,http://eureka3:8761/eureka/
- name: EUREKA_SERVER
value: http://eureka1:888/eureka/
- name: k
value: v2
nodeAffinity: #可以不设置 节点亲和 这里演示的是尽量将pod分散到 i h g 三个可用区,默认设置了pod反亲和
key: "failure-domain.beta.kubernetes.io/zone"
operator: "In"
Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,13 @@ func onStart() {
config.ImagePullSecrets = strings.Split(imagePullSecrets, ",")
}

Env := os.Getenv("Env")
Env := os.Getenv("SPRING_BOOT_ENV")
if Env == "" {
setupLog.Info("Not set env Env")
} else {
config.Env = make(map[string]string)
setupLog.Info("Get user set env value ", "Env", Env)
for _, kv := range strings.Split(imagePullSecrets, ",") {
for _, kv := range strings.Split(Env, ";") {
kyarray := strings.Split(kv, "=")
if len(kyarray) == 2 {
config.Env[kyarray[0]] = kyarray[1]
Expand Down
138 changes: 117 additions & 21 deletions manifests/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
apiVersion: v1
kind: Namespace
metadata:
labels:
control-plane: controller-manager
name: spring-boot-operator-system
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
Expand Down Expand Up @@ -48,10 +41,111 @@ spec:
cluster ip). "" by default
type: string
env:
additionalProperties:
type: string
description: The spring boot application env.
type: object
items:
description: EnvVar represents an environment variable present
in a Container.
properties:
name:
description: Name of the environment variable. Must be a C_IDENTIFIER.
type: string
value:
description: 'Variable references $(VAR_NAME) are expanded
using the previous defined environment variables in the
container and any service environment variables. If a variable
cannot be resolved, the reference in the input string will
be unchanged. The $(VAR_NAME) syntax can be escaped with
a double $$, ie: $$(VAR_NAME). Escaped references will never
be expanded, regardless of whether the variable exists or
not. Defaults to "".'
type: string
valueFrom:
description: Source for the environment variable's value.
Cannot be used if value is not empty.
properties:
configMapKeyRef:
description: Selects a key of a ConfigMap.
properties:
key:
description: The key to select.
type: string
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind,
uid?'
type: string
optional:
description: Specify whether the ConfigMap or its
key must be defined
type: boolean
required:
- key
type: object
fieldRef:
description: 'Selects a field of the pod: supports metadata.name,
metadata.namespace, metadata.labels, metadata.annotations,
spec.nodeName, spec.serviceAccountName, status.hostIP,
status.podIP, status.podIPs.'
properties:
apiVersion:
description: Version of the schema the FieldPath is
written in terms of, defaults to "v1".
type: string
fieldPath:
description: Path of the field to select in the specified
API version.
type: string
required:
- fieldPath
type: object
resourceFieldRef:
description: 'Selects a resource of the container: only
resources limits and requests (limits.cpu, limits.memory,
limits.ephemeral-storage, requests.cpu, requests.memory
and requests.ephemeral-storage) are currently supported.'
properties:
containerName:
description: 'Container name: required for volumes,
optional for env vars'
type: string
divisor:
anyOf:
- type: integer
- type: string
description: Specifies the output format of the exposed
resources, defaults to "1"
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
resource:
description: 'Required: resource to select'
type: string
required:
- resource
type: object
secretKeyRef:
description: Selects a key of a secret in the pod's namespace
properties:
key:
description: The key of the secret to select from. Must
be a valid secret key.
type: string
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind,
uid?'
type: string
optional:
description: Specify whether the Secret or its key
must be defined
type: boolean
required:
- key
type: object
type: object
required:
- name
type: object
type: array
image:
description: The spring boot application Image If the value is empty,using
fmt.Sprintf("%s/%s:%s", config.ImageRepository, Name, s.Version)
Expand All @@ -73,9 +167,9 @@ spec:
type: string
type: array
required:
- key
- operator
- values
- key
- operator
- values
type: object
path:
description: The spring boot application path Liveness and Readiness is
Expand Down Expand Up @@ -135,23 +229,24 @@ spec:
type: string
type: object
required:
- springBoot
- springBoot
type: object
status:
description: SpringBootApplicationStatus defines the observed state of SpringBootApplication
type: object
type: object
version: v1alpha1
versions:
- name: v1alpha1
served: true
storage: true
- name: v1alpha1
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []

---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
Expand Down Expand Up @@ -353,9 +448,9 @@ spec:
- name: LIMIT_CPU
value: ""
- name: REQUEST_MEMORY
value: 500Mi
value: 512Mi
- name: LIMIT_MEMORY
value: 500Mi
value: 512Mi
- name: READINESS_PATH
value: /actuator/health
- name: LIVENESS_PATH
Expand All @@ -376,9 +471,10 @@ spec:
value: ""
- name: NODE_AFFINITY_VALUES
value: ""
- name: ENV
- name: SPRING_BOOT_ENV
value: ""
image: freemanliu/spring-boot-operator-controller:v0.0.2
image: freemanliu/spring-boot-operator-controller:latest
imagePullPolicy: Always
name: manager
resources:
limits:
Expand Down
Loading

0 comments on commit 2e9039d

Please sign in to comment.