@@ -36,8 +36,6 @@ const (
3636 StartedState DesiredState = "STARTED"
3737 StoppedState DesiredState = "STOPPED"
3838
39- Kind string = "CFApp"
40- APIVersion string = "korifi.cloudfoundry.org/v1alpha1"
4139 CFAppGUIDLabel string = "korifi.cloudfoundry.org/app-guid"
4240 AppResourceType string = "App"
4341 AppEnvResourceType string = "App Env"
@@ -292,7 +290,7 @@ func (f *AppRepo) CreateApp(ctx context.Context, authInfo authorization.Info, ap
292290
293291 envSecret := & corev1.Secret {
294292 ObjectMeta : metav1.ObjectMeta {
295- Name : GenerateEnvSecretName ( cfApp .Name ) ,
293+ Name : cfApp .Spec . EnvSecretName ,
296294 Namespace : cfApp .Namespace ,
297295 Labels : map [string ]string {
298296 CFAppGUIDLabel : cfApp .Name ,
@@ -388,16 +386,27 @@ func (f *AppRepo) ListApps(ctx context.Context, authInfo authorization.Info, mes
388386}
389387
390388func (f * AppRepo ) PatchAppEnvVars (ctx context.Context , authInfo authorization.Info , message PatchAppEnvVarsMessage ) (AppEnvVarsRecord , error ) {
391- secretObj := corev1.Secret {
389+ userClient , err := f .userClientFactory .BuildClient (authInfo )
390+ if err != nil {
391+ return AppEnvVarsRecord {}, fmt .Errorf ("failed to build user client: %w" , err )
392+ }
393+
394+ cfApp := & korifiv1alpha1.CFApp {
392395 ObjectMeta : metav1.ObjectMeta {
393- Name : GenerateEnvSecretName (message .AppGUID ),
394396 Namespace : message .SpaceGUID ,
397+ Name : message .AppGUID ,
395398 },
396399 }
397-
398- userClient , err := f .userClientFactory .BuildClient (authInfo )
400+ err = userClient .Get (ctx , client .ObjectKeyFromObject (cfApp ), cfApp )
399401 if err != nil {
400- return AppEnvVarsRecord {}, fmt .Errorf ("failed to build user client: %w" , err )
402+ return AppEnvVarsRecord {}, apierrors .FromK8sError (err , AppEnvResourceType )
403+ }
404+
405+ secretObj := corev1.Secret {
406+ ObjectMeta : metav1.ObjectMeta {
407+ Name : cfApp .Spec .EnvSecretName ,
408+ Namespace : message .SpaceGUID ,
409+ },
401410 }
402411
403412 err = PatchResource (ctx , userClient , & secretObj , func () {
@@ -617,23 +626,18 @@ func getAppEnv(ctx context.Context, userClient client.Client, app AppRecord) (ma
617626 return appEnvMap , nil
618627}
619628
620- func GenerateEnvSecretName (appGUID string ) string {
621- return appGUID + "-env"
622- }
623-
624629func (m * CreateAppMessage ) toCFApp () korifiv1alpha1.CFApp {
625- guid := uuid .NewString ()
626630 return korifiv1alpha1.CFApp {
627631 ObjectMeta : metav1.ObjectMeta {
628- Name : guid ,
632+ Name : uuid . NewString () ,
629633 Namespace : m .SpaceGUID ,
630634 Labels : m .Labels ,
631635 Annotations : m .Annotations ,
632636 },
633637 Spec : korifiv1alpha1.CFAppSpec {
634638 DisplayName : m .Name ,
635639 DesiredState : korifiv1alpha1 .AppState (m .State ),
636- EnvSecretName : GenerateEnvSecretName ( guid ),
640+ EnvSecretName : uuid . NewString ( ),
637641 Lifecycle : korifiv1alpha1.Lifecycle {
638642 Type : korifiv1alpha1 .LifecycleType (m .Lifecycle .Type ),
639643 Data : korifiv1alpha1.LifecycleData {
0 commit comments