Skip to content

Commit 5460fe0

Browse files
author
enshi.wzh
committed
alpha0.1
1 parent 76fab36 commit 5460fe0

File tree

119 files changed

+8672
-5339
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+8672
-5339
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ Dockerfile.cross
2323
*.swp
2424
*.swo
2525
*~
26+
27+
# macOS paraphernalia
28+
.DS_Store
29+
30+
bin/*

.gitlab-ci.yml.exampleforchair

Lines changed: 0 additions & 12 deletions
This file was deleted.

Dockerfile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
# Build the manager binary
21
FROM golang:1.19 as builder
32
ARG TARGETOS
43
ARG TARGETARCH
54

6-
WORKDIR /workspace
5+
WORKDIR /go/src/github.com/traas-stack/altershield-operator
76

87
# Copy the Go Modules manifests
98
COPY go.mod go.mod
@@ -13,27 +12,28 @@ COPY go.sum go.sum
1312
RUN go mod download
1413

1514
# Copy the go source
16-
COPY main.go main.go
17-
COPY apis/ apis/
18-
COPY controllers/ controllers/
19-
COPY routers/ routers/
20-
COPY runnable/ runnable/
15+
COPY . /go/src/github.com/traas-stack/altershield-operator
16+
17+
RUN cd /go/src/github.com/traas-stack/altershield-operator/certs && \
18+
sh generate-tls-certificates.sh
2119

2220
# Build
2321
# the GOARCH has not a default value to allow the binary be built according to the host where the command
2422
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
2523
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
2624
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
2725
#RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go
28-
RUN CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -a -o manager main.go
26+
RUN GO111MODULE=on CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -a -o manager main.go
2927

3028
# Use distroless as minimal base image to package the manager binary
3129
# Refer to https://github.com/GoogleContainerTools/distroless for more details
3230
#FROM gcr.io/distroless/static:nonroot
3331
FROM alpine:3.16 AS final
3432
RUN apk update && apk add curl
3533
WORKDIR /
36-
COPY --from=builder /workspace/manager .
34+
COPY --from=builder /go/src/github.com/traas-stack/altershield-operator/manager .
35+
COPY --from=builder /go/src/github.com/traas-stack/altershield-operator/certs/tls.crt /tmp/k8s-webhook-server/serving-certs/tls.crt
36+
COPY --from=builder /go/src/github.com/traas-stack/altershield-operator/certs/tls.key /tmp/k8s-webhook-server/serving-certs/tls.key
3737
USER 65532:65532
3838
#USER root
3939

PROJECT

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins:
55
manifests.sdk.operatorframework.io/v2: {}
66
scorecard.sdk.operatorframework.io/v2: {}
77
projectName: altershieldoperator
8-
repo: gitlab.alipay-inc.com/common_release/altershieldoperator
8+
repo: github.com/traas-stack/altershield-operator
99
resources:
1010
- api:
1111
crdVersion: v1
@@ -14,7 +14,7 @@ resources:
1414
domain: ops.cloud.alipay.com
1515
group: app
1616
kind: OpsCheckRecord
17-
path: gitlab.alipay-inc.com/common_release/altershieldoperator/api/v1alpha1
17+
path: github.com/traas-stack/altershield-operator/api/v1alpha1
1818
version: v1alpha1
1919
- api:
2020
crdVersion: v1
@@ -23,7 +23,7 @@ resources:
2323
domain: ops.cloud.alipay.com
2424
group: app
2525
kind: OpsConfigInfo
26-
path: gitlab.alipay-inc.com/common_release/altershieldoperator/api/v1alpha1
26+
path: github.com/traas-stack/altershield-operator/api/v1alpha1
2727
version: v1alpha1
2828
- api:
2929
crdVersion: v1
@@ -32,7 +32,7 @@ resources:
3232
domain: ops.cloud.alipay.com
3333
group: app
3434
kind: OpsCheckOrder
35-
path: gitlab.alipay-inc.com/common_release/altershieldoperator/api/v1alpha1
35+
path: github.com/traas-stack/altershield-operator/api/v1alpha1
3636
version: v1alpha1
3737
- api:
3838
crdVersion: v1
@@ -41,7 +41,7 @@ resources:
4141
domain: ops.cloud.alipay.com
4242
group: app
4343
kind: ExeOrder
44-
path: gitlab.alipay-inc.com/common_release/altershieldoperator/api/v1alpha1
44+
path: github.com/traas-stack/altershield-operator/api/v1alpha1
4545
version: v1alpha1
4646
- api:
4747
crdVersion: v1
@@ -50,7 +50,7 @@ resources:
5050
domain: ops.cloud.alipay.com
5151
group: app
5252
kind: ExeNode
53-
path: gitlab.alipay-inc.com/common_release/altershieldoperator/api/v1alpha1
53+
path: github.com/traas-stack/altershield-operator/api/v1alpha1
5454
version: v1alpha1
5555
- api:
5656
crdVersion: v1
@@ -59,7 +59,7 @@ resources:
5959
domain: ops.cloud.alipay.com
6060
group: app
6161
kind: ChangeWorkload
62-
path: gitlab.alipay-inc.com/common_release/altershieldoperator/api/v1alpha1
62+
path: github.com/traas-stack/altershield-operator/api/v1alpha1
6363
version: v1alpha1
6464
- api:
6565
crdVersion: v1
@@ -68,17 +68,33 @@ resources:
6868
domain: ops.cloud.alipay.com
6969
group: app
7070
kind: ChangePod
71-
path: gitlab.alipay-inc.com/common_release/altershieldoperator/api/v1alpha1
71+
path: github.com/traas-stack/altershield-operator/api/v1alpha1
7272
version: v1alpha1
7373
- api:
7474
crdVersion: v1
7575
namespaced: true
7676
group: apps
7777
kind: Deployment
78-
path: gitlab.alipay-inc.com/common_release/altershieldoperator/apis/apps/v1
78+
path: github.com/traas-stack/altershield-operator/apis/apps/v1
7979
version: v1
8080
webhooks:
8181
defaulting: true
8282
validation: true
8383
webhookVersion: v1
84+
- api:
85+
crdVersion: v1
86+
namespaced: true
87+
controller: true
88+
group: app.ops.cloud.alipay.com
89+
kind: ChangeDefense
90+
path: github.com/traas-stack/altershield-operator/apis/app.ops.cloud.alipay.com/v1alpha1
91+
version: v1alpha1
92+
- api:
93+
crdVersion: v1
94+
namespaced: true
95+
controller: true
96+
group: app.ops.cloud.alipay.com
97+
kind: ChangeDefenseExecution
98+
path: github.com/traas-stack/altershield-operator/apis/app.ops.cloud.alipay.com/v1alpha1
99+
version: v1alpha1
84100
version: "3"
6 KB
Binary file not shown.
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/apimachinery/pkg/util/intstr"
22+
)
23+
24+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
25+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
26+
27+
type TargetType string
28+
29+
const (
30+
TargetTypeWorkload TargetType = "workload"
31+
)
32+
33+
// ChangeDefenseSpec defines the desired state of ChangeDefense
34+
type ChangeDefenseSpec struct {
35+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
36+
// Important: Run "make" to regenerate code after modifying this file
37+
38+
// Target indicates the resource that needs change defense
39+
Target *TargetRef `json:"target"`
40+
// DefenseStrategy indicates the defense strategy on targeted resource changes
41+
DefenseStrategy *DefenseStrategy `json:"defenseStrategy"`
42+
// RiskPolicy indicates what to do on risks discovered by defense strategy
43+
// +kubebuilder:validation:Optional
44+
RiskPolicy *RiskPolicy `json:"riskPolicy"`
45+
}
46+
47+
// TargetRef defines the object that needs change defense
48+
type TargetRef struct {
49+
// Type of change resource target
50+
Type TargetType `json:"type"`
51+
// ObjectRef references the targeted kubernetes object
52+
ObjectRef *ObjectRef `json:"objectRef"`
53+
}
54+
55+
// DefenseStrategy defines the defense strategy on resource changes
56+
type DefenseStrategy struct {
57+
// Workload indicates the defense strategy on targeted workload changes
58+
// +kubebuilder:validation:Optional
59+
Workload WorkloadDefenseStrategy `json:"workload"`
60+
}
61+
62+
// Workload defines the defense strategy on workload changes
63+
type WorkloadDefenseStrategy struct {
64+
// Steps define the order of phases to execute defense in batches(e.g. 20%, 40%, 60%, 80%, 100%)
65+
Steps []WorkloadDefenseStep `json:"steps"`
66+
}
67+
68+
type WorkloadDefenseStep struct {
69+
Partition intstr.IntOrString `json:"partition"`
70+
// +kubebuilder:validation:Optional
71+
CheckAfterComplete *int32 `json:"checkAfterComplete"`
72+
}
73+
74+
// RiskPolicy defines what to do on risks discovered by defense strategy
75+
type RiskPolicy struct {
76+
}
77+
78+
type ObjectRef struct {
79+
// API Version of the referent
80+
APIVersion string `json:"apiVersion"`
81+
// Kind of the referent
82+
Kind string `json:"kind"`
83+
// Name of the referent
84+
Name string `json:"name"`
85+
}
86+
87+
type DefensePhase string
88+
const (
89+
DefensePhaseInitial DefensePhase = "Initial"
90+
DefensePhasePreCheck DefensePhase = "PreCheck"
91+
DefensePhaseProgressing DefensePhase = "Progressing"
92+
DefensePhaseObserving DefensePhase = "Observing"
93+
DefensePhasePostCheck DefensePhase = "PostCheck"
94+
DefensePhasePassed DefensePhase = "Passed"
95+
DefensePhaseFailed DefensePhase = "Failed"
96+
DefensePhaseSkipped DefensePhase = "Skipped"
97+
)
98+
99+
// ChangeDefenseStatus defines the observed state of ChangeDefense
100+
type ChangeDefenseStatus struct {
101+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
102+
// Important: Run "make" to regenerate code after modifying this file
103+
// +kubebuilder:validation:Optional
104+
CurrentExecutionID string `json:"currentExecutionID"`
105+
// +kubebuilder:validation:Optional
106+
Verdict string `json:"verdict"`
107+
// +kubebuilder:validation:Optional
108+
Phase DefensePhase `json:"phase"`
109+
}
110+
111+
//+kubebuilder:object:root=true
112+
//+kubebuilder:subresource:status
113+
114+
// ChangeDefense is the Schema for the changedefenses API
115+
type ChangeDefense struct {
116+
metav1.TypeMeta `json:",inline"`
117+
metav1.ObjectMeta `json:"metadata,omitempty"`
118+
119+
Spec ChangeDefenseSpec `json:"spec,omitempty"`
120+
Status ChangeDefenseStatus `json:"status,omitempty"`
121+
}
122+
123+
//+kubebuilder:object:root=true
124+
125+
// ChangeDefenseList contains a list of ChangeDefense
126+
type ChangeDefenseList struct {
127+
metav1.TypeMeta `json:",inline"`
128+
metav1.ListMeta `json:"metadata,omitempty"`
129+
Items []ChangeDefense `json:"items"`
130+
}
131+
132+
func init() {
133+
SchemeBuilder.Register(&ChangeDefense{}, &ChangeDefenseList{})
134+
}

0 commit comments

Comments
 (0)