Skip to content

Commit

Permalink
chore: remove oss crd & deployments (#631)
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow authored Jan 15, 2023
1 parent 73a3270 commit d499422
Show file tree
Hide file tree
Showing 92 changed files with 7 additions and 8,456 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-sealos-cluster-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
run: |
echo "deb [trusted=yes] https://apt.fury.io/labring/ /" | sudo tee /etc/apt/sources.list.d/labring.list
sudo apt update
sudo apt install sealos=4.1.3
sudo apt install sealos=4.1.4
sudo sealos version
- name: Install buildah
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dockerize-controllers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
max-parallel: 2
matrix:
module: [database, gateway, oss]
module: [database, gateway]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
max-parallel: 2
matrix:
module: [database, gateway, oss]
module: [database, gateway]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ kubernetes-local/
.vscode/configurationCache.log
.vscode/dryrun.log
.vscode/targets.log
core/controllers/oss/.vscode/configurationCache.log
core/controllers/oss/.vscode/targets.log
core/controllers/oss/.vscode/dryrun.log

.kube/

Expand Down
3 changes: 1 addition & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"christian-kohler.npm-intellisense",
"streetsidesoftware.code-spell-checker",
"pomdtr.excalidraw-editor",
"golang.go",
"Tim-Koehler.helm-intellisense"
"Tim-Koehler.helm-intellisense"
]
}
78 changes: 0 additions & 78 deletions core/controllers/gateway/config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,81 +95,3 @@ rules:
- get
- patch
- update
- apiGroups:
- oss.laf.dev
resources:
- buckets
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- oss.laf.dev
resources:
- buckets/finalizers
verbs:
- update
- apiGroups:
- oss.laf.dev
resources:
- buckets/status
verbs:
- get
- patch
- update
- apiGroups:
- oss.laf.dev
resources:
- stores
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- oss.laf.dev
resources:
- stores/finalizers
verbs:
- update
- apiGroups:
- oss.laf.dev
resources:
- stores/status
verbs:
- get
- patch
- update
- apiGroups:
- oss.laf.dev
resources:
- users
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- oss.laf.dev
resources:
- users/finalizers
verbs:
- update
- apiGroups:
- oss.laf.dev
resources:
- users/status
verbs:
- get
- patch
- update
10 changes: 0 additions & 10 deletions core/controllers/gateway/controllers/domain_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ type DomainReconciler struct {
//+kubebuilder:rbac:groups=gateway.laf.dev,resources=domains/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=gateway.laf.dev,resources=domains/finalizers,verbs=update

//+kubebuilder:rbac:groups=oss.laf.dev,resources=buckets,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=oss.laf.dev,resources=buckets/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=oss.laf.dev,resources=buckets/finalizers,verbs=update
//+kubebuilder:rbac:groups=oss.laf.dev,resources=users,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=oss.laf.dev,resources=users/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=oss.laf.dev,resources=users/finalizers,verbs=update
//+kubebuilder:rbac:groups=oss.laf.dev,resources=stores,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=oss.laf.dev,resources=stores/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=oss.laf.dev,resources=stores/finalizers,verbs=update

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
// TODO(user): Modify the Reconcile function to compare the state specified by
Expand Down
162 changes: 0 additions & 162 deletions core/controllers/gateway/controllers/gateway_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ import (
"errors"
"time"

v1 "github.com/labring/laf/core/controllers/oss/api/v1"
"github.com/labring/laf/core/pkg/util"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -81,12 +79,6 @@ func (r *GatewayReconciler) apply(ctx context.Context, gateway *gatewayv1.Gatewa
}
}

// apply bucket route
result, err := r.applyBucket(ctx, gateway)
if err != nil {
return result, err
}

// update ready condition
if util.ConditionIsTrue(gateway.Status.Conditions, "Ready") == false {
condition := metav1.Condition{
Expand Down Expand Up @@ -170,160 +162,6 @@ func (r *GatewayReconciler) applyApp(ctx context.Context, gateway *gatewayv1.Gat
return ctrl.Result{}, nil
}

// applyBucket apply bucket
func (r *GatewayReconciler) applyBucket(ctx context.Context, gateway *gatewayv1.Gateway) (ctrl.Result, error) {

// create bucket route
createBuckets := make([]string, 0)
for _, bucketName := range gateway.Spec.Buckets {
if _, ok := gateway.Status.BucketRoutes[bucketName]; !ok {
createBuckets = append(createBuckets, bucketName)
}
}
if len(createBuckets) != 0 {
result, err := r.addBuckets(ctx, gateway, createBuckets)
if err != nil {
return result, err
}
}

// delete bucket route
deleteBuckets := make([]string, 0)
for bucketName := range gateway.Status.BucketRoutes {
if !util.ContainsString(gateway.Spec.Buckets, bucketName) {
deleteBuckets = append(deleteBuckets, bucketName)
}
}
if len(deleteBuckets) != 0 {
result, err := r.deleteBuckets(ctx, gateway, deleteBuckets)
if err != nil {
return result, err
}
}

return ctrl.Result{}, nil
}

// addBuckets add buckets
func (r *GatewayReconciler) addBuckets(ctx context.Context, gateway *gatewayv1.Gateway, buckets []string) (ctrl.Result, error) {
_log := log.FromContext(ctx)

// if gateway status bucketRoutes is nil, init it
if gateway.Status.BucketRoutes == nil {
gateway.Status.BucketRoutes = make(map[string]*gatewayv1.GatewayRoute, 0)
}

// select bucket domain
for _, bucketName := range buckets {

// if bucket route is not exist, create it
if _, ok := gateway.Status.BucketRoutes[bucketName]; ok {
continue
}

// get bucket
bucket := v1.Bucket{}
err := r.Get(ctx, client.ObjectKey{Namespace: gateway.Namespace, Name: bucketName}, &bucket)
if err != nil {
return ctrl.Result{}, err
}
// get user
user := v1.User{}
err = r.Get(ctx, client.ObjectKey{Namespace: gateway.Namespace, Name: bucket.Status.User}, &user)
if err != nil {
return ctrl.Result{}, err
}
// get store
store := v1.Store{}
err = r.Get(ctx, client.ObjectKey{Namespace: user.Status.StoreNamespace, Name: user.Status.StoreName}, &store)
if err != nil {
return ctrl.Result{}, err
}
// select bucket domain
bucketDomain, err := r.selectDomain(ctx, gatewayv1.BUCKET, store.Spec.Region)
if err != nil {
return ctrl.Result{}, err
}
if bucketDomain == nil {
_log.Info("no bucket domain found")
continue
}

routeStatus := &gatewayv1.GatewayRoute{
DomainName: bucketDomain.Name,
DomainNamespace: bucketDomain.Namespace,
Domain: bucketName + "." + bucketDomain.Spec.Domain,
}

// create bucket route
bucketRoute := &gatewayv1.Route{
ObjectMeta: ctrl.ObjectMeta{
Name: "bucket-" + bucketName,
Namespace: gateway.Namespace,
},
Spec: gatewayv1.RouteSpec{
Domain: routeStatus.Domain,
DomainName: bucketDomain.Name,
DomainNamespace: bucketDomain.Namespace,
Backend: gatewayv1.Backend{
ServiceName: user.Status.Endpoint,
ServicePort: 0, // If set to 0, the port is not used
},
},
}

if _, err := controllerutil.CreateOrUpdate(ctx, r.Client, bucketRoute, func() error {
if err := controllerutil.SetControllerReference(gateway, bucketRoute, r.Scheme); err != nil {
return err
}
return nil
}); err != nil {
return ctrl.Result{}, err
}
gateway.Status.BucketRoutes[bucketName] = routeStatus

if err = r.updateStatus(ctx, types.NamespacedName{Name: gateway.Name, Namespace: gateway.Namespace}, gateway.Status.DeepCopy()); err != nil {
return ctrl.Result{}, err
}
}

return ctrl.Result{}, nil
}

// deleteBuckets delete buckets
func (r *GatewayReconciler) deleteBuckets(ctx context.Context, gateway *gatewayv1.Gateway, buckets []string) (ctrl.Result, error) {
_ = log.FromContext(ctx)

// find deleted bucket, remote route and finalizer
for _, bucketName := range buckets {
// delete route
route := &gatewayv1.Route{}

// 删除名称为test的route
if err := r.Get(ctx, client.ObjectKey{Namespace: gateway.Namespace, Name: "bucket-" + bucketName}, route); err != nil {
if apierrors.IsNotFound(err) {
continue
}
return ctrl.Result{}, err
}

if err := r.Delete(ctx, route); err != nil {
if apierrors.IsNotFound(err) {
continue
}
return ctrl.Result{}, err
}

// delete bucket route
delete(gateway.Status.BucketRoutes, bucketName)
if err := r.updateStatus(ctx, types.NamespacedName{Name: gateway.Name, Namespace: gateway.Namespace}, gateway.Status.DeepCopy()); err != nil {
return ctrl.Result{}, err
}
}

return ctrl.Result{}, nil
}

func (r *GatewayReconciler) selectDomain(ctx context.Context, backendType gatewayv1.BackendType, region string) (*gatewayv1.Domain, error) {
_ = log.FromContext(ctx)

Expand Down
Loading

0 comments on commit d499422

Please sign in to comment.