Skip to content

Commit

Permalink
Merge pull request #20 from xishengcai/n1
Browse files Browse the repository at this point in the history
support service annotation
  • Loading branch information
caixisheng authored Oct 25, 2022
2 parents 3cfa017 + 8a92c42 commit f51d9a8
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 16 deletions.
2 changes: 2 additions & 0 deletions apis/core/v1alpha2/core_workload_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ type ContainerizedWorkloadSpec struct {
// More info: https://kubernetes.io/docs/concepts/services-networking/service/
// +optional
ServiceType corev1.ServiceType `json:"serviceType,omitempty"`

ServiceAnnotation map[string]string `json:"serviceAnnotation,omitempty"`
}

type Dependency struct {
Expand Down
7 changes: 7 additions & 0 deletions apis/core/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ if [ -z "$VERSION" ]; then
fi

if [ -z "$IMAGE_REPO" ]; then
# IMAGE_REPO='registry.cn-beijing.aliyuncs.com/launcher-agent-only-dev'
IMAGE_REPO='registry.cn-hangzhou.aliyuncs.com/launcher-agent-only-test'
IMAGE_REPO='registry.cn-beijing.aliyuncs.com/launcher-agent-only-dev'
# IMAGE_REPO='registry.cn-hangzhou.aliyuncs.com/launcher-agent-only-test'
fi

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/${BIN_FILE} ./main.go
Expand Down
6 changes: 3 additions & 3 deletions charts/oam-kubernetes-runtime/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: v1
apiVersion: v2
name: oam-kubernetes-runtime
description: A Helm chart for OAM Kubernetes Resources Controller

Expand All @@ -14,8 +14,8 @@ type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
version: 0.81.0
version: 0.91.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application.
appVersion: 0.1
appVersion: 3.9.3
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,10 @@ spec:
pointToGrayName:
description: old grey workload name need modify match selector
type: string
serviceAnnotation:
additionalProperties:
type: string
type: object
serviceMesh:
description: check add istio label
type: boolean
Expand Down
5 changes: 3 additions & 2 deletions examples/workload-node-port/sample_component.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ spec:
apiVersion: core.oam.dev/v1alpha2
kind: ContainerizedWorkload
spec:
serviceType: LoadBalancer
forceUpdateTimestamp: 2022-05-31 03:51:49.22334519 +0000 UTC m=+6038.673245278
serviceType: ClusterIP
containers:
- name: wordpress
image: wordpress:4.6.1-apache
Expand All @@ -16,7 +17,7 @@ spec:
name: wordpress
- containerPort: 81
name: xxx
# nodePort: 31234
nodePort: 0
env:
- name: TEST_ENV
value: test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
// server side apply the service
if err := r.applicator.Apply(ctx, service, applyOpts...); err != nil {
klog.ErrorS(err, "Failed to apply a service")
delErr := r.Client.Delete(ctx, service)
if delErr != nil {
klog.ErrorS(delErr, "Failed to delete a service")
}
r.record.Event(eventObj, event.Warning(errApplyService, err))
return util.ReconcileWaitResult,
util.PatchCondition(ctx, r, &workload, cpv1alpha1.ReconcileError(errors.Wrap(err, errApplyService)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,8 @@ func (r *Reconciler) renderService(ctx context.Context,
if service == nil || len(service.Spec.Ports) == 0 {
return nil, nil
}
// the service injector lib doesn't set the namespace and serviceType
service.Namespace = workload.Namespace
// k8s server-side patch complains if the protocol is not set

for index, i := range service.Spec.Ports {
if i.Protocol == "" {
service.Spec.Ports[index].Protocol = corev1.ProtocolTCP
}
}
// always set the controller reference so that we can watch this service and
service.Annotations = workload.Spec.ServiceAnnotation
if err := ctrl.SetControllerReference(workload, service, r.Scheme); err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ func ServiceInjector(_ context.Context, w *v1alpha2.ContainerizedWorkload, obj r
for _, c := range container.Ports {
svc.Spec.Ports = append(svc.Spec.Ports, corev1.ServicePort{
Name: fmt.Sprintf("cont-%d-%s", index, c.Name),
Protocol: corev1.ProtocolTCP,
Port: c.Port,
TargetPort: intstr.FromInt(int(c.Port)),
NodePort: c.NodePort,
Expand Down

0 comments on commit f51d9a8

Please sign in to comment.