Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP #204

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

WIP #204

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/deployer/connector/astra_connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ func TestAstraConnectGetDeploymentObjects(t *testing.T) {
Namespace: "test-namespace",
},
Spec: v1.AstraConnectorSpec{
AutoSupport: v1.AutoSupport{Enrolled: true,
URL: "https://my-asup"},

ImageRegistry: v1.ImageRegistry{
Name: "test-registry",
Secret: "test-secret",
Expand Down Expand Up @@ -119,6 +122,9 @@ func DummyAstraConnector() v1.AstraConnector {
Image: "test-image",
Replicas: 1,
},
AutoSupport: v1.AutoSupport{
Enrolled: true,
URL: "https://my-asup"},
},
}
}
Expand Down
20 changes: 20 additions & 0 deletions app/deployer/neptune/neptuneV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package neptune
import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -315,3 +316,22 @@ func (n NeptuneClientDeployerV2) GetRoleBindingObjects(m *v1.AstraConnector, ctx
func (n NeptuneClientDeployerV2) GetClusterRoleBindingObjects(m *v1.AstraConnector, ctx context.Context) ([]client.Object, error) {
return nil, nil
}

func GetASUPControllerObject(asupEnabled bool) client.Object {

cr := &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "management.astra.netapp.io/v1alpha1",
"kind": "AutoSupportBundleSchedule",
"metadata": map[string]interface{}{
"name": "autosupportbundleschedule-123",
},
"spec": map[string]interface{}{
"enabled": asupEnabled,
},
},
}

return cr

}
6 changes: 6 additions & 0 deletions app/deployer/neptune/neptune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func createNeptuneDeployer() (neptune.NeptuneClientDeployer, *v1.AstraConnector,
Namespace: "test-namespace",
},
Spec: v1.AstraConnectorSpec{
AutoSupport: v1.AutoSupport{
Enrolled: true,
URL: "https://my-asup"},
ImageRegistry: v1.ImageRegistry{
Secret: "test-secret",
},
Expand All @@ -50,6 +53,9 @@ func createNeptuneDeployerV2() (neptune.NeptuneClientDeployerV2, *v1.AstraConnec
Namespace: "test-namespace",
},
Spec: v1.AstraConnectorSpec{
AutoSupport: v1.AutoSupport{
Enrolled: true,
URL: "https://my-asup"},
ImageRegistry: v1.ImageRegistry{
Secret: "test-secret",
},
Expand Down
3 changes: 3 additions & 0 deletions app/register/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ func createClusterRegister(astraConnectorInput AstraConnectorInput) (register.Cl
Astra: v1.Astra{
TokenRef: apiTokenSecret,
},
AutoSupport: v1.AutoSupport{
Enrolled: true,
URL: "https://my-asup"},
ImageRegistry: v1.ImageRegistry{
Name: "test-registry",
Secret: "test-secret",
Expand Down
19 changes: 19 additions & 0 deletions details/operator-sdk/api/v1/astraconnector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ type Astra struct {
Unregister bool `json:"unregister,omitempty"`
}

// AutoSupport defines how the customer interacts with NetApp ActiveIQ.
type AutoSupport struct {
// Enrolled determines if you want to send anonymous data to NetApp for support purposes.
// +kubebuilder:default:=true
Enrolled bool `json:"enrolled"`

// URL determines where the anonymous data will be sent
// +kubebuilder:default:="https://216.240.31.151/put/AsupPut-setenv"
URL string `json:"url,omitempty"`
}

type NatsSyncClient struct {
CloudBridgeURL string `json:"cloudBridgeURL,omitempty"`
// +kubebuilder:validation:Optional
Expand Down Expand Up @@ -60,6 +71,14 @@ type AstraConnectorSpec struct {
AstraConnect AstraConnect `json:"astraConnect,omitempty"`
Neptune Neptune `json:"neptune"`
ImageRegistry ImageRegistry `json:"imageRegistry,omitempty"`

// AutoSupport indicates willingness to participate in NetApp's proactive support application, NetApp Active IQ.
// An internet connection is required (port 442) and all support data is anonymized.
// The default election is true and indicates support data will be sent to NetApp.
// An empty or blank election is the same as a default election.
// Air gapped installations should enter false.
// +kubebuilder:validation:Required
AutoSupport AutoSupport `json:"autoSupport"`
}

// AstraConnectorStatus defines the observed state of AstraConnector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ var _ = Describe("Astraconnector controller", func() {
Namespace: namespace.Name,
},
Spec: v1.AstraConnectorSpec{
AutoSupport: v1.AutoSupport{
Enrolled: false,
},
ImageRegistry: v1.ImageRegistry{
Name: "test-registry",
Secret: "test-secret",
Expand Down
45 changes: 45 additions & 0 deletions details/operator-sdk/controllers/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package controllers

import (
"context"
"github.com/NetApp-Polaris/astra-connector-operator/details/k8s"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"net/http"
"sigs.k8s.io/controller-runtime/pkg/client"
"time"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -34,6 +37,16 @@ func (r *AstraConnectorController) deployConnector(ctx context.Context,
}
}

if natsSyncClientStatus.AstraConnectorID == "" {
err := createASUPCR(ctx, astraConnector, r.Client, "123")
if err != nil {
log.Error(err, FailedASUPCreation)
natsSyncClientStatus.Status = FailedASUPCreation
_ = r.updateAstraConnectorStatus(ctx, astraConnector, *natsSyncClientStatus)
return ctrl.Result{RequeueAfter: time.Minute * conf.Config.ErrorTimeout()}, err
}
}

// Let's register the cluster now
registerUtil := register.NewClusterRegisterUtil(astraConnector, &http.Client{}, r.Client, log, context.Background())
registered := false
Expand Down Expand Up @@ -122,6 +135,16 @@ func (r *AstraConnectorController) deployConnector(ctx context.Context,
natsSyncClientStatus.Status = UnregisterNSClient
}

if natsSyncClientStatus.Registered == "true" && natsSyncClientStatus.AstraConnectorID != "" {
err = createASUPCR(ctx, astraConnector, r.Client, natsSyncClientStatus.AstraConnectorID)
if err != nil {
log.Error(err, FailedASUPCreation)
natsSyncClientStatus.Status = FailedASUPCreation
_ = r.updateAstraConnectorStatus(ctx, astraConnector, *natsSyncClientStatus)
return ctrl.Result{RequeueAfter: time.Minute * conf.Config.ErrorTimeout()}, err
}
}

// No need to requeue due to success
return ctrl.Result{}, nil
}
Expand All @@ -136,3 +159,25 @@ func (r *AstraConnectorController) deleteConnectorClusterScopedResources(ctx con
r.deleteClusterScopedResources(ctx, deployer, astraConnector)
}
}

func createASUPCR(ctx context.Context, astraConnector *v1.AstraConnector, client client.Client, astraConnectorID string) error {
log := ctrllog.FromContext(ctx)
k8sUtil := k8s.NewK8sUtil(client, log)

cr := &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "management.astra.netapp.io/v1alpha1",
"kind": "AutoSupportBundleSchedule",
"metadata": map[string]interface{}{
"name": "asupbundleschedule-" + astraConnectorID,
"namespace": astraConnector.Namespace,
},
"spec": map[string]interface{}{
"enabled": astraConnector.Spec.AutoSupport.Enrolled,
},
},
}

return k8sUtil.CreateOrUpdateResource(ctx, cr, astraConnector)

}
2 changes: 2 additions & 0 deletions details/operator-sdk/controllers/neptune.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func (r *AstraConnectorController) deployNeptune(ctx context.Context,
return ctrl.Result{RequeueAfter: time.Minute * conf.Config.ErrorTimeout()}, err
}

// let's deploy the ASUP controller if user wants automatic asups

// No need to requeue due to success
return ctrl.Result{}, nil
}
1 change: 1 addition & 0 deletions details/operator-sdk/controllers/status_strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
FailedRegisterNSClient = "Failed to register natsSyncClient"
UnregisterNSClient = "Unregistered natsSyncClient"
FailedUnRegisterNSClient = "Failed to unregister natsSyncClient"
FailedASUPCreation = "Failed to create ASUP CR"

DeployedComponents = "Deployed all the connector components"
UnregisterFromAstra = "Unregistered the cluster with Astra"
Expand Down
2 changes: 2 additions & 0 deletions util/go_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func createAstraConnector() *v1.AstraConnector {
AccountId: "test-account-id",
ClusterName: "test-cluster-name",
},
AutoSupport: v1.AutoSupport{Enrolled: true,
URL: "https://my-asup"},
NatsSyncClient: v1.NatsSyncClient{
CloudBridgeURL: "test-url",
},
Expand Down
Loading