Skip to content

Commit

Permalink
API of validation (#148)
Browse files Browse the repository at this point in the history
* Start to work on a proposal of validation of config

* first validation controller

* Avoid race condition using validation-hash on pod

* Design a validation manager

* initialize validation manager

* Add role

* wait last generation of status on rpaas-api

* working to validate file

* Add tests about validation

* Remove duplicated imports

* Add tests about desired volumes and volumeMounts

* Add tests that covers creation of validation pod

* use k8s.io/utils/ptr instead of k8s.io/utils/pointer

* Fix order of import

* go mod tidy

* Upgrade golangci-lint

* Update nginx-operator

* Add flag by cluster to disable validation

* fix race condition

* Upgrade kubernetes and version of rpaas-operator

* Include CRD of RPaaSValidation on kustomize

* Review some codes

* Update lint
  • Loading branch information
wpjunior authored Jun 6, 2024
1 parent cb9c21d commit 0479ead
Show file tree
Hide file tree
Showing 24 changed files with 8,943 additions and 309 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: "1.21"
- uses: golangci/golangci-lint-action@v3
- uses: golangci/golangci-lint-action@v6
with:
version: v1.56
version: v1.59
args: --timeout=10m
- run: make test

integration:
Expand All @@ -21,8 +22,8 @@ jobs:
fail-fast: true
matrix:
k8s_version:
- 1.24.13 # current version at GKE stable channel (https://cloud.google.com/kubernetes-engine/docs/release-notes#current_versions)
- 1.25.8 # current version at GKE regular channel (https://cloud.google.com/kubernetes-engine/docs/release-notes#current_versions)
- 1.27.11 # current version at GKE stable channel (https://cloud.google.com/kubernetes-engine/docs/release-notes#current_versions)
- 1.28.7 # current version at GKE regular channel (https://cloud.google.com/kubernetes-engine/docs/release-notes#current_versions)
steps:
- uses: actions/checkout@master
- name: Running up Kubernetes (using Minikube)
Expand Down
16 changes: 15 additions & 1 deletion api/v1alpha1/rpaasinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import (
)

const (
DefaultLabelKeyPrefix = "rpaas.extensions.tsuru.io"
DefaultLabelKeyPrefix = "rpaas.extensions.tsuru.io"

RpaasOperatorValidationNameLabelKey = DefaultLabelKeyPrefix + "/validation-name"
RpaasOperatorValidationHashAnnotationKey = DefaultLabelKeyPrefix + "/validation-hash"

RpaasOperatorInstanceNameLabelKey = DefaultLabelKeyPrefix + "/instance-name"
RpaasOperatorServiceNameLabelKey = DefaultLabelKeyPrefix + "/service-name"
RpaasOperatorPlanNameLabelKey = DefaultLabelKeyPrefix + "/plan-name"
Expand Down Expand Up @@ -123,3 +127,13 @@ func mergeMap(a, b map[string]string) map[string]string {
}
return a
}

func (i *RpaasValidation) BelongsToCluster(clusterName string) bool {
instanceCluster := i.Labels[RpaasOperatorClusterNameLabelKey]

if instanceCluster == "" {
return false
}

return clusterName == instanceCluster
}
50 changes: 50 additions & 0 deletions api/v1alpha1/rpaasvalidation_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2024 tsuru authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +kubebuilder:object:root=true
// +kubebuilder:resource:shortName=rpaas-validation
// +kubebuilder:subresource:status
// RpaasInstance is the Schema for the rpaasinstances API
type RpaasValidation struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Status RpaasValidationStatus `json:"status,omitempty"`
// Spec reuse the same properties of RpaasInstance, just to avoid duplication of code
Spec RpaasInstanceSpec `json:"spec,omitempty"`
}

// RpaasValidationStatus defines the observed state of RpaasValidation
type RpaasValidationStatus struct {
//Revision hash calculated for the current spec of rpaasvalidation
RevisionHash string `json:"revisionHash,omitempty"`

// The most recent generation observed by the rpaas operator controller.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// Valid determines whether validation is valid
Valid *bool `json:"valid,omitempty"`

// Feedback of validation of nginx
Error string `json:"error,omitempty"`
}

// +kubebuilder:object:root=true

// RpaasValidationList contains a list of RpaasInstance
type RpaasValidationList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []RpaasValidation `json:"items"`
}

func init() {
SchemeBuilder.Register(&RpaasValidation{}, &RpaasValidationList{})
}
79 changes: 79 additions & 0 deletions api/v1alpha1/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 cmd/plugin/rpaasv2/cmd/autoscale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

"github.com/tsuru/rpaas-operator/pkg/rpaas/client/autogenerated"
)
Expand Down Expand Up @@ -71,7 +71,7 @@ max replicas: 5
Schedules: []autogenerated.ScheduledWindow{
{MinReplicas: 1, Start: "00 08 * * 1-5", End: "00 20 * * 1-5"},
{MinReplicas: 5, Start: "00 20 * * 2", End: "00 01 * * 3"},
{MinReplicas: 5, Start: "00 22 * * 0", End: "00 02 * * 1", Timezone: pointer.String("America/Chile")},
{MinReplicas: 5, Start: "00 22 * * 0", End: "00 02 * * 1", Timezone: ptr.To("America/Chile")},
},
})
}),
Expand Down
Loading

0 comments on commit 0479ead

Please sign in to comment.