From d61712215b9ef42791337fcd2cc000ce7fbd3af7 Mon Sep 17 00:00:00 2001 From: Oscar Rodriguez Date: Tue, 4 Jun 2024 10:57:27 -0600 Subject: [PATCH 1/5] adding more resources to mutate func --- .../connector/astra_connect_natless.go | 229 ++++++++++-------- app/deployer/neptune/neptuneV2.go | 15 +- 2 files changed, 131 insertions(+), 113 deletions(-) diff --git a/app/deployer/connector/astra_connect_natless.go b/app/deployer/connector/astra_connect_natless.go index da122dd3..e6a2ab73 100644 --- a/app/deployer/connector/astra_connect_natless.go +++ b/app/deployer/connector/astra_connect_natless.go @@ -217,77 +217,85 @@ func (d *AstraConnectDeployer) GetServiceAccountObjects(m *v1.AstraConnector, ct } func (d *AstraConnectDeployer) GetClusterRoleObjects(m *v1.AstraConnector, ctx context.Context) ([]client.Object, controllerutil.MutateFn, error) { + rules := []rbacv1.PolicyRule{ + { + APIGroups: []string{""}, + Resources: []string{"namespaces", "persistentvolumes", "nodes", "pods", "services"}, + Verbs: []string{"watch", "list", "get"}, + }, + { + APIGroups: []string{"storage.k8s.io"}, + Resources: []string{"storageclasses"}, + Verbs: []string{"update", "watch", "list", "get"}, + }, + { + APIGroups: []string{"storage.k8s.io"}, + Resources: []string{"csidrivers"}, + Verbs: []string{"watch", "list", "get"}, + }, + { + APIGroups: []string{"snapshot.storage.k8s.io"}, + Resources: []string{"volumesnapshotclasses"}, + Verbs: []string{"watch", "list", "get"}, + }, + { + APIGroups: []string{"trident.netapp.io"}, + Resources: []string{"tridentversions", "tridentorchestrators"}, + Verbs: []string{"watch", "list", "get"}, + }, + { + APIGroups: []string{"astra.netapp.io"}, + Resources: []string{ + "applications", + "appmirrorrelationships", + "appmirrorupdates", + "appvaults", + "autosupportbundles", + "autosupportbundleschedules", + "backups", + "backupinplacerestores", + "backuprestores", + "exechooks", + "exechooksruns", + "kopiavolumebackups", + "kopiavolumerestores", + "pvccopies", + "pvcerases", + "resourcebackups", + "resourcedeletes", + "resourcerestores", + "resourcesummaryuploads", + "resticvolumebackups", + "resticvolumerestores", + "schedules", + "shutdownsnapshots", + "snapshots", + "snapshotinplacerestores", + "snapshotrestores", + "astraconnectors", + }, + Verbs: []string{"watch", "list", "get"}, + }, + { + APIGroups: []string{"security.openshift.io"}, + Resources: []string{"securitycontextconstraints"}, + Verbs: []string{"use"}, + }, + } + clusterRole := &rbacv1.ClusterRole{ ObjectMeta: metav1.ObjectMeta{ Name: common.AstraConnectName, }, - Rules: []rbacv1.PolicyRule{ - { - APIGroups: []string{""}, - Resources: []string{"namespaces", "persistentvolumes", "nodes", "pods", "services"}, - Verbs: []string{"watch", "list", "get"}, - }, - { - APIGroups: []string{"storage.k8s.io"}, - Resources: []string{"storageclasses"}, - Verbs: []string{"update", "watch", "list", "get"}, - }, - { - APIGroups: []string{"storage.k8s.io"}, - Resources: []string{"csidrivers"}, - Verbs: []string{"watch", "list", "get"}, - }, - { - APIGroups: []string{"snapshot.storage.k8s.io"}, - Resources: []string{"volumesnapshotclasses"}, - Verbs: []string{"watch", "list", "get"}, - }, - { - APIGroups: []string{"trident.netapp.io"}, - Resources: []string{"tridentversions", "tridentorchestrators"}, - Verbs: []string{"watch", "list", "get"}, - }, - { - APIGroups: []string{"astra.netapp.io"}, - Resources: []string{ - "applications", - "appmirrorrelationships", - "appmirrorupdates", - "appvaults", - "autosupportbundles", - "autosupportbundleschedules", - "backups", - "backupinplacerestores", - "backuprestores", - "exechooks", - "exechooksruns", - "kopiavolumebackups", - "kopiavolumerestores", - "pvccopies", - "pvcerases", - "resourcebackups", - "resourcedeletes", - "resourcerestores", - "resourcesummaryuploads", - "resticvolumebackups", - "resticvolumerestores", - "schedules", - "shutdownsnapshots", - "snapshots", - "snapshotinplacerestores", - "snapshotrestores", - "astraconnectors", - }, - Verbs: []string{"watch", "list", "get"}, - }, - { - APIGroups: []string{"security.openshift.io"}, - Resources: []string{"securitycontextconstraints"}, - Verbs: []string{"use"}, - }, - }, + Rules: rules, } - return []client.Object{clusterRole}, model.NonMutateFn, nil + + mutateFn := func() error { + clusterRole.Rules = rules + return nil + } + + return []client.Object{clusterRole}, mutateFn, nil } func (d *AstraConnectDeployer) GetClusterRoleBindingObjects(m *v1.AstraConnector, ctx context.Context) ([]client.Object, controllerutil.MutateFn, error) { @@ -313,53 +321,60 @@ func (d *AstraConnectDeployer) GetClusterRoleBindingObjects(m *v1.AstraConnector // GetRoleObjects returns a ConfigMapRole object for Astra Connect func (d *AstraConnectDeployer) GetRoleObjects(m *v1.AstraConnector, ctx context.Context) ([]client.Object, controllerutil.MutateFn, error) { + rules := []rbacv1.PolicyRule{ + { + APIGroups: []string{""}, + Resources: []string{"secrets"}, + Verbs: []string{"create", "update", "list", "get"}, + }, + { + APIGroups: []string{"astra.netapp.io"}, + Resources: []string{ + "applications", + "appmirrorrelationships", + "appmirrorupdates", + "appvaults", + "autosupportbundles", + "autosupportbundleschedules", + "backups", + "backupinplacerestores", + "backuprestores", + "exechooks", + "exechooksruns", + "pvccopies", + "pvcerases", + "resourcebackups", + "resourcedeletes", + "resourcerestores", + "resourcesummaryuploads", + "resticvolumebackups", + "resticvolumerestores", + "schedules", + "shutdownsnapshots", + "snapshots", + "snapshotinplacerestores", + "snapshotrestores", + "astraconnectors", + "kopiavolumebackups", + "kopiavolumerestores", + }, + Verbs: []string{"create", "update", "delete"}, + }, + } + role := &rbacv1.Role{ ObjectMeta: metav1.ObjectMeta{ Name: common.AstraConnectName, Namespace: m.Namespace, }, - Rules: []rbacv1.PolicyRule{ - { - APIGroups: []string{""}, - Resources: []string{"secrets"}, - Verbs: []string{"create", "update", "list", "get"}, - }, - { - APIGroups: []string{"astra.netapp.io"}, - Resources: []string{ - "applications", - "appmirrorrelationships", - "appmirrorupdates", - "appvaults", - "autosupportbundles", - "autosupportbundleschedules", - "backups", - "backupinplacerestores", - "backuprestores", - "exechooks", - "exechooksruns", - "pvccopies", - "pvcerases", - "resourcebackups", - "resourcedeletes", - "resourcerestores", - "resourcesummaryuploads", - "resticvolumebackups", - "resticvolumerestores", - "schedules", - "shutdownsnapshots", - "snapshots", - "snapshotinplacerestores", - "snapshotrestores", - "astraconnectors", - "kopiavolumebackups", - "kopiavolumerestores", - }, - Verbs: []string{"create", "update", "delete"}, - }, - }, + Rules: rules, + } + + mutateFn := func() error { + role.Rules = rules + return nil } - return []client.Object{role}, model.NonMutateFn, nil + return []client.Object{role}, mutateFn, nil } // GetRoleBindingObjects returns a ConfigMapRoleBinding object diff --git a/app/deployer/neptune/neptuneV2.go b/app/deployer/neptune/neptuneV2.go index 6577a93c..26de5476 100644 --- a/app/deployer/neptune/neptuneV2.go +++ b/app/deployer/neptune/neptuneV2.go @@ -233,13 +233,16 @@ func (n NeptuneClientDeployerV2) GetDeploymentObjects(m *v1.AstraConnector, ctx containers := deployment.Spec.Template.Spec.Containers newContainers := make([]corev1.Container, 0, 2) - for i, container := range containers { + for _, container := range containers { if container.Name == "manager" { - for j, envVar := range container.Env { - if envVar.Name == "NEPTUNE_AUTOSUPPORT_URL" { - containers[i].Env[j].Value = m.Spec.AutoSupport.URL - } - } + container.Env = getNeptuneEnvVars( + imageRegistry, + containerImage, + m.Spec.Neptune.JobImagePullPolicy, + m.Spec.ImageRegistry.Secret, + m.Spec.AutoSupport.URL, + m.Spec.Labels, + ) container.Image = neptuneImage } newContainers = append(newContainers, container) From e07cd71be9d397b2439f750ca14f8da73eb25918 Mon Sep 17 00:00:00 2001 From: Oscar Rodriguez Date: Wed, 5 Jun 2024 11:28:53 -0600 Subject: [PATCH 2/5] Changing CRD --- .../connector/astra_connect_natless.go | 7 +- app/register/register.go | 12 ++-- .../api/v1/astraconnector_types.go | 49 ++++--------- .../api/v1/zz_generated.deepcopy.go | 48 ------------- .../astra.netapp.io_astraconnectors.yaml | 52 ++++---------- .../controllers/astraconnector_controller.go | 68 +++++++++---------- details/operator-sdk/controllers/deployer.go | 16 ++--- .../controllers/natless_connector.go | 4 +- details/operator-sdk/controllers/neptune.go | 4 +- 9 files changed, 82 insertions(+), 178 deletions(-) diff --git a/app/deployer/connector/astra_connect_natless.go b/app/deployer/connector/astra_connect_natless.go index e6a2ab73..33417110 100644 --- a/app/deployer/connector/astra_connect_natless.go +++ b/app/deployer/connector/astra_connect_natless.go @@ -54,6 +54,7 @@ func (d *AstraConnectDeployer) GetDeploymentObjects(m *v1.AstraConnector, ctx co connectorImage = fmt.Sprintf("%s/astra-connector:%s", imageRegistry, containerImage) log.Info("Using AstraConnector image", "image", connectorImage) + replicaCount := int32(1) dep := &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ @@ -65,7 +66,7 @@ func (d *AstraConnectDeployer) GetDeploymentObjects(m *v1.AstraConnector, ctx co }, Spec: appsv1.DeploymentSpec{ // TODO remove option to set replica count in CRD. This should always only-ever be 1 - Replicas: &m.Spec.AstraConnect.Replicas, + Replicas: &replicaCount, Selector: &metav1.LabelSelector{ MatchLabels: ls, }, @@ -92,7 +93,7 @@ func (d *AstraConnectDeployer) GetDeploymentObjects(m *v1.AstraConnector, ctx co }, { Name: "ASTRA_CONTROL_URL", - Value: m.Spec.NatsSyncClient.CloudBridgeURL, + Value: m.Spec.Astra.AstraControlURL, }, { Name: "ACCOUNT_ID", @@ -108,7 +109,7 @@ func (d *AstraConnectDeployer) GetDeploymentObjects(m *v1.AstraConnector, ctx co }, { Name: "HOST_ALIAS_IP", - Value: m.Spec.NatsSyncClient.HostAliasIP, + Value: m.Spec.Astra.HostAliasIP, }, { Name: "SKIP_TLS_VALIDATION", diff --git a/app/register/register.go b/app/register/register.go index 701056f3..237c4ef7 100644 --- a/app/register/register.go +++ b/app/register/register.go @@ -127,8 +127,8 @@ type AstraConnector struct { func GetAstraHostURL(astraConnector *v1.AstraConnector) string { var astraHost string - if astraConnector.Spec.NatsSyncClient.CloudBridgeURL != "" { - astraHost = astraConnector.Spec.NatsSyncClient.CloudBridgeURL + if astraConnector.Spec.Astra.AstraControlURL != "" { + astraHost = astraConnector.Spec.Astra.AstraControlURL astraHost = strings.TrimSuffix(astraHost, "/") } else { astraHost = common.NatsSyncClientDefaultCloudBridgeURL @@ -160,8 +160,8 @@ func (c clusterRegisterUtil) SetHttpClient(disableTls bool, astraHost string) er c.Log.WithValues("disableTls", disableTls).Info("TLS Validation Disabled! Not for use in production!") } - if c.AstraConnector.Spec.NatsSyncClient.HostAliasIP != "" { - c.Log.WithValues("HostAliasIP", c.AstraConnector.Spec.NatsSyncClient.HostAliasIP).Info("Using the HostAlias IP") + if c.AstraConnector.Spec.Astra.HostAliasIP != "" { + c.Log.WithValues("HostAliasIP", c.AstraConnector.Spec.Astra.HostAliasIP).Info("Using the HostAlias IP") cloudBridgeHost, err := c.getAstraHostFromURL(astraHost) if err != nil { return err @@ -174,10 +174,10 @@ func (c clusterRegisterUtil) SetHttpClient(disableTls bool, astraHost string) er http.DefaultTransport.(*http.Transport).DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) { if addr == cloudBridgeHost+":443" { - addr = c.AstraConnector.Spec.NatsSyncClient.HostAliasIP + ":443" + addr = c.AstraConnector.Spec.Astra.HostAliasIP + ":443" } if addr == cloudBridgeHost+":80" { - addr = c.AstraConnector.Spec.NatsSyncClient.HostAliasIP + ":80" + addr = c.AstraConnector.Spec.Astra.HostAliasIP + ":80" } return dialer.DialContext(ctx, network, addr) } diff --git a/details/operator-sdk/api/v1/astraconnector_types.go b/details/operator-sdk/api/v1/astraconnector_types.go index 22df716c..3d0685cf 100644 --- a/details/operator-sdk/api/v1/astraconnector_types.go +++ b/details/operator-sdk/api/v1/astraconnector_types.go @@ -11,7 +11,9 @@ import ( type Astra struct { // +kubebuilder:validation:Required - AccountId string `json:"accountId"` + AccountId string `json:"accountId"` + AstraControlURL string `json:"astraControlURL,omitempty"` + // +kubebuilder:validation:Optional // +kubebuilder:validation:Required CloudId string `json:"cloudId"` // +kubebuilder:validation:Required @@ -19,6 +21,8 @@ type Astra struct { // +kubebuilder:validation:Optional ClusterName string `json:"clusterName,omitempty"` // +kubebuilder:validation:Optional + HostAliasIP string `json:"hostAliasIP,omitempty"` + // +kubebuilder:validation:Optional SkipTLSValidation bool `json:"skipTLSValidation,omitempty"` TokenRef string `json:"tokenRef,omitempty"` // +kubebuilder:validation:Optional @@ -36,30 +40,10 @@ type AutoSupport struct { URL string `json:"url,omitempty"` } -type NatsSyncClient struct { - CloudBridgeURL string `json:"cloudBridgeURL,omitempty"` - // +kubebuilder:validation:Optional - Image string `json:"image,omitempty"` - // +kubebuilder:validation:Optional - HostAliasIP string `json:"hostAliasIP,omitempty"` - // +kubebuilder:default:=1 - Replicas int32 `json:"replicas,omitempty"` -} - -// +kubebuilder:validation:Optional - -type Nats struct { - Image string `json:"image,omitempty"` - // +kubebuilder:default:=1 - Replicas int32 `json:"replicas,omitempty"` -} - // +kubebuilder:validation:Optional type AstraConnect struct { - Image string `json:"image,omitempty"` - // +kubebuilder:default:=1 - Replicas int32 `json:"replicas,omitempty"` + Image string `json:"image,omitempty"` ResourceRequirements corev1.ResourceRequirements `json:"resources,omitempty"` } @@ -73,12 +57,10 @@ type Neptune struct { // AstraConnectorSpec defines the desired state of AstraConnector type AstraConnectorSpec struct { - Astra Astra `json:"astra"` - NatsSyncClient NatsSyncClient `json:"natsSyncClient,omitempty"` - Nats Nats `json:"nats,omitempty"` - AstraConnect AstraConnect `json:"astraConnect,omitempty"` - Neptune Neptune `json:"neptune"` - ImageRegistry ImageRegistry `json:"imageRegistry,omitempty"` + Astra Astra `json:"astra"` + 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. @@ -98,11 +80,6 @@ type AstraConnectorSpec struct { // AstraConnectorStatus defines the observed state of AstraConnector type AstraConnectorStatus struct { - NatsSyncClient NatsSyncClientStatus `json:"natsSyncClient"` -} - -// NatsSyncClientStatus defines the observed state of NatsSyncClient -type NatsSyncClientStatus struct { Registered string `json:"registered"` //todo cluster vs connector registered AstraClusterId string `json:"astraClusterID,omitempty"` Status string `json:"status"` @@ -117,9 +94,9 @@ type ImageRegistry struct { //+kubebuilder:object:root=true //+kubebuilder:subresource:status -//+kubebuilder:printcolumn:name="Registered",type=string,JSONPath=`.status.natsSyncClient.registered` -//+kubebuilder:printcolumn:name="AstraClusterID",type=string,JSONPath=`.status.natsSyncClient.astraClusterID` -//+kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.natsSyncClient.status` +//+kubebuilder:printcolumn:name="Registered",type=string,JSONPath=`.status.registered` +//+kubebuilder:printcolumn:name="AstraClusterID",type=string,JSONPath=`.status.astraClusterID` +//+kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.status` // AstraConnector is the Schema for the astraconnectors API // +kubebuilder:subresource:status diff --git a/details/operator-sdk/api/v1/zz_generated.deepcopy.go b/details/operator-sdk/api/v1/zz_generated.deepcopy.go index aefea291..a88b764a 100644 --- a/details/operator-sdk/api/v1/zz_generated.deepcopy.go +++ b/details/operator-sdk/api/v1/zz_generated.deepcopy.go @@ -107,8 +107,6 @@ func (in *AstraConnectorList) DeepCopyObject() runtime.Object { func (in *AstraConnectorSpec) DeepCopyInto(out *AstraConnectorSpec) { *out = *in out.Astra = in.Astra - out.NatsSyncClient = in.NatsSyncClient - out.Nats = in.Nats in.AstraConnect.DeepCopyInto(&out.AstraConnect) in.Neptune.DeepCopyInto(&out.Neptune) out.ImageRegistry = in.ImageRegistry @@ -135,7 +133,6 @@ func (in *AstraConnectorSpec) DeepCopy() *AstraConnectorSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *AstraConnectorStatus) DeepCopyInto(out *AstraConnectorStatus) { *out = *in - out.NatsSyncClient = in.NatsSyncClient } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AstraConnectorStatus. @@ -178,51 +175,6 @@ func (in *ImageRegistry) DeepCopy() *ImageRegistry { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Nats) DeepCopyInto(out *Nats) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Nats. -func (in *Nats) DeepCopy() *Nats { - if in == nil { - return nil - } - out := new(Nats) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *NatsSyncClient) DeepCopyInto(out *NatsSyncClient) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NatsSyncClient. -func (in *NatsSyncClient) DeepCopy() *NatsSyncClient { - if in == nil { - return nil - } - out := new(NatsSyncClient) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *NatsSyncClientStatus) DeepCopyInto(out *NatsSyncClientStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NatsSyncClientStatus. -func (in *NatsSyncClientStatus) DeepCopy() *NatsSyncClientStatus { - if in == nil { - return nil - } - out := new(NatsSyncClientStatus) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Neptune) DeepCopyInto(out *Neptune) { *out = *in diff --git a/details/operator-sdk/config/crd/bases/astra.netapp.io_astraconnectors.yaml b/details/operator-sdk/config/crd/bases/astra.netapp.io_astraconnectors.yaml index 9011d05c..b73f3c4a 100644 --- a/details/operator-sdk/config/crd/bases/astra.netapp.io_astraconnectors.yaml +++ b/details/operator-sdk/config/crd/bases/astra.netapp.io_astraconnectors.yaml @@ -17,13 +17,13 @@ spec: scope: Namespaced versions: - additionalPrinterColumns: - - jsonPath: .status.natsSyncClient.registered + - jsonPath: .status.registered name: Registered type: string - - jsonPath: .status.natsSyncClient.astraClusterID + - jsonPath: .status.astraClusterID name: AstraClusterID type: string - - jsonPath: .status.natsSyncClient.status + - jsonPath: .status.status name: Status type: string name: v1 @@ -50,12 +50,16 @@ spec: properties: accountId: type: string + astraURL: + type: string cloudId: type: string clusterId: type: string clusterName: type: string + hostAliasIP: + type: string skipTLSValidation: type: boolean tokenRef: @@ -71,10 +75,6 @@ spec: properties: image: type: string - replicas: - default: 1 - format: int32 - type: integer resources: description: ResourceRequirements describes the compute resource requirements. @@ -159,28 +159,6 @@ spec: type: string description: Labels any additional labels wanted to be added to resources type: object - nats: - properties: - image: - type: string - replicas: - default: 1 - format: int32 - type: integer - type: object - natsSyncClient: - properties: - cloudBridgeURL: - type: string - hostAliasIP: - type: string - image: - type: string - replicas: - default: 1 - format: int32 - type: integer - type: object neptune: description: Neptune properties: @@ -248,16 +226,12 @@ spec: status: description: AstraConnectorStatus defines the observed state of AstraConnector properties: - natsSyncClient: - description: NatsSyncClientStatus defines the observed state of NatsSyncClient - properties: - astraClusterID: - type: string - registered: - type: string - status: - type: string - type: object + astraClusterID: + type: string + registered: + type: string + status: + type: string type: object type: object served: true diff --git a/details/operator-sdk/controllers/astraconnector_controller.go b/details/operator-sdk/controllers/astraconnector_controller.go index d9b1cb15..bd2647c1 100644 --- a/details/operator-sdk/controllers/astraconnector_controller.go +++ b/details/operator-sdk/controllers/astraconnector_controller.go @@ -69,7 +69,7 @@ func (r *AstraConnectorController) Reconcile(ctx context.Context, req ctrl.Reque } // Error reading the object - requeue the request. log.Error(err, FailedAstraConnectorGet) - _ = r.updateAstraConnectorStatus(ctx, astraConnector, v1.NatsSyncClientStatus{ + _ = r.updateAstraConnectorStatus(ctx, astraConnector, v1.AstraConnectorStatus{ Status: FailedAstraConnectorGet, Registered: "false", }) @@ -77,11 +77,11 @@ func (r *AstraConnectorController) Reconcile(ctx context.Context, req ctrl.Reque return ctrl.Result{}, err } - natsSyncClientStatus := astraConnector.Status.NatsSyncClient - natsSyncClientStatus.AstraClusterId = astraConnector.Status.NatsSyncClient.AstraClusterId + astraConnectorStatus := astraConnector.Status + astraConnectorStatus.AstraClusterId = astraConnector.Status.AstraClusterId - if natsSyncClientStatus.Registered == "" { - natsSyncClientStatus.Registered = "false" + if astraConnectorStatus.Registered == "" { + astraConnectorStatus.Registered = "false" } // Validate AstraConnector CR for any errors @@ -89,8 +89,8 @@ func (r *AstraConnectorController) Reconcile(ctx context.Context, req ctrl.Reque if err != nil { // Error validating the connector object. Do not requeue and update the connector status. log.Error(err, FailedAstraConnectorValidation) - natsSyncClientStatus.Status = fmt.Sprintf("%s; %s", FailedAstraConnectorValidation, err.Error()) - _ = r.updateAstraConnectorStatus(ctx, astraConnector, natsSyncClientStatus) + astraConnectorStatus.Status = fmt.Sprintf("%s; %s", FailedAstraConnectorValidation, err.Error()) + _ = r.updateAstraConnectorStatus(ctx, astraConnector, astraConnectorStatus) // Do not requeue. This is a user input error return ctrl.Result{}, err } @@ -106,8 +106,8 @@ func (r *AstraConnectorController) Reconcile(ctx context.Context, req ctrl.Reque log.Info("Adding finalizer to AstraConnector instance", "finalizerName", finalizerName) controllerutil.AddFinalizer(astraConnector, finalizerName) if err := r.Update(ctx, astraConnector); err != nil { - natsSyncClientStatus.Status = FailedFinalizerAdd - _ = r.updateAstraConnectorStatus(ctx, astraConnector, natsSyncClientStatus) + astraConnectorStatus.Status = FailedFinalizerAdd + _ = r.updateAstraConnectorStatus(ctx, astraConnector, astraConnectorStatus) return ctrl.Result{}, err } // spec change this will trigger a reconcile @@ -117,8 +117,8 @@ func (r *AstraConnectorController) Reconcile(ctx context.Context, req ctrl.Reque // The object is being deleted if controllerutil.ContainsFinalizer(astraConnector, finalizerName) { // Update status message to indicate that CR delete is in progress - natsSyncClientStatus.Status = DeleteInProgress - _ = r.updateAstraConnectorStatus(ctx, astraConnector, natsSyncClientStatus) + astraConnectorStatus.Status = DeleteInProgress + _ = r.updateAstraConnectorStatus(ctx, astraConnector, astraConnectorStatus) // delete any cluster scoped resources created by the operator r.deleteConnectorClusterScopedResources(ctx, astraConnector) @@ -126,15 +126,15 @@ func (r *AstraConnectorController) Reconcile(ctx context.Context, req ctrl.Reque // remove our finalizer from the list and update it. controllerutil.RemoveFinalizer(astraConnector, finalizerName) if err := r.Update(ctx, astraConnector); err != nil { - natsSyncClientStatus.Status = FailedFinalizerRemove - _ = r.updateAstraConnectorStatus(ctx, astraConnector, natsSyncClientStatus) + astraConnectorStatus.Status = FailedFinalizerRemove + _ = r.updateAstraConnectorStatus(ctx, astraConnector, astraConnectorStatus) // Do not requeue. Item is being deleted return ctrl.Result{}, err } // Update status message to indicate that CR delete is in finished - natsSyncClientStatus.Status = DeletionComplete - _ = r.updateAstraConnectorStatus(ctx, astraConnector, natsSyncClientStatus) + astraConnectorStatus.Status = DeletionComplete + _ = r.updateAstraConnectorStatus(ctx, astraConnector, astraConnectorStatus) } // Stop reconciliation as the item is being deleted @@ -158,8 +158,8 @@ func (r *AstraConnectorController) Reconcile(ctx context.Context, req ctrl.Reque errString = errString + err.Error() } errString = "Pre-check errors: " + errString - natsSyncClientStatus.Status = errString - _ = r.updateAstraConnectorStatus(ctx, astraConnector, natsSyncClientStatus) + astraConnectorStatus.Status = errString + _ = r.updateAstraConnectorStatus(ctx, astraConnector, astraConnectorStatus) // Do not requeue. Item is being deleted return ctrl.Result{}, errors.New(errString) } @@ -168,7 +168,7 @@ func (r *AstraConnectorController) Reconcile(ctx context.Context, req ctrl.Reque // deploy Neptune if conf.Config.FeatureFlags().DeployNeptune() { log.Info("Initiating Neptune deployment") - neptuneResult, err := r.deployNeptune(ctx, astraConnector, &natsSyncClientStatus) + neptuneResult, err := r.deployNeptune(ctx, astraConnector, &astraConnectorStatus) if err != nil { // Note: Returning nil in error since we want to wait for the requeue to happen // non nil errors triggers the requeue right away @@ -182,16 +182,16 @@ func (r *AstraConnectorController) Reconcile(ctx context.Context, req ctrl.Reque var connectorResults ctrl.Result var deployError error - connectorResults, deployError = r.deployNatlessConnector(ctx, astraConnector, &natsSyncClientStatus) + connectorResults, deployError = r.deployNatlessConnector(ctx, astraConnector, &astraConnectorStatus) // Wait for the cluster to become managed (aka "registered") - natsSyncClientStatus.Status = WaitForClusterManagedState - _ = r.updateAstraConnectorStatus(ctx, astraConnector, natsSyncClientStatus) + astraConnectorStatus.Status = WaitForClusterManagedState + _ = r.updateAstraConnectorStatus(ctx, astraConnector, astraConnectorStatus) isManaged, err := waitForManagedCluster(astraConnector, r.Client, log) if !isManaged { log.Error(err, "timed out waiting for cluster to become managed, requeueing after delay", "delay", conf.Config.ErrorTimeout()) - natsSyncClientStatus.Status = ErrorClusterUnmanaged - _ = r.updateAstraConnectorStatus(ctx, astraConnector, natsSyncClientStatus) + astraConnectorStatus.Status = ErrorClusterUnmanaged + _ = r.updateAstraConnectorStatus(ctx, astraConnector, astraConnectorStatus) // Do not wait 5min, wait 5sec before requeue instead since we have already been waiting in waitForManagedCluster return ctrl.Result{RequeueAfter: time.Second * conf.Config.ErrorTimeout()}, nil } @@ -201,15 +201,15 @@ func (r *AstraConnectorController) Reconcile(ctx context.Context, req ctrl.Reque err = r.createASUPCR(ctx, astraConnector, astraConnector.Spec.Astra.ClusterId) if err != nil { log.Error(err, FailedASUPCreation) - natsSyncClientStatus.Status = FailedASUPCreation - _ = r.updateAstraConnectorStatus(ctx, astraConnector, natsSyncClientStatus) + astraConnectorStatus.Status = FailedASUPCreation + _ = r.updateAstraConnectorStatus(ctx, astraConnector, astraConnectorStatus) return ctrl.Result{RequeueAfter: time.Minute * conf.Config.ErrorTimeout()}, err } - natsSyncClientStatus.Registered = "true" - natsSyncClientStatus.AstraClusterId = astraConnector.Spec.Astra.ClusterId - natsSyncClientStatus.Status = RegisteredWithAstra - _ = r.updateAstraConnectorStatus(ctx, astraConnector, natsSyncClientStatus) + astraConnectorStatus.Registered = "true" + astraConnectorStatus.AstraClusterId = astraConnector.Spec.Astra.ClusterId + astraConnectorStatus.Status = RegisteredWithAstra + _ = r.updateAstraConnectorStatus(ctx, astraConnector, astraConnectorStatus) if deployError != nil { // Note: Returning nil in error since we want to wait for the requeue to happen @@ -219,11 +219,11 @@ func (r *AstraConnectorController) Reconcile(ctx context.Context, req ctrl.Reque } } - if natsSyncClientStatus.AstraClusterId != "" { - log.Info(fmt.Sprintf("Updating CR status, clusterID: '%s'", natsSyncClientStatus.AstraClusterId)) + if astraConnectorStatus.AstraClusterId != "" { + log.Info(fmt.Sprintf("Updating CR status, clusterID: '%s'", astraConnectorStatus.AstraClusterId)) } - _ = r.updateAstraConnectorStatus(ctx, astraConnector, natsSyncClientStatus) + _ = r.updateAstraConnectorStatus(ctx, astraConnector, astraConnectorStatus) err = r.waitForStatusUpdate(astraConnector, log) if err != nil { log.Error(err, "Failed to update status, ignoring since this will be fixed on a future reconcile.") @@ -235,11 +235,11 @@ func (r *AstraConnectorController) Reconcile(ctx context.Context, req ctrl.Reque func (r *AstraConnectorController) updateAstraConnectorStatus( ctx context.Context, astraConnector *v1.AstraConnector, - natsSyncClientStatus v1.NatsSyncClientStatus) error { + newAstraConnectorStatus v1.AstraConnectorStatus) error { // due to conflicts with network or changing object we need to retry on conflict return retry.RetryOnConflict(retry.DefaultRetry, func() error { - astraConnector.Status.NatsSyncClient = natsSyncClientStatus + astraConnector.Status = newAstraConnectorStatus // Update the status err := r.Status().Update(ctx, astraConnector) diff --git a/details/operator-sdk/controllers/deployer.go b/details/operator-sdk/controllers/deployer.go index c0397788..1fa68517 100644 --- a/details/operator-sdk/controllers/deployer.go +++ b/details/operator-sdk/controllers/deployer.go @@ -44,7 +44,7 @@ var resources = []createResourceParams{ {createMessage: CreateDeployment, errorMessage: ErrorCreateDeployments, getResource: model.Deployer.GetDeploymentObjects, clusterScope: false}, } -func (r *AstraConnectorController) deployResources(ctx context.Context, deployer model.Deployer, astraConnector *installer.AstraConnector, natsSyncClientStatus *installer.NatsSyncClientStatus) error { +func (r *AstraConnectorController) deployResources(ctx context.Context, deployer model.Deployer, astraConnector *installer.AstraConnector, astraConnectorStatus *installer.AstraConnectorStatus) error { log := ctrllog.FromContext(ctx) k8sUtil := k8s.NewK8sUtil(r.Client, r.Clientset, log) @@ -62,18 +62,18 @@ func (r *AstraConnectorController) deployResources(ctx context.Context, deployer key := client.ObjectKeyFromObject(kubeObject) statusMsg := fmt.Sprintf(funcList.createMessage, key.Namespace, key.Name) log.Info(statusMsg) - natsSyncClientStatus.Status = statusMsg - _ = r.updateAstraConnectorStatus(ctx, astraConnector, *natsSyncClientStatus) + astraConnectorStatus.Status = statusMsg + _ = r.updateAstraConnectorStatus(ctx, astraConnector, *astraConnectorStatus) result, err := k8sUtil.CreateOrUpdateResource(ctx, kubeObject, astraConnector, mutateFunc) if err != nil { - return r.formatError(ctx, astraConnector, log, funcList.errorMessage, key.Namespace, key.Name, err, natsSyncClientStatus) + return r.formatError(ctx, astraConnector, log, funcList.errorMessage, key.Namespace, key.Name, err, astraConnectorStatus) } else { waitCtx, cancel := context.WithCancel(ctx) defer cancel() err = r.waitForResourceReady(waitCtx, kubeObject, astraConnector) if err != nil { - return r.formatError(ctx, astraConnector, log, funcList.errorMessage, key.Namespace, key.Name, err, natsSyncClientStatus) + return r.formatError(ctx, astraConnector, log, funcList.errorMessage, key.Namespace, key.Name, err, astraConnectorStatus) } log.Info(fmt.Sprintf("Successfully %s resources", result)) } @@ -158,10 +158,10 @@ func (r *AstraConnectorController) waitForResourceReady(ctx context.Context, kub func (r *AstraConnectorController) formatError(ctx context.Context, astraConnector *installer.AstraConnector, log logr.Logger, errorMessage, namespace, name string, err error, - natsSyncClientStatus *installer.NatsSyncClientStatus) error { + astraConnectorStatus *installer.AstraConnectorStatus) error { statusMsg := fmt.Sprintf(errorMessage, namespace, name) - natsSyncClientStatus.Status = statusMsg - _ = r.updateAstraConnectorStatus(ctx, astraConnector, *natsSyncClientStatus) + astraConnectorStatus.Status = statusMsg + _ = r.updateAstraConnectorStatus(ctx, astraConnector, *astraConnectorStatus) log.Error(err, statusMsg) return errors.Wrapf(err, statusMsg) } diff --git a/details/operator-sdk/controllers/natless_connector.go b/details/operator-sdk/controllers/natless_connector.go index 2de8789d..6d16da92 100644 --- a/details/operator-sdk/controllers/natless_connector.go +++ b/details/operator-sdk/controllers/natless_connector.go @@ -17,13 +17,13 @@ import ( ) func (r *AstraConnectorController) deployNatlessConnector(ctx context.Context, - astraConnector *v1.AstraConnector, natsSyncClientStatus *v1.NatsSyncClientStatus) (ctrl.Result, error) { + astraConnector *v1.AstraConnector, astraConnectorStatus *v1.AstraConnectorStatus) (ctrl.Result, error) { log := ctrllog.FromContext(ctx) // let's deploy Astra Connector without Nats connectorDeployers := getDeployers() for _, deployer := range connectorDeployers { - err := r.deployResources(ctx, deployer, astraConnector, natsSyncClientStatus) + err := r.deployResources(ctx, deployer, astraConnector, astraConnectorStatus) if err != nil { // Failed deploying we want status to reflect that for at least 30 seconds before it's requeued so // anyone watching can be informed diff --git a/details/operator-sdk/controllers/neptune.go b/details/operator-sdk/controllers/neptune.go index d4cb1da8..0b84a975 100644 --- a/details/operator-sdk/controllers/neptune.go +++ b/details/operator-sdk/controllers/neptune.go @@ -12,14 +12,14 @@ import ( ) func (r *AstraConnectorController) deployNeptune(ctx context.Context, - astraConnector *v1.AstraConnector, natsSyncClientStatus *v1.NatsSyncClientStatus) (ctrl.Result, error) { + astraConnector *v1.AstraConnector, astraConnectorStatus *v1.AstraConnectorStatus) (ctrl.Result, error) { // TODO CRD will be installed as part of our crd install // check if they are installed if not error here or maybe a pre-check // Deploy Neptune neptuneDeployer := neptune.NewNeptuneClientDeployerV2() - err := r.deployResources(ctx, neptuneDeployer, astraConnector, natsSyncClientStatus) + err := r.deployResources(ctx, neptuneDeployer, astraConnector, astraConnectorStatus) if err != nil { // Failed deploying we want status to reflect that for at least 30 seconds before it's requeued so // anyone watching can be informed From f778a7199b987de99d8deec2ffdacb8f3666c264 Mon Sep 17 00:00:00 2001 From: Oscar Rodriguez Date: Wed, 5 Jun 2024 13:45:43 -0600 Subject: [PATCH 3/5] remove nats everywhere --- .config.yaml.sample | 2 +- README.md | 3 +- app/conf/config.go | 20 ++-- app/conf/config_test.go | 4 +- .../connector/astra_connect_natless.go | 20 ++-- app/deployer/connector/astra_connect_test.go | 4 +- app/register/register.go | 2 +- app/register/register_test.go | 4 +- common/constants.go | 21 +--- .../samples/astra_v1_astraconnector.yaml | 3 +- .../controllers/astraconnector_controller.go | 4 +- .../controllers/natless_connector.go | 2 +- .../controllers/status_strings.go | 6 +- scripts/create_default_images_manifest.go | 2 - scripts/oscar_get_cluster_cloud_id.sh | 97 +++++++++++++++++++ unified-installer/astra-unified-installer.sh | 7 +- unified-installer/tmp.sh | 8 ++ util/go_util_test.go | 14 ++- 18 files changed, 148 insertions(+), 75 deletions(-) create mode 100755 scripts/oscar_get_cluster_cloud_id.sh create mode 100755 unified-installer/tmp.sh diff --git a/.config.yaml.sample b/.config.yaml.sample index 4ee176bf..69872474 100644 --- a/.config.yaml.sample +++ b/.config.yaml.sample @@ -16,6 +16,6 @@ HealthProbePort: 8083 # Enable/Disable features. FeatureFlags: - DeployNatsConnector: true + DeployConnector: true DeployNeptune: false SkipAstraRegistration: false diff --git a/README.md b/README.md index 88d9faa2..d63562f4 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,7 @@ This guide provides instructions for installing the latest version of the Astra clusterName: skipTLSValidation: false # Should be set to false in production environments tokenRef: astra-token - natsSyncClient: - cloudBridgeURL: + astraControlURL: hostAliasIP: imageRegistry: name: cr.astra.netapp.io/astra diff --git a/app/conf/config.go b/app/conf/config.go index 00402751..dad2e08e 100644 --- a/app/conf/config.go +++ b/app/conf/config.go @@ -78,8 +78,8 @@ func DefaultConfiguration() *MutableConfiguration { WaitDurationForResource: 5 * time.Minute, ErrorTimeout: 5, FeatureFlags: featureFlags{ - DeployNatsConnector: true, - DeployNeptune: true, + DeployConnector: true, + DeployNeptune: true, }, } } @@ -95,8 +95,8 @@ func toImmutableConfig(config *MutableConfiguration) *ImmutableConfiguration { waitDurationForResource: config.WaitDurationForResource, errorTimeout: config.ErrorTimeout, featureFlags: ImmutableFeatureFlags{ - deployNatsConnector: config.FeatureFlags.DeployNatsConnector, - deployNeptune: config.FeatureFlags.DeployNeptune, + deployConnector: config.FeatureFlags.DeployConnector, + deployNeptune: config.FeatureFlags.DeployNeptune, }, config: config, } @@ -142,17 +142,17 @@ func (i ImmutableConfiguration) FeatureFlags() ImmutableFeatureFlags { } type ImmutableFeatureFlags struct { - deployNatsConnector bool - deployNeptune bool + deployConnector bool + deployNeptune bool } type featureFlags struct { - DeployNatsConnector bool - DeployNeptune bool + DeployConnector bool + DeployNeptune bool } -func (f ImmutableFeatureFlags) DeployNatsConnector() bool { - return f.deployNatsConnector +func (f ImmutableFeatureFlags) DeployConnector() bool { + return f.deployConnector } func (f ImmutableFeatureFlags) DeployNeptune() bool { diff --git a/app/conf/config_test.go b/app/conf/config_test.go index 0c1d1499..2eaaae08 100644 --- a/app/conf/config_test.go +++ b/app/conf/config_test.go @@ -40,8 +40,8 @@ func TestImmutableFeatureFlags(t *testing.T) { // Initialize a test feature flag configuration flags := conf.ImmutableFeatureFlags{} - if flags.DeployNatsConnector() != false { - t.Errorf("Expected true, got %v", flags.DeployNatsConnector()) + if flags.DeployConnector() != false { + t.Errorf("Expected true, got %v", flags.DeployConnector()) } if flags.DeployNeptune() != false { diff --git a/app/deployer/connector/astra_connect_natless.go b/app/deployer/connector/astra_connect_natless.go index c9819698..e87dbcb2 100644 --- a/app/deployer/connector/astra_connect_natless.go +++ b/app/deployer/connector/astra_connect_natless.go @@ -82,10 +82,6 @@ func (d *AstraConnectDeployer) GetDeploymentObjects(m *v1.AstraConnector, ctx co Name: "LOG_LEVEL", // todo should this match what operator is Value: "info", }, - { - Name: "NATS_DISABLED", - Value: "true", - }, { Name: "API_TOKEN_SECRET_REF", Value: m.Spec.Astra.TokenRef, @@ -192,17 +188,23 @@ func (d *AstraConnectDeployer) GetServiceObjects(m *v1.AstraConnector, ctx conte // GetConfigMapObjects returns a ConfigMap object for Astra Connect func (d *AstraConnectDeployer) GetConfigMapObjects(m *v1.AstraConnector, ctx context.Context) ([]client.Object, controllerutil.MutateFn, error) { + data := map[string]string{ + "skip_tls_validation": strconv.FormatBool(m.Spec.Astra.SkipTLSValidation), + } + configMap := &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Namespace: m.Namespace, Name: common.AstraConnectName, }, - Data: map[string]string{ - //"nats_url": GetNatsURL(m), - "skip_tls_validation": strconv.FormatBool(m.Spec.Astra.SkipTLSValidation), - }, + Data: data, + } + + mutateFn := func() error { + configMap.Data = data + return nil } - return []client.Object{configMap}, model.NonMutateFn, nil + return []client.Object{configMap}, mutateFn, nil } // GetServiceAccountObjects returns a ServiceAccount object for Astra Connect diff --git a/app/deployer/connector/astra_connect_test.go b/app/deployer/connector/astra_connect_test.go index 0ff0d242..d37b2990 100644 --- a/app/deployer/connector/astra_connect_test.go +++ b/app/deployer/connector/astra_connect_test.go @@ -61,7 +61,6 @@ func TestAstraConnectGetDeploymentObjects(t *testing.T) { assert.Equal(t, 10, len(container.Env)) assert.Equal(t, "LOG_LEVEL", container.Env[0].Name) - assert.Equal(t, "NATS_DISABLED", container.Env[1].Name) assert.Equal(t, "true", container.Env[1].Value) assert.Equal(t, 1, len(deployment.Spec.Template.Spec.ImagePullSecrets)) @@ -80,8 +79,7 @@ func DummyAstraConnector() v1.AstraConnector { Secret: "test-secret", }, AstraConnect: v1.AstraConnect{ - Image: "test-image", - Replicas: 1, + Image: "test-image", }, AutoSupport: v1.AutoSupport{ Enrolled: true, diff --git a/app/register/register.go b/app/register/register.go index 237c4ef7..4bf8dce2 100644 --- a/app/register/register.go +++ b/app/register/register.go @@ -131,7 +131,7 @@ func GetAstraHostURL(astraConnector *v1.AstraConnector) string { astraHost = astraConnector.Spec.Astra.AstraControlURL astraHost = strings.TrimSuffix(astraHost, "/") } else { - astraHost = common.NatsSyncClientDefaultCloudBridgeURL + astraHost = common.DefaultCloudAstraControlURL } return astraHost diff --git a/app/register/register_test.go b/app/register/register_test.go index 621464c0..47c43fa5 100644 --- a/app/register/register_test.go +++ b/app/register/register_test.go @@ -102,8 +102,8 @@ func createClusterRegister(astraConnectorInput AstraConnectorInput) (register.Cl } if astraConnectorInput.invalidHostDetails { - astraConnector.Spec.NatsSyncClient.CloudBridgeURL = testURL - astraConnector.Spec.NatsSyncClient.HostAliasIP = testIP + astraConnector.Spec.Astra.AstraControlURL = testURL + astraConnector.Spec.Astra.HostAliasIP = testIP } clusterRegisterUtil := register.NewClusterRegisterUtil(astraConnector, mockHttpClient, fakeClient, k8sUtil, log, context.Background()) diff --git a/common/constants.go b/common/constants.go index 22be003b..ea84dab6 100644 --- a/common/constants.go +++ b/common/constants.go @@ -7,8 +7,6 @@ package common import ( _ "embed" "strings" - - "github.com/NetApp-Polaris/astra-connector-operator/app/conf" ) const ( @@ -18,8 +16,7 @@ const ( AstraConnectName = "astraconnect" AstraConnectorOperatorRepository = "netapp/astra-connector-operator" - NatsSyncClientDefaultImage = "natssync-client:2.2.202402012115" - NatsSyncClientDefaultCloudBridgeURL = "https://astra.netapp.io" + DefaultCloudAstraControlURL = "https://astra.netapp.io" NeptuneName = "neptune-controller-manager" @@ -27,10 +24,6 @@ const ( NeptuneMetricServiceProtocol = "TCP" NeptuneReplicas = 1 - ConnectorNeptuneCapability = "neptuneV1" - ConnectorV2Capability = "connectorV2" // V2 refers specifically to Arch 3.0 connector and beyond - ConnectorWatcherCapability = "watcherV1" - RbacProxyImage = "kube-rbac-proxy:v0.14.1" ) @@ -55,15 +48,3 @@ var ( func GetNeptuneRepositories() []string { return []string{"controller", "exechook", "resourcebackup", "resourcedelete", "resourcerestore", "resourcesummaryupload", "restic"} } - -func GetConnectorCapabilities() []string { - capabilities := []string{ - ConnectorV2Capability, - ConnectorWatcherCapability, - } - - if conf.Config.FeatureFlags().DeployNeptune() { - capabilities = append(capabilities, ConnectorNeptuneCapability) - } - return capabilities -} diff --git a/details/operator-sdk/config/samples/astra_v1_astraconnector.yaml b/details/operator-sdk/config/samples/astra_v1_astraconnector.yaml index f46e6dc7..38f43fc5 100644 --- a/details/operator-sdk/config/samples/astra_v1_astraconnector.yaml +++ b/details/operator-sdk/config/samples/astra_v1_astraconnector.yaml @@ -9,6 +9,5 @@ spec: accountId: Astra Account ID from the API Access page in Astra UI skipTLSValidation: true clusterName: Name of your cluster - natsSyncClient: - cloudBridgeURL: https://integration.astra.netapp.io + astraControlURL: https://integration.astra.netapp.io hostAliasIP: 10.193.60.80 diff --git a/details/operator-sdk/controllers/astraconnector_controller.go b/details/operator-sdk/controllers/astraconnector_controller.go index bd2647c1..a4a5e5d5 100644 --- a/details/operator-sdk/controllers/astraconnector_controller.go +++ b/details/operator-sdk/controllers/astraconnector_controller.go @@ -177,7 +177,7 @@ func (r *AstraConnectorController) Reconcile(ctx context.Context, req ctrl.Reque } } - if conf.Config.FeatureFlags().DeployNatsConnector() { + if conf.Config.FeatureFlags().DeployConnector() { log.Info("Initiating Connector deployment") var connectorResults ctrl.Result var deployError error @@ -214,7 +214,7 @@ func (r *AstraConnectorController) Reconcile(ctx context.Context, req ctrl.Reque if deployError != nil { // Note: Returning nil in error since we want to wait for the requeue to happen // non nil errors triggers the requeue right away - log.Error(err, "Error deploying NatsConnector, requeueing after delay", "delay", conf.Config.ErrorTimeout()) + log.Error(err, "Error deploying Connector, requeueing after delay", "delay", conf.Config.ErrorTimeout()) return connectorResults, nil } } diff --git a/details/operator-sdk/controllers/natless_connector.go b/details/operator-sdk/controllers/natless_connector.go index 6d16da92..263fe292 100644 --- a/details/operator-sdk/controllers/natless_connector.go +++ b/details/operator-sdk/controllers/natless_connector.go @@ -20,7 +20,7 @@ func (r *AstraConnectorController) deployNatlessConnector(ctx context.Context, astraConnector *v1.AstraConnector, astraConnectorStatus *v1.AstraConnectorStatus) (ctrl.Result, error) { log := ctrllog.FromContext(ctx) - // let's deploy Astra Connector without Nats + // let's deploy Astra Connector connectorDeployers := getDeployers() for _, deployer := range connectorDeployers { err := r.deployResources(ctx, deployer, astraConnector, astraConnectorStatus) diff --git a/details/operator-sdk/controllers/status_strings.go b/details/operator-sdk/controllers/status_strings.go index e0efede4..7bd7b582 100644 --- a/details/operator-sdk/controllers/status_strings.go +++ b/details/operator-sdk/controllers/status_strings.go @@ -32,11 +32,7 @@ const ( FailedAstraConnectorGet = "Failed to get AstraConnector" FailedAstraConnectorValidation = "Failed to validate AstraConnector" - FailedLocationIDGet = "Failed to get the locationID from ConfigMap" - EmptyLocationIDGet = "Got an empty location ID from ConfigMap" - - FailedUnRegisterNSClient = "Failed to unregister natsSyncClient" - FailedASUPCreation = "Failed to create ASUP CR" + FailedASUPCreation = "Failed to create ASUP CR" DeployedComponents = "Deployed all the connector components" RegisteredWithAstra = "Registered with Astra" diff --git a/scripts/create_default_images_manifest.go b/scripts/create_default_images_manifest.go index 8c7bca18..91a91886 100644 --- a/scripts/create_default_images_manifest.go +++ b/scripts/create_default_images_manifest.go @@ -33,8 +33,6 @@ func main() { // Connector images images := []string{ fmt.Sprintf("%s/astra-connector:%s", defaultImageRegistry, common.ConnectorImageTag), - fmt.Sprintf("%s/%s", defaultImageRegistry, common.NatsSyncClientDefaultImage), - // fmt.Sprintf("%s/%s", defaultImageRegistry, common.NatsDefaultImage), fmt.Sprintf("%s:%s", common.AstraConnectorOperatorRepository, connectorOperatorVersion), fmt.Sprintf("%s/trident-autosupport:%s", defaultImageRegistry, common.AsupImageTag), fmt.Sprintf("%s/%s", defaultImageRegistry, common.RbacProxyImage), diff --git a/scripts/oscar_get_cluster_cloud_id.sh b/scripts/oscar_get_cluster_cloud_id.sh new file mode 100755 index 00000000..4ebbb326 --- /dev/null +++ b/scripts/oscar_get_cluster_cloud_id.sh @@ -0,0 +1,97 @@ +#!/bin/bash + +## Please fill this out +astra_url="https://dev-ol-astra-enterprise-team3-03-lb.rtp.openenglab.netapp.com" +account_id="bb22ca62-48ad-4697-a4d3-64bded53d849" +auth_token="gmiQt963pM9iRC2E-6a5EwuUzkT5w2iIk87_ca6x-DM=" +cluster_name="bobby" + +# Define the base URL and headers for convenience +base_url="${astra_url}/accounts/${account_id}/topology/v1/clouds" +accept_header="accept: application/json" +auth_header="Authorization: Bearer ${auth_token}" +cluster_name_unique=${cluster_name}-$(date +%m-%d-%H-%M%S) + +# See if cloud exists +response=$(curl -s -S -k -X 'GET' \ + "${base_url}?include=id%2Cname%2Cstate&filter=name%20eq%20%27private%27" \ + -H "${accept_header}" \ + -H "${auth_header}") +# check see GET wored +if [ $? -ne 0 ]; then + echo "Error: Failed to make GET request" + exit 1 +fi + +# Extract the items array from the response +items=$(echo "${response}" | jq '.items') + +# Check if the items array has exactly one item +if [ $(echo "${items}" | jq 'length') -eq 1 ]; then + # If it does, extract the id and store it in cloudID + cloudID=$(echo "${items}" | jq -r '.[0][0]') +else + # If it doesn't, make a POST request to create the item + post_response=$(curl -k -X 'POST' \ + "${base_url}" \ + -H "${accept_header}" \ + -H "${auth_header}" \ + -H 'Content-Type: application/astra-cloud+json' \ + -d '{ + "cloudType": "private", + "name": "private", + "type": "application/astra-cloud", + "version": "1.1" + }') + + # Extract the id from the response and store it in cloudID + cloudID=$(echo "${post_response}" | jq -r '.id') +fi + +# Now you can use $cloudID in the rest of your script +#echo "Cloud ID: ${cloudID}" + + + +# Make the POST request using the cloudID +cluster_response=$(curl -s -S -k -X 'POST' \ + "${base_url}/${cloudID}/clusters" \ + -H 'accept: application/astra-cluster+json' \ + -H "${auth_header}" \ + -H 'Content-Type: application/astra-cluster+json' \ + -d '{ + "name": "'"${cluster_name_unique}"'", + "type": "application/astra-cluster", + "connectorInstall": "pending", + "version": "1.6" + }') + +# Check if the curl command was successful +if [ $? -ne 0 ]; then + echo "Error: Failed to make POST request" + exit 1 +fi + +# Extract the id from the response and store it in clusterID +clusterID=$(echo "${cluster_response}" | jq -r '.id') +#echo "Cluster ID: ${clusterID}" + +# Print the YAML template, replacing the placeholders with the variables +echo "apiVersion: astra.netapp.io/v1 +kind: AstraConnector +metadata: + name: astra-connector + namespace: astra-connector +spec: + astra: + accountId: ${account_id} + clusterId: ${clusterID} + cloudId: ${cloudID} + skipTLSValidation: true + tokenRef: astra-api-token + natsSyncClient: + cloudBridgeURL: ${astra_url} + # hostAliasIP: IP needed if cloudBridgeURL DNS is not routable + imageRegistry: + name: netappdownloads.jfrog.io/docker-astra-control-staging/arch30/neptune + secret: regcred" \ No newline at end of file diff --git a/unified-installer/astra-unified-installer.sh b/unified-installer/astra-unified-installer.sh index 1d58b983..e5af9b2b 100755 --- a/unified-installer/astra-unified-installer.sh +++ b/unified-installer/astra-unified-installer.sh @@ -2073,6 +2073,7 @@ metadata: spec: astra: accountId: ${account_id} + astraControlURL: ${astra_url} tokenRef: astra-api-token cloudId: ${cloud_id} clusterId: ${cluster_id} @@ -2091,10 +2092,6 @@ spec: cpu: ".5" memory: ${memory_limit}Gi EOF - { - echo " natsSyncClient:" - echo " cloudBridgeURL: ${astra_url}" - } >> "$crs_file" if [ -n "$host_alias_ip" ]; then echo " hostAliasIP: $host_alias_ip" >> "$crs_file" fi @@ -2464,7 +2461,7 @@ step_monitor_deployment_progress() { add_problem "neptune deploy: failed" "Neptune failed to deploy" elif ! wait_for_deployment_running "astraconnect" "$connector_ns" "5"; then add_problem "astraconnect deploy: failed" "The Astra Connector failed to deploy" - elif ! wait_for_cr_state "astraconnectors/astra-connector" ".status.natsSyncClient.status" "Registered with Astra" "$connector_ns"; then + elif ! wait_for_cr_state "astraconnectors/astra-connector" ".status.status" "Registered with Astra" "$connector_ns"; then add_problem "cluster registration: failed" "Cluster registration failed" fi fi diff --git a/unified-installer/tmp.sh b/unified-installer/tmp.sh new file mode 100755 index 00000000..25a006be --- /dev/null +++ b/unified-installer/tmp.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +user="NetApp" +repo="astra-connector-operator" + +latest_release=$(curl --silent "https://api.github.com/repos/$user/$repo/releases/latest" | jq -r .tag_name) + +echo "Latest release is: $latest_release" \ No newline at end of file diff --git a/util/go_util_test.go b/util/go_util_test.go index 648b3542..d5733f81 100644 --- a/util/go_util_test.go +++ b/util/go_util_test.go @@ -18,17 +18,15 @@ func createAstraConnector() *v1.AstraConnector { }, Spec: v1.AstraConnectorSpec{ Astra: v1.Astra{ - TokenRef: "test-api-token", - AccountId: "test-account-id", - ClusterName: "test-cluster-name", + TokenRef: "test-api-token", + AccountId: "test-account-id", + ClusterName: "test-cluster-name", + AstraControlURL: "test-url", }, AutoSupport: v1.AutoSupport{ Enrolled: true, URL: "https://my-asup", }, - NatsSyncClient: v1.NatsSyncClient{ - CloudBridgeURL: "test-url", - }, }, } @@ -64,8 +62,8 @@ func TestGetJSONFieldName(t *testing.T) { jsonTag := util.GetJSONFieldName(&ac.Spec, &ac.Spec.Astra) assert.Equal(t, "astra", jsonTag) - jsonTag = util.GetJSONFieldName(&ac.Status, &ac.Status.NatsSyncClient) - assert.Equal(t, "natsSyncClient", jsonTag) + jsonTag = util.GetJSONFieldName(&ac.Status, &ac.Status) + assert.Equal(t, "astraConnectorStatus", jsonTag) }) t.Run("TestGetJSONFieldName__WhenInvalidStructFieldReturnEmptyString", func(t *testing.T) { From 5be1b82dc25fd4174b99ff013a7c3d6996975dfc Mon Sep 17 00:00:00 2001 From: Oscar Rodriguez Date: Wed, 5 Jun 2024 14:02:19 -0600 Subject: [PATCH 4/5] adding host alias --- unified-installer/astra-unified-installer.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/unified-installer/astra-unified-installer.sh b/unified-installer/astra-unified-installer.sh index 56f65d31..b0343f09 100755 --- a/unified-installer/astra-unified-installer.sh +++ b/unified-installer/astra-unified-installer.sh @@ -2264,6 +2264,13 @@ spec: cloudId: ${cloud_id} clusterId: ${cluster_id} skipTLSValidation: ${skip_tls_validation} # Should be set to false in production environments${labels_field_and_content} +EOF + +if [ -n "$host_alias_ip" ]; then + echo " hostAliasIP: $host_alias_ip" >> "$crs_file" +fi + +cat <> "$crs_file" imageRegistry: name: "${connector_registry}" secret: "${connector_regcred_name}" @@ -2278,9 +2285,6 @@ spec: cpu: ".5" memory: ${memory_limit}Gi EOF - if [ -n "$host_alias_ip" ]; then - echo " hostAliasIP: $host_alias_ip" >> "$crs_file" - fi if [ -n "$connector_tag" ]; then echo " astraConnect:" >> "$crs_file" From 9e72dae66d98f5f783adea9373d21bcba3e83901 Mon Sep 17 00:00:00 2001 From: Oscar Rodriguez Date: Wed, 5 Jun 2024 14:22:00 -0600 Subject: [PATCH 5/5] removing extra files i accidently added --- scripts/oscar_get_cluster_cloud_id.sh | 97 --------------------------- unified-installer/tmp.sh | 8 --- 2 files changed, 105 deletions(-) delete mode 100755 scripts/oscar_get_cluster_cloud_id.sh delete mode 100755 unified-installer/tmp.sh diff --git a/scripts/oscar_get_cluster_cloud_id.sh b/scripts/oscar_get_cluster_cloud_id.sh deleted file mode 100755 index 4ebbb326..00000000 --- a/scripts/oscar_get_cluster_cloud_id.sh +++ /dev/null @@ -1,97 +0,0 @@ -#!/bin/bash - -## Please fill this out -astra_url="https://dev-ol-astra-enterprise-team3-03-lb.rtp.openenglab.netapp.com" -account_id="bb22ca62-48ad-4697-a4d3-64bded53d849" -auth_token="gmiQt963pM9iRC2E-6a5EwuUzkT5w2iIk87_ca6x-DM=" -cluster_name="bobby" - -# Define the base URL and headers for convenience -base_url="${astra_url}/accounts/${account_id}/topology/v1/clouds" -accept_header="accept: application/json" -auth_header="Authorization: Bearer ${auth_token}" -cluster_name_unique=${cluster_name}-$(date +%m-%d-%H-%M%S) - -# See if cloud exists -response=$(curl -s -S -k -X 'GET' \ - "${base_url}?include=id%2Cname%2Cstate&filter=name%20eq%20%27private%27" \ - -H "${accept_header}" \ - -H "${auth_header}") -# check see GET wored -if [ $? -ne 0 ]; then - echo "Error: Failed to make GET request" - exit 1 -fi - -# Extract the items array from the response -items=$(echo "${response}" | jq '.items') - -# Check if the items array has exactly one item -if [ $(echo "${items}" | jq 'length') -eq 1 ]; then - # If it does, extract the id and store it in cloudID - cloudID=$(echo "${items}" | jq -r '.[0][0]') -else - # If it doesn't, make a POST request to create the item - post_response=$(curl -k -X 'POST' \ - "${base_url}" \ - -H "${accept_header}" \ - -H "${auth_header}" \ - -H 'Content-Type: application/astra-cloud+json' \ - -d '{ - "cloudType": "private", - "name": "private", - "type": "application/astra-cloud", - "version": "1.1" - }') - - # Extract the id from the response and store it in cloudID - cloudID=$(echo "${post_response}" | jq -r '.id') -fi - -# Now you can use $cloudID in the rest of your script -#echo "Cloud ID: ${cloudID}" - - - -# Make the POST request using the cloudID -cluster_response=$(curl -s -S -k -X 'POST' \ - "${base_url}/${cloudID}/clusters" \ - -H 'accept: application/astra-cluster+json' \ - -H "${auth_header}" \ - -H 'Content-Type: application/astra-cluster+json' \ - -d '{ - "name": "'"${cluster_name_unique}"'", - "type": "application/astra-cluster", - "connectorInstall": "pending", - "version": "1.6" - }') - -# Check if the curl command was successful -if [ $? -ne 0 ]; then - echo "Error: Failed to make POST request" - exit 1 -fi - -# Extract the id from the response and store it in clusterID -clusterID=$(echo "${cluster_response}" | jq -r '.id') -#echo "Cluster ID: ${clusterID}" - -# Print the YAML template, replacing the placeholders with the variables -echo "apiVersion: astra.netapp.io/v1 -kind: AstraConnector -metadata: - name: astra-connector - namespace: astra-connector -spec: - astra: - accountId: ${account_id} - clusterId: ${clusterID} - cloudId: ${cloudID} - skipTLSValidation: true - tokenRef: astra-api-token - natsSyncClient: - cloudBridgeURL: ${astra_url} - # hostAliasIP: IP needed if cloudBridgeURL DNS is not routable - imageRegistry: - name: netappdownloads.jfrog.io/docker-astra-control-staging/arch30/neptune - secret: regcred" \ No newline at end of file diff --git a/unified-installer/tmp.sh b/unified-installer/tmp.sh deleted file mode 100755 index 25a006be..00000000 --- a/unified-installer/tmp.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -user="NetApp" -repo="astra-connector-operator" - -latest_release=$(curl --silent "https://api.github.com/repos/$user/$repo/releases/latest" | jq -r .tag_name) - -echo "Latest release is: $latest_release" \ No newline at end of file