Skip to content

Commit

Permalink
Use wsprovision as alias for provision/workspace throughout code
Browse files Browse the repository at this point in the history
This is a really annoying change to make, since
1. VS Code will remove "unused" imports and reimport the unaliased
   package name on save, *even* if you use find-replace
2. Goland will let you refactor the import alias, but will basically
   find-replace throughout the file to do so, meaning that "workspace"
   gets replaced with "wsprovision" *in comments*.

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
  • Loading branch information
amisevsk committed Aug 12, 2021
1 parent 9f530f7 commit 17cdf4b
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions pkg/provision/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/devfile/devworkspace-operator/pkg/constants"
"github.com/devfile/devworkspace-operator/pkg/provision/workspace"
wsprovision "github.com/devfile/devworkspace-operator/pkg/provision/workspace"
)

const (
Expand All @@ -35,7 +35,7 @@ type NamespacedConfig struct {
// ReadNamespacedConfig reads the per-namespace DevWorkspace configmap and returns it as a struct. If there are
// no valid configmaps in the specified namespace, returns (nil, nil). If there are multiple configmaps with the
// per-namespace configmap label, returns an error.
func ReadNamespacedConfig(namespace string, api workspace.ClusterAPI) (*NamespacedConfig, error) {
func ReadNamespacedConfig(namespace string, api wsprovision.ClusterAPI) (*NamespacedConfig, error) {
cmList := &corev1.ConfigMapList{}
labelSelector, err := labels.Parse(fmt.Sprintf("%s=true", constants.NamespacedConfigLabelKey))
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/provision/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
maputils "github.com/devfile/devworkspace-operator/internal/map"
"github.com/devfile/devworkspace-operator/pkg/common"
"github.com/devfile/devworkspace-operator/pkg/constants"
"github.com/devfile/devworkspace-operator/pkg/provision/workspace"
wsprovision "github.com/devfile/devworkspace-operator/pkg/provision/workspace"
)

const (
Expand All @@ -46,7 +46,7 @@ const (
// ProvisionWorkspaceMetadata creates a configmap on the cluster that stores metadata about the workspace and configures all
// workspace containers to mount that configmap at /devworkspace-metadata. Each container has the environment
// variable DEVWORKSPACE_METADATA set to the mount path for the configmap
func ProvisionWorkspaceMetadata(podAdditions *v1alpha1.PodAdditions, original, flattened *dw.DevWorkspace, api *workspace.ClusterAPI) error {
func ProvisionWorkspaceMetadata(podAdditions *v1alpha1.PodAdditions, original, flattened *dw.DevWorkspace, api *wsprovision.ClusterAPI) error {
cm, err := getSpecMetadataConfigMap(original, flattened)
if err != nil {
return err
Expand Down Expand Up @@ -79,7 +79,7 @@ func ProvisionWorkspaceMetadata(podAdditions *v1alpha1.PodAdditions, original, f
return nil
}

func syncConfigMapToCluster(specCM *corev1.ConfigMap, api *workspace.ClusterAPI) (inSync bool, err error) {
func syncConfigMapToCluster(specCM *corev1.ConfigMap, api *wsprovision.ClusterAPI) (inSync bool, err error) {
clusterCM := &corev1.ConfigMap{}
err = api.Client.Get(context.TODO(), types.NamespacedName{Name: specCM.Name, Namespace: specCM.Namespace}, clusterCM)

Expand Down
8 changes: 4 additions & 4 deletions pkg/provision/storage/asyncStorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/devfile/devworkspace-operator/pkg/constants"
devfileConstants "github.com/devfile/devworkspace-operator/pkg/library/constants"
"github.com/devfile/devworkspace-operator/pkg/provision/storage/asyncstorage"
"github.com/devfile/devworkspace-operator/pkg/provision/workspace"
wsprovision "github.com/devfile/devworkspace-operator/pkg/provision/workspace"
)

// The AsyncStorageProvisioner provisions one PVC per namespace and creates an ssh deployment that syncs data into that PVC.
Expand All @@ -42,7 +42,7 @@ func (*AsyncStorageProvisioner) NeedsStorage(workspace *dw.DevWorkspaceTemplateS
return needsStorage(workspace)
}

func (p *AsyncStorageProvisioner) ProvisionStorage(podAdditions *v1alpha1.PodAdditions, workspace *dw.DevWorkspace, clusterAPI workspace.ClusterAPI) error {
func (p *AsyncStorageProvisioner) ProvisionStorage(podAdditions *v1alpha1.PodAdditions, workspace *dw.DevWorkspace, clusterAPI wsprovision.ClusterAPI) error {
if err := checkConfigured(); err != nil {
return &ProvisioningError{
Message: fmt.Sprintf("%s. Contact an administrator to resolve this issue.", err.Error()),
Expand Down Expand Up @@ -141,7 +141,7 @@ func (p *AsyncStorageProvisioner) ProvisionStorage(podAdditions *v1alpha1.PodAdd
return nil
}

func (p *AsyncStorageProvisioner) CleanupWorkspaceStorage(workspace *dw.DevWorkspace, clusterAPI workspace.ClusterAPI) error {
func (p *AsyncStorageProvisioner) CleanupWorkspaceStorage(workspace *dw.DevWorkspace, clusterAPI wsprovision.ClusterAPI) error {
// TODO: This approach relies on there being a maximum of one workspace running per namespace.
asyncDeploy, err := asyncstorage.GetWorkspaceSyncDeploymentCluster(workspace.Namespace, clusterAPI)
if err != nil {
Expand Down Expand Up @@ -240,7 +240,7 @@ func (*AsyncStorageProvisioner) addVolumesForAsyncStorage(podAdditions *v1alpha1
// getAsyncWorkspaceCount returns whether the async storage provider can support starting a workspace.
// Due to how cleanup for the async storage PVC is implemented, only one workspace that uses the async storage
// type can be running at a time.
func (*AsyncStorageProvisioner) getAsyncWorkspaceCount(api workspace.ClusterAPI) (started, total int, err error) {
func (*AsyncStorageProvisioner) getAsyncWorkspaceCount(api wsprovision.ClusterAPI) (started, total int, err error) {
workspaces := &dw.DevWorkspaceList{}
err = api.Client.List(api.Ctx, workspaces)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/provision/storage/asyncstorage/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

"github.com/devfile/devworkspace-operator/pkg/provision/workspace"
wsprovision "github.com/devfile/devworkspace-operator/pkg/provision/workspace"
)

const (
Expand All @@ -45,7 +45,7 @@ func getSSHAuthorizedKeysConfigMapSpec(namespace string, authorizedKeys []byte)
return cm
}

func getSSHAuthorizedKeysConfigMapCluster(namespace string, clusterAPI workspace.ClusterAPI) (*corev1.ConfigMap, error) {
func getSSHAuthorizedKeysConfigMapCluster(namespace string, clusterAPI wsprovision.ClusterAPI) (*corev1.ConfigMap, error) {
cm := &corev1.ConfigMap{}
namespaceName := types.NamespacedName{
Name: sshAuthorizedKeysConfigMapName,
Expand Down
4 changes: 2 additions & 2 deletions pkg/provision/storage/asyncstorage/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

"github.com/devfile/devworkspace-operator/pkg/provision/workspace"
wsprovision "github.com/devfile/devworkspace-operator/pkg/provision/workspace"
)

// GetOrCreateSSHConfig returns the secret and configmap used for the asynchronous deployment. The Secret is generated per-workspace
Expand All @@ -34,7 +34,7 @@ import (
// In both cases, if the ConfigMap does not exist, it is created.
//
// Returns NotReadyError if changes were made to the cluster.
func GetOrCreateSSHConfig(workspace *dw.DevWorkspace, clusterAPI workspace.ClusterAPI) (*corev1.Secret, *corev1.ConfigMap, error) {
func GetOrCreateSSHConfig(workspace *dw.DevWorkspace, clusterAPI wsprovision.ClusterAPI) (*corev1.Secret, *corev1.ConfigMap, error) {
var pubKey []byte
clusterSecret, err := getSSHSidecarSecretCluster(workspace, clusterAPI)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/provision/storage/asyncstorage/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/devfile/devworkspace-operator/internal/images"
"github.com/devfile/devworkspace-operator/pkg/provision/workspace"
wsprovision "github.com/devfile/devworkspace-operator/pkg/provision/workspace"
)

func SyncWorkspaceSyncDeploymentToCluster(namespace string, sshConfigMap *corev1.ConfigMap, storage *corev1.PersistentVolumeClaim, clusterAPI workspace.ClusterAPI) (*appsv1.Deployment, error) {
func SyncWorkspaceSyncDeploymentToCluster(namespace string, sshConfigMap *corev1.ConfigMap, storage *corev1.PersistentVolumeClaim, clusterAPI wsprovision.ClusterAPI) (*appsv1.Deployment, error) {
specDeployment := getWorkspaceSyncDeploymentSpec(namespace, sshConfigMap, storage)
clusterDeployment, err := GetWorkspaceSyncDeploymentCluster(namespace, clusterAPI)
if err != nil {
Expand Down Expand Up @@ -139,7 +139,7 @@ func getWorkspaceSyncDeploymentSpec(namespace string, sshConfigMap *corev1.Confi
},
},
TerminationGracePeriodSeconds: &terminationGracePeriod,
SecurityContext: workspace.GetDevWorkspaceSecurityContext(),
SecurityContext: wsprovision.GetDevWorkspaceSecurityContext(),
AutomountServiceAccountToken: nil,
},
},
Expand All @@ -148,7 +148,7 @@ func getWorkspaceSyncDeploymentSpec(namespace string, sshConfigMap *corev1.Confi
return deployment
}

func GetWorkspaceSyncDeploymentCluster(namespace string, clusterAPI workspace.ClusterAPI) (*appsv1.Deployment, error) {
func GetWorkspaceSyncDeploymentCluster(namespace string, clusterAPI wsprovision.ClusterAPI) (*appsv1.Deployment, error) {
deploy := &appsv1.Deployment{}
namespacedName := types.NamespacedName{
Name: "async-storage", // TODO
Expand Down
4 changes: 2 additions & 2 deletions pkg/provision/storage/asyncstorage/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

"github.com/devfile/devworkspace-operator/pkg/provision/workspace"
wsprovision "github.com/devfile/devworkspace-operator/pkg/provision/workspace"
)

const (
Expand Down Expand Up @@ -50,7 +50,7 @@ func getSSHSidecarSecretSpec(workspace *dw.DevWorkspace, privateKey []byte) *cor
return secret
}

func getSSHSidecarSecretCluster(workspace *dw.DevWorkspace, clusterAPI workspace.ClusterAPI) (*corev1.Secret, error) {
func getSSHSidecarSecretCluster(workspace *dw.DevWorkspace, clusterAPI wsprovision.ClusterAPI) (*corev1.Secret, error) {
secret := &corev1.Secret{}
namespacedName := types.NamespacedName{
Name: GetSSHSidecarSecretName(workspace.Status.DevWorkspaceId),
Expand Down
6 changes: 3 additions & 3 deletions pkg/provision/storage/asyncstorage/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

"github.com/devfile/devworkspace-operator/pkg/provision/workspace"
wsprovision "github.com/devfile/devworkspace-operator/pkg/provision/workspace"
)

func SyncWorkspaceSyncServiceToCluster(asyncDeploy *appsv1.Deployment, api workspace.ClusterAPI) (*corev1.Service, error) {
func SyncWorkspaceSyncServiceToCluster(asyncDeploy *appsv1.Deployment, api wsprovision.ClusterAPI) (*corev1.Service, error) {
specService := getWorkspaceSyncServiceSpec(asyncDeploy)
err := controllerutil.SetOwnerReference(asyncDeploy, specService, api.Scheme)
if err != nil {
Expand Down Expand Up @@ -78,7 +78,7 @@ func getWorkspaceSyncServiceSpec(asyncDeploy *appsv1.Deployment) *corev1.Service
}
}

func getWorkspaceSyncServiceCluster(namespace string, api workspace.ClusterAPI) (*corev1.Service, error) {
func getWorkspaceSyncServiceCluster(namespace string, api wsprovision.ClusterAPI) (*corev1.Service, error) {
service := &corev1.Service{}
namespacedName := types.NamespacedName{
Name: asyncServerServiceName,
Expand Down
6 changes: 3 additions & 3 deletions pkg/provision/storage/commonStorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/devfile/devworkspace-operator/pkg/config"
"github.com/devfile/devworkspace-operator/pkg/constants"
devfileConstants "github.com/devfile/devworkspace-operator/pkg/library/constants"
"github.com/devfile/devworkspace-operator/pkg/provision/workspace"
wsprovision "github.com/devfile/devworkspace-operator/pkg/provision/workspace"
)

// The CommonStorageProvisioner provisions one PVC per namespace and configures all volumes in a workspace
Expand All @@ -36,7 +36,7 @@ func (*CommonStorageProvisioner) NeedsStorage(workspace *dw.DevWorkspaceTemplate
return needsStorage(workspace)
}

func (p *CommonStorageProvisioner) ProvisionStorage(podAdditions *v1alpha1.PodAdditions, workspace *dw.DevWorkspace, clusterAPI workspace.ClusterAPI) error {
func (p *CommonStorageProvisioner) ProvisionStorage(podAdditions *v1alpha1.PodAdditions, workspace *dw.DevWorkspace, clusterAPI wsprovision.ClusterAPI) error {
// Add ephemeral volumes
if err := addEphemeralVolumesFromWorkspace(workspace, podAdditions); err != nil {
return err
Expand All @@ -60,7 +60,7 @@ func (p *CommonStorageProvisioner) ProvisionStorage(podAdditions *v1alpha1.PodAd
return nil
}

func (*CommonStorageProvisioner) CleanupWorkspaceStorage(workspace *dw.DevWorkspace, clusterAPI workspace.ClusterAPI) error {
func (*CommonStorageProvisioner) CleanupWorkspaceStorage(workspace *dw.DevWorkspace, clusterAPI wsprovision.ClusterAPI) error {
return runCommonPVCCleanupJob(workspace, clusterAPI)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/provision/storage/commonStorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (

"github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
"github.com/devfile/devworkspace-operator/pkg/config"
"github.com/devfile/devworkspace-operator/pkg/provision/workspace"
wsprovision "github.com/devfile/devworkspace-operator/pkg/provision/workspace"
)

var scheme = runtime.NewScheme()
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestRewriteContainerVolumeMountsForCommonStorageClass(t *testing.T) {
t.Fatalf("Failure during setup: %s", err)
}
commonPVC.Status.Phase = corev1.ClaimBound
clusterAPI := workspace.ClusterAPI{
clusterAPI := wsprovision.ClusterAPI{
Client: fake.NewFakeClientWithScheme(scheme, commonPVC),
Logger: zap.New(),
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/provision/storage/ephemeralStorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

"github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
"github.com/devfile/devworkspace-operator/pkg/library/container"
"github.com/devfile/devworkspace-operator/pkg/provision/workspace"
wsprovision "github.com/devfile/devworkspace-operator/pkg/provision/workspace"
)

// The EphemeralStorageProvisioner provisions all workspace storage as emptyDir volumes.
Expand All @@ -32,7 +32,7 @@ func (e EphemeralStorageProvisioner) NeedsStorage(_ *dw.DevWorkspaceTemplateSpec
return false
}

func (e EphemeralStorageProvisioner) ProvisionStorage(podAdditions *v1alpha1.PodAdditions, workspace *dw.DevWorkspace, _ workspace.ClusterAPI) error {
func (e EphemeralStorageProvisioner) ProvisionStorage(podAdditions *v1alpha1.PodAdditions, workspace *dw.DevWorkspace, _ wsprovision.ClusterAPI) error {
persistent, ephemeral, projects := getWorkspaceVolumes(workspace)
if _, err := addEphemeralVolumesToPodAdditions(podAdditions, persistent); err != nil {
return err
Expand All @@ -56,6 +56,6 @@ func (e EphemeralStorageProvisioner) ProvisionStorage(podAdditions *v1alpha1.Pod
return nil
}

func (e EphemeralStorageProvisioner) CleanupWorkspaceStorage(_ *dw.DevWorkspace, _ workspace.ClusterAPI) error {
func (e EphemeralStorageProvisioner) CleanupWorkspaceStorage(_ *dw.DevWorkspace, _ wsprovision.ClusterAPI) error {
return nil
}
6 changes: 3 additions & 3 deletions pkg/provision/storage/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

"github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
"github.com/devfile/devworkspace-operator/pkg/constants"
"github.com/devfile/devworkspace-operator/pkg/provision/workspace"
wsprovision "github.com/devfile/devworkspace-operator/pkg/provision/workspace"
)

// Provisioner is an interface for rewriting volumeMounts in a pod according to a storage policy (e.g. common PVC for all mounts, etc.)
Expand All @@ -26,14 +26,14 @@ type Provisioner interface {
// out-of-pod required objects to the cluster.
// Returns NotReadyError to signify that storage is not ready, ProvisioningError when a fatal issue is encountered,
// and other error if there is an unexpected problem.
ProvisionStorage(podAdditions *v1alpha1.PodAdditions, workspace *dw.DevWorkspace, clusterAPI workspace.ClusterAPI) error
ProvisionStorage(podAdditions *v1alpha1.PodAdditions, workspace *dw.DevWorkspace, clusterAPI wsprovision.ClusterAPI) error
// NeedsStorage returns whether the current workspace needs a PVC to be provisioned, given this storage strategy.
NeedsStorage(workspace *dw.DevWorkspaceTemplateSpec) bool
// CleanupWorkspaceStorage removes any objects provisioned by in the ProvisionStorage step that aren't automatically removed when a
// DevWorkspace is deleted (e.g. delete subfolders in a common PVC assigned to the workspace)
// Returns nil on success (DevWorkspace can be deleted), NotReadyError if additional reconciles are necessary, ProvisioningError when
// a fatal issue is encountered, and any other error if an unexpected problem arises.
CleanupWorkspaceStorage(workspace *dw.DevWorkspace, clusterAPI workspace.ClusterAPI) error
CleanupWorkspaceStorage(workspace *dw.DevWorkspace, clusterAPI wsprovision.ClusterAPI) error
}

// GetProvisioner returns the storage provisioner that should be used for the current workspace
Expand Down
6 changes: 3 additions & 3 deletions pkg/provision/storage/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
devfileConstants "github.com/devfile/devworkspace-operator/pkg/library/constants"
containerlib "github.com/devfile/devworkspace-operator/pkg/library/container"
nsconfig "github.com/devfile/devworkspace-operator/pkg/provision/config"
"github.com/devfile/devworkspace-operator/pkg/provision/workspace"
wsprovision "github.com/devfile/devworkspace-operator/pkg/provision/workspace"
)

func getCommonPVCSpec(namespace string, size string) (*corev1.PersistentVolumeClaim, error) {
Expand Down Expand Up @@ -79,7 +79,7 @@ func needsStorage(workspace *dw.DevWorkspaceTemplateSpec) bool {
return containerlib.AnyMountSources(workspace.Components)
}

func syncCommonPVC(namespace string, clusterAPI workspace.ClusterAPI) (*corev1.PersistentVolumeClaim, error) {
func syncCommonPVC(namespace string, clusterAPI wsprovision.ClusterAPI) (*corev1.PersistentVolumeClaim, error) {
namespacedConfig, err := nsconfig.ReadNamespacedConfig(namespace, clusterAPI)
if err != nil {
return nil, fmt.Errorf("failed to read namespace-specific configuration: %w", err)
Expand All @@ -93,7 +93,7 @@ func syncCommonPVC(namespace string, clusterAPI workspace.ClusterAPI) (*corev1.P
if err != nil {
return nil, err
}
currObject, requeue, err := workspace.SyncObject(pvc, clusterAPI.Client, clusterAPI.Logger, false)
currObject, requeue, err := wsprovision.SyncObject(pvc, clusterAPI.Client, clusterAPI.Logger, false)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 17cdf4b

Please sign in to comment.