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

Migrate odf-info structs to API folder #2698

Merged
merged 1 commit into from
Jul 17, 2024
Merged
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
41 changes: 41 additions & 0 deletions api/v1alpha1/odfinfoconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright 2020 Red Hat OpenShift Container Storage.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import "k8s.io/apimachinery/pkg/types"

// ConnectedClient describes the connected clients of the storage cluster key
type ConnectedClient struct {
Name string `yaml:"name"`
ClusterID string `yaml:"clusterId"`
}

// InfoStorageCluster describes information regarding a storage cluster key
type InfoStorageCluster struct {
NamespacedName types.NamespacedName `yaml:"namespacedName"`
StorageProviderEndpoint string `yaml:"storageProviderEndpoint"`
CephClusterFSID string `yaml:"cephClusterFSID"`
}

// OdfInfoData describes odf-info CM's data
type OdfInfoData struct {
Version string `yaml:"version"`
DeploymentType string `yaml:"deploymentType"`
Clients []ConnectedClient `yaml:"clients"`
StorageCluster InfoStorageCluster `yaml:"storageCluster"`
StorageSystemName string `yaml:"storageSystemName"`
}
52 changes: 52 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.

29 changes: 5 additions & 24 deletions controllers/storagecluster/odfinfoconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,12 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/yaml"
)

type connectedClient struct {
Name string `yaml:"name"`
ClusterID string `yaml:"clusterId"`
}
type infoStorageCluster struct {
NamespacedName types.NamespacedName `yaml:"namespacedName"`
StorageProviderEndpoint string `yaml:"storageProviderEndpoint"`
CephClusterFSID string `yaml:"cephClusterFSID"`
}

type OdfInfoData struct {
Version string `yaml:"version"`
DeploymentType string `yaml:"deploymentType"`
Clients []connectedClient `yaml:"clients"`
StorageCluster infoStorageCluster `yaml:"storageCluster"`
StorageSystemName string `yaml:"storageSystemName"`
}

const (
odfInfoKeySuffix = "config.yaml"
odfDeploymentTypeExternal = "external"
Expand Down Expand Up @@ -161,12 +142,12 @@ func getOdfInfoData(r *StorageClusterReconciler, storageCluster *ocsv1.StorageCl
return "", err
}

data := OdfInfoData{
data := ocsv1a1.OdfInfoData{
Version: ocsVersion,
DeploymentType: odfDeploymentType,
StorageSystemName: storageSystemName,
Clients: connectedClients,
StorageCluster: infoStorageCluster{
StorageCluster: ocsv1a1.InfoStorageCluster{
NamespacedName: client.ObjectKeyFromObject(storageCluster),
StorageProviderEndpoint: storageCluster.Status.StorageProviderEndpoint,
CephClusterFSID: cephFSId,
Expand All @@ -180,19 +161,19 @@ func getOdfInfoData(r *StorageClusterReconciler, storageCluster *ocsv1.StorageCl

}

func getConnectedClients(r *StorageClusterReconciler, storageCluster *ocsv1.StorageCluster) ([]connectedClient, error) {
func getConnectedClients(r *StorageClusterReconciler, storageCluster *ocsv1.StorageCluster) ([]ocsv1a1.ConnectedClient, error) {
storageConsumers := &ocsv1a1.StorageConsumerList{}
err := r.Client.List(r.ctx, storageConsumers, client.InNamespace(storageCluster.Namespace))
if err != nil {
return nil, err
}
connectedClients := make([]connectedClient, 0, len(storageConsumers.Items))
connectedClients := make([]ocsv1a1.ConnectedClient, 0, len(storageConsumers.Items))

for storageConsumerIdx := range storageConsumers.Items {
storageConsumer := &storageConsumers.Items[storageConsumerIdx]
clusterID := storageConsumer.Status.Client.ClusterID
name := storageConsumer.Status.Client.Name
newConnectedClient := connectedClient{
newConnectedClient := ocsv1a1.ConnectedClient{
Name: name,
ClusterID: clusterID,
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/storagecluster/odfinfoconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestOdfInfoConfig(t *testing.T) {
assert.NilError(t, err, "expected to find configmap %q: %+v", odfInfoConfigMapName, err)

// compare with the expected results
odfInfoDataOfStorageClusterKey := OdfInfoData{}
odfInfoDataOfStorageClusterKey := v1alpha1.OdfInfoData{}
err = yaml.Unmarshal([]byte(configMap.Data[odfInfoConfigReconciler.getOdfInfoKeyName(sc)]),
&odfInfoDataOfStorageClusterKey)
assert.NilError(t, err, "Expected unmarshalling of OdfInfoConfig's data")
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading