The relationship between Germany and the Soviet Union changed drastically from 1939 to 1941. The relationship started out very well, but this good relationship changed when Germany invaded the Soviet Union in June of 1941.
Before the war, the Soviet Union and Germany had a nonaggression pact. This was a surprise to many because Hitler was radically anticommunist. He felt that communism was an evil force in the world. He also felt that it was closely tied to the Jews. Hitler also believed that the Slavs (an ethnic group that includes Russians) were racially inferior to the Germans. Thus, it seemed odd that he would make peace with the Soviets.
Once the war started, the two countries still had a good relationship. They divided Poland between themselves. The Soviets provided the Germans with vital raw materials and the Germans sold the Soviets military and industrial equipment. The two sides were not allies, but they were clearly friendly.
But Hitler was planning all along to invade and destroy the Soviet Union. The invasion started on June 22, 1941. This changed the relationship between the two countries. Having once been relatively friendly, they were now mortal enemies.