Skip to content

Commit

Permalink
Remase on master, fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Anatolii Bazko <abazko@redhat.com>
  • Loading branch information
tolusha committed Feb 15, 2021
1 parent ece6761 commit 7165804
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 28 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/che/che_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
instance.Spec.Auth.OpenShiftoAuth = nil
instance.Spec.Auth.InitialOpenShiftOAuthUser = nil
updateFields := map[string]string{
"openShiftoAuth": "nil",
"openShiftoAuth": "nil",
"initialOpenShiftOAuthUser": "nil",
}

Expand All @@ -406,7 +406,7 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
}

if instance.Spec.Auth.InitialOpenShiftOAuthUser == nil && instance.Status.OpenShiftOAuthUserCredentialsSecret != "" {
secret, err := deploy.GetSecret(openShiftOAuthUserCredentialsSecret, instance.Namespace, deployContext.ClusterAPI)
secret, err := deploy.GetSecret(deployContext, instance.Status.OpenShiftOAuthUserCredentialsSecret, instance.Namespace)
if secret == nil {
if err == nil {
instance.Status.OpenShiftOAuthUserCredentialsSecret = ""
Expand Down
2 changes: 1 addition & 1 deletion pkg/deploy/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func MountSecrets(specDeployment *appsv1.Deployment, deployContext *DeployContex
specDeployment.Spec.Template.Spec.Containers[0].VolumeMounts = append(specDeployment.Spec.Template.Spec.Containers[0].VolumeMounts, volumeMount)

case "env":
secret, err := GetSecret(secretObj.Name, deployContext.CheCluster.Namespace, deployContext.ClusterAPI)
secret, err := GetSecret(deployContext, secretObj.Name, deployContext.CheCluster.Namespace)
if err != nil {
return err
} else if secret == nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/deploy/devfile-registry/devfile_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func SyncDevfileRegistryToCluster(deployContext *deploy.DeployContext, cheHost s
deployContext,
cheHost,
deploy.DevfileRegistryName,
deployContext.CheCluster.Spec.Server.PluginRegistryRoute,
deployContext.CheCluster.Spec.Server.PluginRegistryIngress,
deployContext.CheCluster.Spec.Server.DevfileRegistryRoute,
deployContext.CheCluster.Spec.Server.DevfileRegistryIngress,
deploy.DevfileRegistryName)
if !done {
return false, err
Expand Down
13 changes: 10 additions & 3 deletions pkg/deploy/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func SyncSecret(
return nil, err
}

clusterSecret, err := GetSecret(specSecret.Name, specSecret.Namespace, deployContext.ClusterAPI)
clusterSecret, err := GetSecret(deployContext, specSecret.Name, specSecret.Namespace)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -74,13 +74,20 @@ func SyncSecret(
}

// GetSecret retrieves given secret from cluster
func GetSecret(name string, namespace string, clusterAPI ClusterAPI) (*corev1.Secret, error) {
func GetSecret(deployContext *DeployContext, name string, namespace string) (*corev1.Secret, error) {
secret := &corev1.Secret{}
namespacedName := types.NamespacedName{
Namespace: namespace,
Name: name,
}
err := clusterAPI.NonCachedClient.Get(context.TODO(), namespacedName, secret)

var err error
if namespace == deployContext.CheCluster.ObjectMeta.Namespace {
err = deployContext.ClusterAPI.Client.Get(context.TODO(), namespacedName, secret)
} else {
err = deployContext.ClusterAPI.NonCachedClient.Get(context.TODO(), namespacedName, secret)
}

if err != nil {
if errors.IsNotFound(err) {
return nil, nil
Expand Down
28 changes: 15 additions & 13 deletions pkg/deploy/server/che_configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,21 +280,23 @@ func GetCheConfigMapData(deployContext *deploy.DeployContext) (cheEnv map[string
// Add TLS key and server certificate to properties when user workspaces should be created in another
// than Che server namespace, from where the Che TLS secret is not accessable
if !util.IsWorkspaceInSameNamespaceWithChe(deployContext.CheCluster) {
cheTLSSecret, err := deploy.GetSecret(deployContext.CheCluster.Spec.K8s.TlsSecretName, deployContext.CheCluster.ObjectMeta.Namespace, deployContext.ClusterAPI)
if err != nil {
return nil, err
}
if cheTLSSecret == nil {
// default k8s secret is used
} else {
if _, exists := cheTLSSecret.Data["tls.key"]; !exists {
return nil, fmt.Errorf("%s secret has no 'tls.key' key in data", deployContext.CheCluster.Spec.K8s.TlsSecretName)
if deployContext.CheCluster.Spec.K8s.TlsSecretName != "" {
cheTLSSecret, err := deploy.GetSecret(deployContext, deployContext.CheCluster.Spec.K8s.TlsSecretName, deployContext.CheCluster.ObjectMeta.Namespace)
if err != nil {
return nil, err
}
if _, exists := cheTLSSecret.Data["tls.crt"]; !exists {
return nil, fmt.Errorf("%s secret has no 'tls.crt' key in data", deployContext.CheCluster.Spec.K8s.TlsSecretName)
if cheTLSSecret == nil {
return nil, fmt.Errorf("%s secret not found", deployContext.CheCluster.Spec.K8s.TlsSecretName)
} else {
if _, exists := cheTLSSecret.Data["tls.key"]; !exists {
return nil, fmt.Errorf("%s secret has no 'tls.key' key in data", deployContext.CheCluster.Spec.K8s.TlsSecretName)
}
if _, exists := cheTLSSecret.Data["tls.crt"]; !exists {
return nil, fmt.Errorf("%s secret has no 'tls.crt' key in data", deployContext.CheCluster.Spec.K8s.TlsSecretName)
}
k8sCheEnv["CHE_INFRA_KUBERNETES_TLS__KEY"] = string(cheTLSSecret.Data["tls.key"])
k8sCheEnv["CHE_INFRA_KUBERNETES_TLS__CERT"] = string(cheTLSSecret.Data["tls.crt"])
}
k8sCheEnv["CHE_INFRA_KUBERNETES_TLS__KEY"] = string(cheTLSSecret.Data["tls.key"])
k8sCheEnv["CHE_INFRA_KUBERNETES_TLS__CERT"] = string(cheTLSSecret.Data["tls.crt"])
}
}

Expand Down
16 changes: 9 additions & 7 deletions pkg/deploy/server/che_configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ func TestNewCheConfigMap(t *testing.T) {
Proxy: &deploy.Proxy{},
ClusterAPI: deploy.ClusterAPI{},
}
expectedIdentityProvider := "openshift-v4"
util.IsOpenShift = true
util.IsOpenShift4 = true

cheEnv, _ := GetCheConfigMapData(deployContext)
testCm, _ := deploy.GetSpecConfigMap(deployContext, CheConfigMapName, cheEnv, CheConfigMapName)

identityProvider := testCm.Data["CHE_INFRA_OPENSHIFT_OAUTH__IDENTITY__PROVIDER"]
_, isOpenshiftv4, _ := util.DetectOpenShift()
protocol := strings.Split(testCm.Data["CHE_API"], "://")[0]
expectedIdentityProvider := "openshift-v3"
if isOpenshiftv4 {
expectedIdentityProvider = "openshift-v4"
}
if identityProvider != expectedIdentityProvider {
t.Errorf("Test failed. Expecting identity provider to be '%s' while got '%s'", expectedIdentityProvider, identityProvider)
}
Expand Down Expand Up @@ -153,12 +153,14 @@ func TestConfigMap(t *testing.T) {
orgv1.SchemeBuilder.AddToScheme(scheme.Scheme)
testCase.initObjects = append(testCase.initObjects)
cli := fake.NewFakeClientWithScheme(scheme.Scheme, testCase.initObjects...)
nonCachedClient := fake.NewFakeClientWithScheme(scheme.Scheme, testCase.initObjects...)

deployContext := &deploy.DeployContext{
CheCluster: testCase.cheCluster,
ClusterAPI: deploy.ClusterAPI{
Client: cli,
Scheme: scheme.Scheme,
Client: cli,
NonCachedClient: nonCachedClient,
Scheme: scheme.Scheme,
},
Proxy: &deploy.Proxy{},
}
Expand Down

0 comments on commit 7165804

Please sign in to comment.