Skip to content

Commit

Permalink
Revert "Updating version to v1alpha1 from v1"
Browse files Browse the repository at this point in the history
  • Loading branch information
jananivMS authored and frodopwns committed Oct 10, 2019
1 parent 7990dd6 commit eb6c4b2
Show file tree
Hide file tree
Showing 35 changed files with 294 additions and 553 deletions.
15 changes: 7 additions & 8 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@ resources:
version: v1
kind: Eventhub
- group: azure
version: v1alpha1
version: v1
kind: ResourceGroup
- group: azure
version: v1alpha1
version: v1
kind: EventhubNamespace
- group: azure
version: v1alpha1
kind: KeyVault
- group: azure
version: v1alpha1
kind: ConsumerGroup
- group: azure
version: v1
kind: SqlServer
Expand All @@ -35,6 +29,11 @@ resources:
- group: azure
version: v1
kind: SqlFirewallRule
- group: azure
version: v1
kind: KeyVault
- group: azure
version: v1
kind: ConsumerGroup
- group: azure
version: v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1
package v1

import (
helpers "github.com/Azure/azure-service-operator/pkg/helpers"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1
package v1

import (
. "github.com/onsi/ginkgo"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1
package v1

import (
helpers "github.com/Azure/azure-service-operator/pkg/helpers"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1
package v1

import (
. "github.com/onsi/ginkgo"
Expand Down
82 changes: 82 additions & 0 deletions api/v1/eventhub_webhook.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package v1

import (
eventhubsmanager "github.com/Azure/azure-service-operator/pkg/resourcemanager/eventhubs"
"golang.org/x/net/context"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/validation/field"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)

var eventhublog = logf.Log.WithName("eventhub-resource")

//SetupWebhookWithManager add webhook manager
func (eventhub *Eventhub) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(eventhub).
Complete()
}

// +kubebuilder:webhook:path=/mutate-azure-microsoft-com-v1-eventhub,mutating=true,failurePolicy=fail,groups=azure.microsoft.com,resources=eventhubs,verbs=create;update,versions=v1,name=meventhub.kb.io

var _ webhook.Defaulter = &Eventhub{}

// Default implements webhook.Defaulter so a webhook will be registered for the type
func (eventhub *Eventhub) Default() {
eventhublog.Info("default", "name", eventhub.Name)

// place to add defaulting logic.
}

// +kubebuilder:webhook:path=/validate-azure-microsoft-com-v1-eventhub,mutating=false,failurePolicy=fail,groups=azure.microsoft.com,resources=eventhubs,verbs=create;update,versions=v1,name=veventhub.kb.io

var _ webhook.Validator = &Eventhub{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (eventhub *Eventhub) ValidateCreate() error {
eventhublog.Info("validate create", "name", eventhub.Name)

//validation logic upon object creation.
return eventhub.validateeventhub()
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (eventhub *Eventhub) ValidateUpdate(old runtime.Object) error {
eventhublog.Info("validate update", "name", eventhub.Name)

//validation logic upon object update.
return eventhub.validateeventhub()
}

func (eventhub *Eventhub) validateeventhub() error {
var allErrs field.ErrorList
err := eventhub.validateValidParent()
if err != nil {
eventhublog.Info("error", "name", eventhub.Name)
allErrs = append(allErrs, err)
}
if len(allErrs) == 0 {
return nil
}

return apierrors.NewInvalid(
schema.GroupKind{Group: "azure.microsoft.com", Kind: "eventhub"},
eventhub.Name, allErrs)
}

func (eventhub *Eventhub) validateValidParent() *field.Error {

resourcegroupName := eventhub.Spec.ResourceGroup
eventhubNamespaceName := eventhub.Spec.Namespace
eventhublog.Info("validate event hub namespace Name", "eventhubNamespaceName", eventhubNamespaceName)
result, _ := eventhubsmanager.GetNamespace(context.Background(), resourcegroupName, eventhubNamespaceName)
eventhublog.Info("validate event hub namespace Name", "result.Response.StatusCode", result.Response.StatusCode)
if result.Response.StatusCode != 200 {
return field.Invalid(field.NewPath("spec").Child("namespace"), eventhubNamespaceName, "EventHubNamespace doesn't exist")
}
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1
package v1

import (
helpers "github.com/Azure/azure-service-operator/pkg/helpers"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1
package v1

import (
. "github.com/onsi/ginkgo"
Expand Down
86 changes: 86 additions & 0 deletions api/v1/eventhubnamespace_webhook.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package v1

import (
resoucegroupsresourcemanager "github.com/Azure/azure-service-operator/pkg/resourcemanager/resourcegroups"
"golang.org/x/net/context"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/validation/field"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)

var eventhubnamespacelog = logf.Log.WithName("eventhubnamespace-resource")

func (eventhubNamespace *EventhubNamespace) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(eventhubNamespace).
Complete()
}

// +kubebuilder:webhook:path=/mutate-azure-microsoft-com-v1-eventhubnamespace,mutating=true,failurePolicy=fail,groups=azure.microsoft.com,resources=eventhubnamespaces,verbs=create;update,versions=v1,name=meventhubnamespace.kb.io

var _ webhook.Defaulter = &EventhubNamespace{}

// Default implements webhook.Defaulter so a webhook will be registered for the type
func (eventhubNamespace *EventhubNamespace) Default() {
eventhubnamespacelog.Info("default", "name", eventhubNamespace.Name)

// place to add defaulting logic.
}

// +kubebuilder:webhook:path=/validate-azure-microsoft-com-v1-eventhubnamespace,mutating=false,failurePolicy=fail,groups=azure.microsoft.com,resources=eventhubnamespaces,verbs=create;update,versions=v1,name=veventhubnamespace.kb.io

var _ webhook.Validator = &EventhubNamespace{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (eventhubNamespace *EventhubNamespace) ValidateCreate() error {
eventhubnamespacelog.Info("validate create", "name", eventhubNamespace.Name)

//validation logic upon object creation.
return eventhubNamespace.validateEventhubNamespace()
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (eventhubNamespace *EventhubNamespace) ValidateUpdate(old runtime.Object) error {
eventhubnamespacelog.Info("validate update", "name", eventhubNamespace.Name)

//validation logic upon object update.
return eventhubNamespace.validateEventhubNamespace()
}

func (eventhubNamespace *EventhubNamespace) validateEventhubNamespace() error {
var allErrs field.ErrorList

if len(eventhubNamespace.Name) < 6 {
err := field.Invalid(field.NewPath("metadata").Child("name"), eventhubNamespace.Name, "Eventhubnamespace minimum length should be 6")
allErrs = append(allErrs, err)
}

err := eventhubNamespace.validateValidParent()
if err != nil {
eventhubnamespacelog.Info("error", "name", eventhubNamespace.Name)
allErrs = append(allErrs, err)
}
if len(allErrs) == 0 {
return nil
}

return apierrors.NewInvalid(
schema.GroupKind{Group: "azure.microsoft.com", Kind: "EventhubNamespace"},
eventhubNamespace.Name, allErrs)
}

func (eventhubNamespace *EventhubNamespace) validateValidParent() *field.Error {

resourcegroupName := eventhubNamespace.Spec.ResourceGroup
eventhubnamespacelog.Info("validate resource group Name", "resourcegroupName", resourcegroupName)
result, _ := resoucegroupsresourcemanager.CheckExistence(context.Background(), resourcegroupName)
eventhubnamespacelog.Info("validate resource group Name", "result.Response.StatusCode", result.Response.StatusCode)
if result.Response.StatusCode != 204 {
return field.Invalid(field.NewPath("spec").Child("resourcegroup"), resourcegroupName, "ResourceGroup doesn't exist")
}
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the azure v1alpha1 API group
// Package v1 contains API Schema definitions for the azure v1 API group
// +kubebuilder:object:generate=true
// +groupName=azure.microsoft.com
package v1alpha1
package v1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -25,7 +25,7 @@ import (

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "azure.microsoft.com", Version: "v1alpha1"}
GroupVersion = schema.GroupVersion{Group: "azure.microsoft.com", Version: "v1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1
package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1
package v1

import (
helpers "github.com/Azure/azure-service-operator/pkg/helpers"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1
package v1

import (
. "github.com/onsi/ginkgo"
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/suite_test.go → api/v1/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1
package v1

import (
"path/filepath"
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/azure.microsoft.com_sqlactions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ spec:
type: object
type: object
versions:
- name: v1alpha1
- name: v1
served: true
storage: true
status:
Expand Down
Loading

0 comments on commit eb6c4b2

Please sign in to comment.