Skip to content

Commit

Permalink
[feature] support cloneset resource
Browse files Browse the repository at this point in the history
Signed-off-by: blade <ddh2022lin@gmail.com>
  • Loading branch information
riven-blade committed Jan 11, 2025
1 parent f66bd47 commit 1df72ed
Show file tree
Hide file tree
Showing 12 changed files with 356 additions and 62 deletions.
118 changes: 63 additions & 55 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/docker/distribution v2.8.2+incompatible
github.com/docker/docker v23.0.1+incompatible
github.com/docker/go-connections v0.4.0
github.com/envoyproxy/go-control-plane v0.10.3
github.com/envoyproxy/go-control-plane v0.11.1-0.20230524094728-9239064ad72f
github.com/gin-gonic/gin v1.9.1
github.com/go-co-op/gocron v1.17.0
github.com/go-ldap/ldap/v3 v3.3.0
Expand All @@ -39,8 +39,8 @@ require (
github.com/go-sql-driver/mysql v1.7.1
github.com/godoes/gorm-dameng v0.0.8
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/golang/protobuf v1.5.3
github.com/google/gnostic v0.6.9
github.com/golang/protobuf v1.5.4
github.com/google/gnostic-models v0.6.8
github.com/google/go-github/v35 v35.3.0
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.0
Expand All @@ -67,11 +67,12 @@ require (
github.com/onsi/ginkgo/v2 v2.12.1
github.com/onsi/gomega v1.27.10
github.com/opencontainers/go-digest v1.0.0
github.com/openkruise/kruise-api v1.6.0
github.com/otiai10/copy v1.7.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pingcap/tidb/parser v0.0.0-20230922051344-241e8464cde0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.15.1
github.com/prometheus/client_golang v1.16.0
github.com/redis/go-redis/v9 v9.2.1
github.com/rfyiamcool/cronlib v1.2.1
github.com/robfig/cron/v3 v3.0.1
Expand All @@ -84,22 +85,22 @@ require (
github.com/stretchr/testify v1.9.0
github.com/swaggo/files v0.0.0-20220728132757-551d4a08d97a
github.com/swaggo/gin-swagger v1.5.3
github.com/swaggo/swag v1.16.3
github.com/tidwall/gjson v1.14.3
github.com/traefik/yaegi v0.16.1
github.com/xanzy/go-gitlab v0.73.1
go.mongodb.org/mongo-driver v1.10.2
go.uber.org/zap v1.25.0
golang.org/x/crypto v0.23.0
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
golang.org/x/net v0.25.0
golang.org/x/oauth2 v0.5.0
golang.org/x/sync v0.6.0
golang.org/x/text v0.15.0
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.30.0
golang.org/x/crypto v0.24.0
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
golang.org/x/net v0.26.0
golang.org/x/oauth2 v0.12.0
golang.org/x/sync v0.7.0
golang.org/x/text v0.16.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc
google.golang.org/grpc v1.55.0
google.golang.org/protobuf v1.35.1
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
gopkg.in/ini.v1 v1.67.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
Expand All @@ -108,22 +109,22 @@ require (
helm.sh/helm/v3 v3.12.3
istio.io/api v0.0.0-20221109202042-b9e5d446a83d
istio.io/client-go v1.16.0
k8s.io/api v0.27.7
k8s.io/apiextensions-apiserver v0.27.7
k8s.io/apimachinery v0.27.7
k8s.io/cli-runtime v0.27.3
k8s.io/client-go v0.27.7
k8s.io/api v0.28.2
k8s.io/apiextensions-apiserver v0.28.2
k8s.io/apimachinery v0.28.2
k8s.io/cli-runtime v0.28.2
k8s.io/client-go v0.28.2
k8s.io/helm v2.17.0+incompatible
k8s.io/klog/v2 v2.100.1
k8s.io/kubectl v0.27.3
k8s.io/metrics v0.27.3
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5
sigs.k8s.io/controller-runtime v0.15.3
k8s.io/klog/v2 v2.120.1
k8s.io/kubectl v0.28.2
k8s.io/metrics v0.28.2
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
sigs.k8s.io/controller-runtime v0.16.2
sigs.k8s.io/yaml v1.4.0
)

require (
cloud.google.com/go/compute v1.18.0 // indirect
cloud.google.com/go/compute v1.20.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230106234847-43070de90fa1 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
Expand Down Expand Up @@ -157,12 +158,12 @@ require (
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/clbanning/mxj/v2 v2.5.5 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cncf/xds/go v0.0.0-20230105202645-06c439db220b // indirect
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 // indirect
github.com/containerd/containerd v1.7.0 // indirect
github.com/containerd/typeurl v1.0.2 // indirect
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgraph-io/ristretto v0.1.0 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
Expand All @@ -173,9 +174,9 @@ require (
github.com/docker/go-units v0.5.0 // indirect
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
github.com/dsnet/compress v0.0.1 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/envoyproxy/protoc-gen-validate v0.9.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/envoyproxy/protoc-gen-validate v0.10.1 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
Expand All @@ -190,7 +191,7 @@ require (
github.com/go-asn1-ber/asn1-ber v1.5.1 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-gorp/gorp/v3 v3.0.5 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
Expand All @@ -206,21 +207,22 @@ require (
github.com/goccy/go-json v0.10.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f // indirect
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/flatbuffers v1.12.1 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-github/v29 v29.0.2 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20230926050212-f7f687d19a98 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/googleapis/gax-go/v2 v2.11.0 // indirect
github.com/gosuri/uitable v0.0.4 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
Expand Down Expand Up @@ -249,7 +251,7 @@ require (
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/moby/locker v1.0.1 // indirect
Expand All @@ -271,11 +273,11 @@ require (
github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63 // indirect
github.com/pingcap/failpoint v0.0.0-20220801062533-2eaa32854a6c // indirect
github.com/pingcap/log v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-20 v0.3.4 // indirect
github.com/quic-go/quic-go v0.39.0 // indirect
Expand All @@ -290,6 +292,7 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/swaggo/swag v1.16.3 // indirect
github.com/tdewolff/parse/v2 v2.7.11 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
Expand All @@ -307,41 +310,46 @@ require (
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/trace v1.14.0 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/mock v0.3.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/image v0.0.0-20190802002840-cff245a6509b // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.19.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
google.golang.org/api v0.110.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
golang.org/x/tools v0.22.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/api v0.126.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
k8s.io/apiserver v0.27.7 // indirect
k8s.io/component-base v0.27.7 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
k8s.io/apiserver v0.28.2 // indirect
k8s.io/component-base v0.28.2 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
oras.land/oras-go v1.2.3 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.13.2 // indirect
sigs.k8s.io/kustomize/kyaml v0.14.1 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)

// this is a fix for a broken docker package, reference: https://github.com/moby/moby/issues/42939
replace github.com/Sirupsen/logrus => github.com/sirupsen/logrus v1.9.0

replace github.com/docker/libnetwork => github.com/docker/libnetwork v0.8.0-dev.2.0.20220716072657-0dde5c895075

replace github.com/google/gnostic => github.com/google/gnostic v0.6.9

replace github.com/google/gnostic-models => github.com/google/gnostic-models v0.6.9
38 changes: 38 additions & 0 deletions pkg/microservice/aslan/core/common/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ package service

import (
"bytes"
"context"
"encoding/json"
"fmt"
"github.com/koderover/zadig/v2/pkg/tool/clientmanager"
"github.com/openkruise/kruise-api/apps/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"net/url"
"regexp"
"strconv"
Expand Down Expand Up @@ -1420,6 +1424,17 @@ func GetServiceImpl(serviceName string, serviceTmpl *commonmodels.Service, workL

ret.Scales = append(ret.Scales, GetDeploymentWorkloadResource(d, inf, log))
ret.Workloads = append(ret.Workloads, ToDeploymentWorkload(d))
case setting.CloneSet:
dc, err := clientmanager.NewKubeClientManager().GetKruiseClient(env.ClusterID)
if err != nil {
continue
}
d, err := dc.AppsV1alpha1().CloneSets(namespace).Get(context.Background(), u.GetName(), metav1.GetOptions{})
if err != nil {
continue
}
ret.Scales = append(ret.Scales, GetCloneSetWorkloadResource(d, inf, log))
ret.Workloads = append(ret.Workloads, ToCloneSetWorkload(d))
case setting.StatefulSet:
sts, err := getter.GetStatefulSetByNameWWithCache(u.GetName(), namespace, inf)
if err != nil {
Expand Down Expand Up @@ -1494,6 +1509,15 @@ func GetDeploymentWorkloadResource(d *appsv1.Deployment, informer informers.Shar
return wrapper.Deployment(d).WorkloadResource(pods)
}

func GetCloneSetWorkloadResource(d *v1alpha1.CloneSet, informer informers.SharedInformerFactory, log *zap.SugaredLogger) *internalresource.Workload {
pods, err := getter.ListPodsWithCache(labels.SelectorFromValidatedSet(d.Spec.Selector.MatchLabels), informer)
if err != nil {
log.Warnf("Failed to get pods, err: %s", err)
}

return wrapper.CloneSet(d).WorkloadResource(pods)
}

func getStatefulSetWorkloadResource(sts *appsv1.StatefulSet, informer informers.SharedInformerFactory, log *zap.SugaredLogger) *internalresource.Workload {
pods, err := getter.ListPodsWithCache(labels.SelectorFromValidatedSet(sts.Spec.Selector.MatchLabels), informer)
if err != nil {
Expand Down Expand Up @@ -1548,6 +1572,20 @@ func ToDeploymentWorkload(v *appsv1.Deployment) *Workload {
return workload
}

func ToCloneSetWorkload(v *v1alpha1.CloneSet) *Workload {
workload := &Workload{
Name: v.Name,
Spec: v.Spec.Template,
Selector: v.Spec.Selector,
Type: setting.CloneSet,
Images: wrapper.CloneSet(v).ImageInfos(),
Containers: wrapper.CloneSet(v).GetContainers(),
Ready: wrapper.CloneSet(v).Ready(),
Annotation: v.Annotations,
}
return workload
}

func toStsWorkload(v *appsv1.StatefulSet) *Workload {
workload := &Workload{
Name: v.Name,
Expand Down
5 changes: 4 additions & 1 deletion pkg/microservice/aslan/core/common/util/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ func SetCurrentContainerImages(args *commonmodels.Service) error {
return errors.New("nil Resource Kind")
}

if resKind.Kind == setting.Deployment || resKind.Kind == setting.StatefulSet || resKind.Kind == setting.Job {
if resKind.Kind == setting.Deployment ||
resKind.Kind == setting.StatefulSet ||
resKind.Kind == setting.Job ||
resKind.Kind == setting.CloneSet {
containers, err := getContainers(yamlData)
if err != nil {
return fmt.Errorf("GetContainers error: %v", err)
Expand Down
Loading

0 comments on commit 1df72ed

Please sign in to comment.